convert anoia.fs to use lualinux

This commit is contained in:
Daniel Barlow
2024-04-25 21:14:37 +01:00
parent dbd1264352
commit cdb23b147c
9 changed files with 44 additions and 21 deletions

View File

@@ -11,9 +11,20 @@
(fn ifmt-bits [mode] (and mode (band mode 0xf000)))
(fn file-type [pathname]
(. {
S_IFDIR :directory
S_IFSOCK :socket
S_IFLNK :link
S_IFREG :file
S_IFBLK :block-device
S_IFCHR :character-device
S_IFIFO :fifo
}
(ifmt-bits (ll.lstat3 pathname))))
(fn directory? [pathname]
(let [(mode size mtime) (ll.lstat3 pathname)]
(= (ifmt-bits mode) S_IFDIR)))
(= (file-type pathname) :directory))
(fn mktree [pathname]
(if (or (= pathname "") (= pathname "/"))
@@ -24,18 +35,25 @@
(or (directory? parent) (mktree parent))
(assert (ll.mkdir pathname)))))
(fn dir [name]
(let [dp (assert (ll.opendir name) name)]
(fn []
(match (ll.readdir dp)
(name type) (values name type)
(nil err) (do (if err (print err)) (ll.closedir dp) nil)))))
(fn rmtree [pathname]
(case (ifmt-bits (ll.lstat3 pathname))
(case (file-type pathname)
nil true
S_IFDIR
:directory
(do
(each [f (lfs.dir pathname)]
(each [f (dir pathname)]
(when (not (or (= f ".") (= f "..")))
(rmtree ( .. pathname "/" f)))
(lfs.rmdir pathname)))
S_IFREG
(ll.rmdir pathname)))
:file
(os.remove pathname)
S_IFLNK
:link
(os.remove pathname)
unknown
(error (.. "can't remove " pathname " of mode \"" unknown "\""))))
@@ -45,5 +63,7 @@
: mktree
: rmtree
: directory?
: dir
: file-type
:symlink (fn [from to] (ll.symlink from to))
}