Fork me on GitHub
#babashka
<
2020-05-10
>
borkdude11:05:24

I pushed a pre-release of the filewatcher pod. Compile yourself, or use the macOS pre-released binary. https://github.com/babashka/pod-babashka-filewatcher

sogaiu11:05:27

may be i'm doing something wrong here?

user=> (require '[babashka.pods :as pods])
nil
user=> (pods/load-pod "pod-babashka-filewatcher")
nil
user=> (def chan (pod.babashka.filewatcher/watch "/tmp"))
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 13, kind: PermissionDenied, message: "Permission denied" })', src/main.rs:122:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
#'user/chan
user=> 

borkdude11:05:47

do you have permission to the /tmp dir?

sogaiu11:05:26

it looks like i can make files there

sogaiu11:05:44

i could try another directory

sogaiu11:05:48

yes, some other directory within my home directory didn't give that error

sogaiu11:05:28

@borkdude all of the tests worked in the alternate directory 👍

sogaiu11:05:01

nice work!

sogaiu11:05:26

it even detected the removal of the directory

borkdude18:05:12

filewatcher now available on brew - also a linux binary. https://github.com/babashka/pod-babashka-filewatcher

lilactown18:05:00

for pods, does the pod need to be on the path somewhere?

nate18:05:41

Yes, that's worked for me.

borkdude19:05:12

@lilactown On the path works. But you can also give load-pod an absolute path.

borkdude19:05:25

or even command line args: (pods/load-pod ["./foo" "--bar"])

jeroenvandijk20:05:58

Really nice work on the filewatcher pod. I did some quick tests on my Mac and it works. I don’t always understand the output. E.g. sometimes it says “create” where it’s really a file update. Maybe this is a problem of the editor i’m using (in this case textmate). I have seen this behaviour with other filewatchers too. Some changes are instantly reported, some are delayed. I’m curious what the cause is of this. Given similar behaviour with the other file watchers, I’m assuming this doesn’t have anything to do with your code, might be an OSX thing

borkdude20:05:17

It's using this library: https://github.com/notify-rs/notify There is a 2 second delay, pre-configured. And events are debounced.

borkdude20:05:49

It's using version 4 of that lib, so the README on master reflects a different API

borkdude20:05:27

You could try to tweak the Rust code and see if that helps. And/or try to watch a directory that you are manually editing, not from the editor

jeroenvandijk07:05:54

Thank you, I will do some tweaking. For my own polling approach I’ve set a 50ms delay so it feels instant, but that does take more CPU. Reading the notify docs it sounds like filesystem restrictions might also force to go back to polling. I didn’t realize how complicated filewatching was 🙈

jeroenvandijk07:05:12

Does the Rust + Pod combination allow to move the configuration of the notify library to Babashka or are those compile time parameters?

borkdude07:05:00

No we can add a configuration map.

jeroenvandijk08:05:58

Sounds good. I saw there are many other options. I think I would need to study this. I don’t understand all it’s usecases 🙈

borkdude08:05:15

Me neither 🙂

borkdude08:05:37

Also in v5 they are making a lot of breaking changes to their API so I'm not sure what's going to be next 😉

borkdude08:05:04

Also: I'd like to add an unwatch function, maybe. But my Rust isn't that advanced yet...

jeroenvandijk08:05:26

It looks pretty advanced to me 😅

borkdude10:05:42

done:

(def chan (fw/watch "/tmp" {:delay-ms 0}))
should now work