Add mkdir-p.

* gash/guix-build-utils.scm (mkdir-p): New function, import from Guix.
This commit is contained in:
Jan Nieuwenhuizen 2018-10-26 22:41:01 +02:00
parent 3c57272971
commit 03fc5c928a
1 changed files with 26 additions and 0 deletions

View File

@ -44,6 +44,7 @@
grep-match-line
grep-match-column
grep-match-end-column
mkdir-p
directory-exists?
executable-file?
@ -212,3 +213,28 @@ transferred and the continuation of the transfer as a thunk."
(lambda (in)
(grep* pattern #:port in #:file-name file))))
(else (grep* pattern))))
(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))))