Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use bootignore patterns in watcher workers #663

Merged
merged 2 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion boot/core/src/boot/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,8 @@
(let [q (LinkedBlockingQueue.)
watcher (apply file/watcher! :time dirs)
paths (into-array String dirs)
k (pod/with-invoke-worker (boot.watcher/make-watcher q paths))]
k (pod/with-invoke-worker
(boot.watcher/make-watcher q paths :ignore @bootignore))]
(daemon
(loop [ret (util/guard [(.take q)])]
(when ret
Expand Down
16 changes: 8 additions & 8 deletions boot/worker/src/boot/watcher.clj
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@
(get x))))

(defn- register-recursive
[service path events]
(when @util/*watchers?*
[service path events ignore-patterns]
(when (and @util/*watchers?*
(not-any? #(re-find % (str path)) ignore-patterns))
(util/dbug* "registering %s %s\n" path events)
(register service path events)
(doseq [dir (.listFiles (io/file path))]
(when (.isDirectory dir)
(register-recursive service dir events)))))
(register-recursive service dir events ignore-patterns)))))

(defn- new-watch-service []
(if (= "Mac OS X" (System/getProperty "os.name"))
Expand All @@ -89,9 +90,9 @@
(.offer queue "changed!"))

(defn- service
[queue paths]
[queue paths ignore-patterns]
(let [service (new-watch-service)
doreg #(register-recursive %1 %2 [:create :modify :delete])]
doreg #(register-recursive %1 %2 [:create :modify :delete] ignore-patterns)]
(doseq [path paths] (doreg service (io/file path)))
(-> #(let [watch-key (take-watch-key service)]
(when-let [path (and watch-key (or (.watchable watch-key) ""))]
Expand Down Expand Up @@ -121,10 +122,9 @@
(when-let [w (@watchers k)] (.close w)))

(defn make-watcher
[queue paths]
[queue paths & {:keys [ignore]}]
(let [k (str (gensym))
s (service queue paths)
fs (->> paths (mapcat (comp file-seq io/file)) (filter (memfn isFile)))]
s (service queue paths ignore)]
(swap! watchers assoc k s)
(send-it! queue)
k))