anoia.fs.mktree replaces mkdir

This uses lfs to make the tree in-process instead of
shelling out to the mkdir command
This commit is contained in:
Daniel Barlow 2023-09-08 21:17:42 +01:00
parent 4e9227dff3
commit 9dd3cf23b4
3 changed files with 18 additions and 10 deletions

View file

@ -1,5 +1,17 @@
(local lfs (require :lfs))
(fn directory? [pathname]
(= (lfs.symlinkattributes pathname :mode) "directory"))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
(error (.. "can't mkdir " pathname)))
(or (directory? pathname)
(let [parent (string.gsub pathname "/[^/]+/?$" "")]
(or (directory? parent) (mktree parent))
(assert (lfs.mkdir pathname)))))
(fn rmtree [pathname]
(case (lfs.symlinkattributes pathname)
nil true
@ -17,4 +29,4 @@
(error (.. "can't remove " pathname " of kind \"" unknown.mode "\""))))
{ : rmtree }
{ : mktree : rmtree }

View file

@ -13,7 +13,4 @@
(fn system [s] (assert (os.execute s)))
(fn mkdir [directory]
(os.execute (.. "mkdir -p " directory)))
{ : merge : split : file-exists? : system : mkdir }
{ : merge : split : file-exists? : system }