From 4e9227dff3d8bfd3cd7f82e99238acff7ceb2f2f Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Fri, 8 Sep 2023 21:03:18 +0100 Subject: [PATCH] move rmtree to anoia library --- pkgs/anoia/fs.fnl | 20 ++++++++++++++++++++ pkgs/odhcp-script/odhcp6-script.fnl | 19 +------------------ 2 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 pkgs/anoia/fs.fnl diff --git a/pkgs/anoia/fs.fnl b/pkgs/anoia/fs.fnl new file mode 100644 index 00000000..ba5bfa45 --- /dev/null +++ b/pkgs/anoia/fs.fnl @@ -0,0 +1,20 @@ +(local lfs (require :lfs)) + +(fn rmtree [pathname] + (case (lfs.symlinkattributes pathname) + nil true + {:mode "directory"} + (do + (each [f (lfs.dir pathname)] + (when (not (or (= f ".") (= f ".."))) + (rmtree ( .. pathname "/" f))) + (lfs.rmdir pathname))) + {:mode "file"} + (os.remove pathname) + {:mode "link"} + (os.remove pathname) + unknown + (error (.. "can't remove " pathname " of kind \"" unknown.mode "\"")))) + + +{ : rmtree } diff --git a/pkgs/odhcp-script/odhcp6-script.fnl b/pkgs/odhcp-script/odhcp6-script.fnl index 0e18ce31..3e5983e8 100644 --- a/pkgs/odhcp-script/odhcp6-script.fnl +++ b/pkgs/odhcp-script/odhcp6-script.fnl @@ -1,23 +1,6 @@ (local { : split : merge : mkdir } (require :anoia)) (local { : view } (require :fennel)) -(local lfs (require :lfs)) - -(fn rmtree [pathname] - (case (lfs.symlinkattributes pathname) - nil true - {:mode "directory"} - (do - (each [f (lfs.dir pathname)] - (when (not (or (= f ".") (= f ".."))) - (rmtree ( .. pathname "/" f))) - (lfs.rmdir pathname))) - {:mode "file"} - (os.remove pathname) - {:mode "link"} - (os.remove pathname) - unknown - (error (.. "can't remove " pathname " of kind \"" unknown.mode "\"")))) - +(local { : rmtree } (require :anoia.fs)) (local state-directory (assert (os.getenv "SERVICE_STATE"))) (mkdir state-directory)