Fork me on GitHub
#babashka
<
2021-02-19
>
Kevin07:02:32

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

borkdude08:02:12

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

Kevin08:02:09

Yeah that probably is

Kevin08:02:18

Thanks, I'll look into this

borkdude10:02:39

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.

👏 24
Eamonn Sullivan15:02:33

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

thumbsup_all 3
Eamonn Sullivan15:02:35

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

Eamonn Sullivan16:02:37

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

borkdude16:02:18

Looks good to me, the PR.

borkdude16:02:39

@UR71VR71S Is there anything you are missing in copy-tree?

borkdude16:02:25

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

Eamonn Sullivan16:02:09

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.

borkdude16:02:55

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

Eamonn Sullivan16:02:09

Sounds good to me. Thank you!

borkdude16:02:13

Should we also add a predicate for this?

borkdude16:02:06

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

Eamonn Sullivan16:02:41

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.

borkdude16:02:37

yeah, I think we're good for now

Eamonn Sullivan16:02:40

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.

borkdude16:02:23

@UR71VR71S This is already in fs as same-file?

Eamonn Sullivan16:02:57

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?

borkdude16:02:31

yeah, would be good to add I think

Eamonn Sullivan16:02:47

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

borkdude16:02:06

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

borkdude16:02:14

But it probably will

Eamonn Sullivan16:02:23

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.

borkdude17:02:23

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 Sullivan17:02:46

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.

Eamonn Sullivan18:02:02

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

borkdude18:02:23

Thanks, merged

pez16:02:29

TIL. On Youtube.

🎉 27
rwstauner17:02:57

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

👍 12
❤️ 6