summaryrefslogtreecommitdiff
path: root/guix/build/utils.scm
diff options
context:
space:
mode:
Diffstat (limited to 'guix/build/utils.scm')
-rw-r--r--guix/build/utils.scm26
1 files changed, 26 insertions, 0 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index d1d3116c45..0543ab48d5 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -26,6 +26,7 @@
#:use-module (rnrs io ports)
#:export (directory-exists?
with-directory-excursion
+ mkdir-p
set-path-environment-variable
search-path-as-string->list
list->search-path-as-string
@@ -62,6 +63,31 @@
(lambda ()
(chdir init)))))
+(define (mkdir-p dir)
+ "Create directory DIR and all its ancestors."
+ (define absolute?
+ (string-prefix? "/" dir))
+
+ (define not-slash
+ (char-set-complement (char-set #\/)))
+
+ (let loop ((components (string-tokenize dir not-slash))
+ (root (if absolute?
+ ""
+ ".")))
+ (match components
+ ((head tail ...)
+ (let ((path (string-append root "/" head)))
+ (catch 'system-error
+ (lambda ()
+ (mkdir path)
+ (loop tail path))
+ (lambda args
+ (if (= EEXIST (system-error-errno args))
+ (loop tail path)
+ (apply throw args))))))
+ (() #t))))
+
;;;
;;; Search paths.