babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
kwrooijen 2021-02-19T07:57:32.031600Z

Hey, there was a way to write a bb script but have the first part be Bash right? e.g. the bash part would download bb in case it's not there

borkdude 2021-02-19T08:18:18.032100Z

@kevin.van.rooijen You can probably do this using the exec trick? https://gist.github.com/borkdude/2b963db1582654ec28bfd40b4dc35748#file-api_diff-clj-L1-L5

borkdude 2021-02-19T08:19:12.032600Z

I think just writing a bash script which then invokes another bb script is easier though

kwrooijen 2021-02-19T08:21:09.032800Z

Yeah that probably is

kwrooijen 2021-02-19T08:21:18.033Z

Thanks, I'll look into this

borkdude 2021-02-19T10:38:39.033400Z

New video: How to use a library from clojars in a babashka script: https://youtu.be/naEH3arI_u0 I use @seancorfield's honeysql v2 as an example.

👏 7
Eamonn Sullivan 2021-02-19T15:54:33.035200Z

@borkdude, I made a very simple (probably throw-away) PR on babashka/fs. I'm working my way slowly to the equivalent of cp -al (copy tree, with attributes, but using hard links). I also just wanted to see if I can create a PR. Feel free to ignore.

1
Eamonn Sullivan 2021-02-19T15:57:35.035300Z

Probably the way to do that is to modify ->copy-opts, maybe?

Eamonn Sullivan 2021-02-19T16:01:37.035600Z

Nah, it's not one of the standard options. I guess I'd need to use walk-file-tree.

borkdude 2021-02-19T16:02:18.035900Z

Looks good to me, the PR.

pez 2021-02-19T16:05:29.036400Z

TIL. On Youtube.

🎉 9
borkdude 2021-02-19T16:06:39.036700Z

@eamonn.sullivan Is there anything you are missing in copy-tree?

borkdude 2021-02-19T16:07:25.036900Z

Copying a tree using hard links: I'm not sure if this is something that is used a lot?

Eamonn Sullivan 2021-02-19T16:12:09.037100Z

In some back up systems, like Apple's TimeMachine (I think that's what it is called), they use hard-links to snapshot the contents of a directory as it appeared at a certain period of time in the past. Hard links are useful in that circumstance because they take up almost no extra space. It's just another name for a single inode. If the user deletes the file, the file will still exist (under a different name) if they want to recover it. My very simple babashka https://github.com/eamonnsullivan/backup-scripts/blob/main/src/eamonnsullivan/backup.clj#L33 does that.

borkdude 2021-02-19T16:12:55.037400Z

yeah, you could do that using walk-file-tree and copy-link (which I will merge now, if you have no objections?)

Eamonn Sullivan 2021-02-19T16:13:09.037600Z

Sounds good to me. Thank you!

borkdude 2021-02-19T16:14:13.037800Z

Should we also add a predicate for this?

borkdude 2021-02-19T16:15:06.038Z

Hmm, it seems the Files class doesn't have such a thing either. Maybe that doesn't apply to hard links

Eamonn Sullivan 2021-02-19T16:24:41.038400Z

I hadn't thought of that. As far as the file system is concerned, they are the exact same file, just with a different name. Like an alias, I guess. But ls knows that a file has more than one name (there is a little number that increments when you do an ls -l). So there must be some attribute that would could check.

borkdude 2021-02-19T16:30:28.038700Z

oh right

borkdude 2021-02-19T16:30:37.038900Z

yeah, I think we're good for now

Eamonn Sullivan 2021-02-19T16:43:40.039300Z

There is a method for this in java (.isSameFile path1 path2), but my Java interop chops are poor and I can't seem to get it to work.

borkdude 2021-02-19T16:44:23.039500Z

@eamonn.sullivan This is already in fs as same-file?

Eamonn Sullivan 2021-02-19T16:45:57.039700Z

As yes, so it is, and it works as a predicate. Do you want me to add that to the test?

(is (fs/same-file? (fs/file tmp-dir "dudette.txt")
                   (fs/file tmp-dir "hard-link.txt")))
Something like that?

borkdude 2021-02-19T16:47:31.039900Z

yeah, would be good to add I think

Eamonn Sullivan 2021-02-19T16:47:47.040100Z

OK, will make a separate very little PR. One sec.

borkdude 2021-02-19T16:49:06.040300Z

It's not so clear to me if same-file? will return false for a soft link, from those docs

borkdude 2021-02-19T16:49:14.040500Z

But it probably will

Eamonn Sullivan 2021-02-19T16:56:03.040700Z

https://github.com/babashka/fs/pull/15

Eamonn Sullivan 2021-02-19T16:56:23.041Z

I tried to find a create-sym-link test, but I don't see it. Just to prove that same-file? would return false here.

borkdude 2021-02-19T17:03:23.041200Z

create-sym-link is used in a bunch of places in the tests, but there is not a dedicated test for it. feel free to add it

Eamonn Sullivan 2021-02-19T17:24:46.041600Z

Well, just for your info: same-file? returns true for both sym links and hard links, so not a predicate in itself for this particular thing. But :man-shrugging: adding it to the test doesn't hurt and makes it clearer, anyway. You've made me curious now. Going to poke around this a little bit. The Posix stat() API would work, if that's possible in Java.

rwstauner 2021-02-19T17:36:57.042300Z

thank you for including hiccup in babashka ❤️ so nice.

👍 4
❤️ 2
Eamonn Sullivan 2021-02-19T18:19:02.042500Z

I've updated the pull request for the expanded test, btw.

borkdude 2021-02-19T18:21:23.042700Z

Thanks, merged