aboutsummaryrefslogtreecommitdiff
path: root/src/property/file.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-05-20 23:04:07 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-05-20 23:05:20 -0700
commit55ae0b8942f44becf2a8fda50c03c085e4da7cc3 (patch)
treeb53e10498ea479542511ead21984b06a8437cec1 /src/property/file.lisp
parentdf8a09e78b92aa04bd2a95232c23670c573d5460 (diff)
downloadconsfigurator-55ae0b8942f44becf2a8fda50c03c085e4da7cc3.tar.gz
add FILE:CONTAINING-DIRECTORY-EXISTS
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/property/file.lisp')
-rw-r--r--src/property/file.lisp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/property/file.lisp b/src/property/file.lisp
index c49a703..7136db9 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -125,6 +125,18 @@ Uses CL-PPCRE:REGEX-REPLACE, which see for the syntax of REPLACE."
;; assume it was already there
:no-change))
+(defprop containing-directory-exists :posix (file)
+ "Ensure that a file's directory and the latter's parents exist."
+ (:desc #?"Directory containing ${file} exists")
+ (:apply
+ (if (pathname-name file)
+ (let ((parent (unix-namestring (pathname-directory-pathname file))))
+ (when (plusp (length parent))
+ (mrun "mkdir" "-p" parent)))
+ (mrun "mkdir" "-p" (pathname-parent-directory-pathname file)))
+ ;; likewise assume it was already there
+ :no-change))
+
;; readlink(1) is not POSIX
(defun remote-link-target (symlink)
(loop with s = (stripln (run :env '(:LOCALE "POSIX") "ls" "-ld" symlink))