fs.fnl (879B)
1 (local lfs (require :lfs)) 2 3 (fn directory? [pathname] 4 (= (lfs.symlinkattributes pathname :mode) "directory")) 5 6 (fn mktree [pathname] 7 (if (or (= pathname "") (= pathname "/")) 8 (error (.. "can't mkdir " pathname))) 9 10 (or (directory? pathname) 11 (let [parent (string.gsub pathname "/[^/]+/?$" "")] 12 (or (directory? parent) (mktree parent)) 13 (assert (lfs.mkdir pathname))))) 14 15 (fn rmtree [pathname] 16 (case (lfs.symlinkattributes pathname) 17 nil true 18 {:mode "directory"} 19 (do 20 (each [f (lfs.dir pathname)] 21 (when (not (or (= f ".") (= f ".."))) 22 (rmtree ( .. pathname "/" f))) 23 (lfs.rmdir pathname))) 24 {:mode "file"} 25 (os.remove pathname) 26 {:mode "link"} 27 (os.remove pathname) 28 unknown 29 (error (.. "can't remove " pathname " of kind \"" unknown.mode "\"")))) 30 31 32 { 33 : mktree 34 : rmtree 35 : directory? 36 }