Skip to content

Commit

Permalink
Use bootignore patterns in watcher workers (#663)
Browse files Browse the repository at this point in the history
* Add :ignore option to pass bootignores to make-watcher
  • Loading branch information
yannvanhalewyn authored and alandipert committed Jun 20, 2018
1 parent 300140d commit 59909f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
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))

0 comments on commit 59909f1

Please sign in to comment.