Fork me on GitHub
#babashka
<
2024-07-07
>
teodorlu13:07:16

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

teodorlu13:07:51

This seems to delete file trees on exit:

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

borkdude14:07:15

@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?

borkdude14:07:18

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
borkdude14:07:14

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
teodorlu14:07:52

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

borkdude14:07:58

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

👀 1
borkdude14:07:23

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

👍 1
teodorlu14:07:41

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?

borkdude20:07:41

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. :)