Fork me on GitHub
#babashka
<
2023-01-28
>
Richie00:01:35

This works in a Dockerfile. I just thought that was neat. Idk if it's very useful yet though.

SHELL ["bb", "-e"]
RUN (spit "config.yml" (cheshire.core/generate-string (clojure.edn/read-string (slurp "config.edn"))))

Richie02:01:14

I think I want to call last-modified but it's private. https://github.com/babashka/fs/blob/8a8bfa618be6f0c1b21be0daafd1887e2a4f5c44/src/babashka/fs.cljc#L867 I want to compare against the LastTagTime of a docker image to know if I should rebuild or skip. This seems like the perfect function for that.

Richie02:01:52

Calling it like (#'last-modified whatever) doesn't work.

lispyclouds08:01:42

I’d probably use the .lastModified method for File via interop than trying to get the private fn to work if I’m just comparing times.

borkdude08:01:24

Use modified-since

lispyclouds08:01:28

@U04V15CAJ that would not support comparing with a timestamp right? it needs another file? i think the use case is to compare with a timestamp

borkdude08:01:40

Yep and there are also functions to convert that result to a long etc

Richie12:01:43

Right, modified-since is closest to what I want since it can take a directory and walk it recursively to find the latest modified time. I don't want to compare against another file though, I want to compare it to another time. last-modified-time only works on one file so I'd have to recurse myself. https://github.com/babashka/fs/blob/8a8bfa618be6f0c1b21be0daafd1887e2a4f5c44/src/babashka/fs.cljc#L873-L875

Richie14:01:04

I copied last-modified and last-modified-1 into my code.

borkdude14:01:28

maybe we could change modified-since to also accept a time (or times) to compare against

borkdude14:01:50

I don't think there is a need to copy last-modified since you can use fs/last-modified-time

borkdude14:01:19

+ fs/file-time->millis

borkdude14:01:06

but feel free to do so :)

thanks3 2
Richie15:01:46

last-modified-time only works against one file, right? I was trying to reuse the code that finds the latest of many files in a folder.

borkdude15:01:35

you can do that like this:

$ bb -e '(map (comp fs/file-time->millis fs/last-modified-time) (fs/glob "." "**"))'
(1674917980174 1674917980162 1674917980162 1674917980172 1674917980171 1674917980171 1674917980172

borkdude15:01:16

$ bb -e '(apply max 0 (map (comp fs/file-time->millis fs/last-modified-time) (fs/glob "." "**")))'
1674917980175

Richie15:01:29

Ok, yea. That's a good idea, thanks!

Richie18:01:48

(fs/glob "." "**") gives:

java.nio.file.NoSuchFileException: c:\Users\me\containers\homer\out\bin\arch
 at sun.nio.fs.WindowsFileSystemProvider.isHidden (WindowsFileSystemProvider.java:471)
emacs says that arch is "a symlink to a nonexistent target"

Richie18:01:44

it's from running docker build -o out .

borkdude18:01:40

Can you give a fuller reproduction of what you're doing?

borkdude18:01:57

as in, are you executing this from the command line or how?

Richie19:01:15

I just reproduced it by making a symlink to a file and then deleting the file. e.g. I made the file target , made a symlink (in cmd.exe mklink link target), deleted target, and then in my bb nrepl (fs/glob "." "**") gives

java.nio.file.NoSuchFileException: c:\Users\me\test\link
 at sun.nio.fs.WindowsFileSystemProvider.isHidden (WindowsFileSystemProvider.java:471)

borkdude19:01:44

try (glob "." "**" {:follow-links false})

Richie19:01:16

(fs/glob "." "**" {:follow-links false})

borkdude19:01:54

Try :hidden true

borkdude19:01:14

I think you can reproduce this with (fs/hidden? the-dead-link)

borkdude19:01:27

The smaller your repro the better

Richie19:01:56

Yea, java.nio.file.NoSuchFileException: test\link (fs/hidden? "test/link")

borkdude19:01:23

Let me try to repro that locally

borkdude19:01:41

lrwxr-xr-x   1 borkdude  wheel     1 Jan 28 20:07 a -> b
drwxrwxrwt  51 root      wheel  1632 Jan 28 20:06 ..
borkdude@m1 /tmp/test-link $ bb -e '(fs/hidden? "a")'
false

borkdude19:01:26

Can you try to repro this using (java.nio.file.Files/isHidden (fs/path "a"))

borkdude19:01:34

Can you try :hidden true in glob

borkdude19:01:40

that skips the hidden? check

Richie19:01:01

(Files/isHidden (.toPath (fs/file "test/link")))

java.nio.file.NoSuchFileException: test\link
 at sun.nio.fs.WindowsFileSystemProvider.isHidden (WindowsFileSystemProvider.java:471)

Richie19:01:25

(fs/glob "test" "**" {:hidden true}) is fine

Richie19:01:34

[#object[sun.nio.fs.WindowsPath 0x1803c3ff "test\\link"]]

borkdude22:01:52

1200 people in this channel! 🎉

🎉 30
🚀 30
babashka 14