Skip to content

Commit

Permalink
[#22] delete-tree must be omnipotent
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Apr 10, 2021
1 parent 19c0397 commit 56a2c7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/babashka/fs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -451,13 +451,14 @@
(defn delete-tree
"Deletes a file tree using walk-file-tree. Similar to rm -rf. Does not follow symlinks."
[root]
(walk-file-tree root
{:visit-file (fn [path _]
(delete path)
:continue)
:post-visit-dir (fn [path _]
(delete path)
:continue)}))
(when (exists? root)
(walk-file-tree root
{:visit-file (fn [path _]
(delete path)
:continue)
:post-visit-dir (fn [path _]
(delete path)
:continue)})))

(defn create-file
"Creates empty file using Files#createFile."
Expand Down
5 changes: 4 additions & 1 deletion test/babashka/fs_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@
(fs/create-file (fs/file nested-dir "tmp-file"))
(is (fs/exists? tmp-file))
(fs/delete-tree nested-dir)
(is (not (fs/exists? nested-dir))))
(is (not (fs/exists? nested-dir)))
(testing "No exception when tree doesn't exist"
(is (do (fs/delete-tree nested-dir)
true))))
(when-not windows?
(testing "delete-tree does not follow symlinks"
(let [tmp-dir1 (temp-dir)
Expand Down

0 comments on commit 56a2c7e

Please sign in to comment.