Fork me on GitHub

Am I correct in assuming that babashka.fs/delete-on-exit works for files, but not for folders? My testing seems to indicate that.


This seems to delete file trees on exit:

(defn delete-tree-on-exit [root]
  (.addShutdownHook (Runtime/getRuntime)
                    (Thread. ^Runnable #(fs/delete-tree root))))


@U3X7174KS delete-on-exit simply defers to Java's behavior. Perhaps a directory can't/won't be deleted if it contains files or so?


yeah that seems to be the case:

$ bb -e '(doto (fs/create-dirs "/tmp/1/2/3") fs/delete-on-exit)'
#object[sun.nio.fs.UnixPath 0x14ec564c "/tmp/1/2/3"]
$ ls /tmp/1/2

👍 1

This won't delete the /tmp/1/2/3 dir:

bb -e '(doto (fs/create-dirs "/tmp/1/2/3") fs/delete-on-exit) (spit "/tmp/1/2/3/dude.txt" "hello")'

👍 1

Right, thanks, I’m seeing the same behavior, fs/delete-on-exit deletes empty directories, but leaves non-empty directories as they are.


but if you mark that inner file with delete-on-exit then the dir will be removed as well

👀 1

so tl;dr, everything has to be recursively marked as delete-on-exit

👍 1

Got it—thank you! 🙏

Jonathan D Johnston19:07:03

I have a tree of git clones & use a bb script to walk the tree to report when they have been updated, based on index file datetime stamp. I'd like to automate more, say updating ones that are stale. I could call git from bb, but I was surprised that there didn't seem to be a bb libgit wrapper or pod. Or did I miss it among the multitude of Babashka tools?


for git shelling out is usually what is done

Jonathan D Johnston20:07:53

Thanks! Just wanted to make sure I wasn't missing some cool lib / tool. :)