wkf / hawk

Clojure file and directory watcher using the JDK 7 java.nio.file.WatchService and Barbary WatchService
https://wkf.github.com/hawk
Eclipse Public License 1.0
187 stars 16 forks source link

recursive works on creating a watcher, but not for new directory additions #16

Open jmarca opened 8 years ago

jmarca commented 8 years ago

Hi, just playing around with hawk, learning clojure, etc.

I noticed that if I add a directory, the watcher previously set no longer watches the new directory

For example, if I do:

(hawk/watch! [{:paths ["/tmp/darktable_exported"]
               :handler (fn [ctx e]
                          (println "event: " e)
                          (println "context: " ctx)
                          ctx)}])

and do:

mkdir /tmp/darktable_exported/August_2016

I see in the repl:

event:  {:file #object[java.io.File 0x1c5661ba /tmp/darktable_exported/August_2016], :kind :create}
context:  {}

But then when I do:

touch /tmp/darktable_exported/August_2016/1.jpg

I see nothing in the repl.

If I restart the watcher, it will see the 1.jpg addition:

boot.user=> event:  {:file #object[java.io.File 0x2c8a60ac /tmp/darktable_exported/August_2016/1.jpg], :kind :create}
context:  {}
event:  {:file #object[java.io.File 0x173395d8 /tmp/darktable_exported/August_2016/1.jpg], :kind :modify}
context:  {}

So one fix from my end is to just check if the addition is a directory, and if it is, then toggle my watcher off and on. I also read in one of the other directory watching implementations that there is some sort of bug with recursively watching new directories, so actually fixing this within hawk is likely well beyond my freshly-minted clojure skill.

wkf commented 8 years ago

Hey, sorry about the late response. I like to think I'll have some time to review this afternoon. Thanks for the bug report!

bhauman commented 7 years ago

I'd like to upvote this.

wkf commented 7 years ago

Hey, sorry folks, and thanks @bhauman for the poke. I've been fairly busy with my day job, but I'm taking a look right now.

vans163 commented 7 years ago

il xref this https://github.com/bhauman/lein-figwheel/issues/496

wkf commented 7 years ago

Hey folks, would you mind giving 0.2.11 a shot to make sure it resolves your issue? If not, I'll reopen. Thanks for your patience. 😅

vans163 commented 7 years ago

@wkf This works for the most part. If you mv a folder though it does not watch it.

wkf commented 7 years ago

@vans163 did you mv a folder from outside your watch folder inside your watch folder, or did you move a folder that was previously being watched?

vans163 commented 7 years ago

previously watched. same folder. So folder1 and folder2 is watched currently.

folder1
  - folder2

becomes

folder1
  - folder3

New/saved files in folder3 now are not tracked. Not sure if I checked moving from outside a watched folder into one. (that should be checked too)