Skip to content
Open
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 project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[net.incongru.watchservice/barbary-watchservice "1.0"]]
:plugins [[lein-modules "0.3.10"]]
:profiles {:dev
{:dependencies [[org.clojure/core.async "0.1.346.0-17112a-alpha"]]}}
{:dependencies [[org.clojure/core.async "0.1.346.0-17112a-alpha"]]
:global-vars {*warn-on-reflection* true}}}
:modules {:subprocess false
:inherited {:url "https://github.com/wkf/hawk"
:scm {:name "git"
Expand Down
20 changes: 11 additions & 9 deletions src/main/clojure/hawk/core.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns hawk.core
(:require [clojure.java.io :as io]
[hawk.watcher :refer [new-watcher] :as watcher]))
[hawk.watcher :refer [new-watcher] :as watcher])
(:import [java.io File]))

(defn catch-errors [f]
(fn [& args]
Expand All @@ -13,13 +14,13 @@
(merge spec
(->> paths
(map #(-> % io/file .getCanonicalFile))
(group-by #(if (.isFile %) :files :directories)))))
(group-by #(if (.isFile ^File %) :files :directories)))))

(defn process-paths [{:keys [files directories] :as spec}]
(assoc spec :paths
(concat
(map #(-> % .toPath) directories)
(map #(-> % .getParentFile .toPath) files))))
(map #(.toPath ^File %) directories)
(map #(-> (.getParentFile ^File %) .toPath) files))))

(defn process-context [spec]
(assoc spec :context
Expand All @@ -30,7 +31,7 @@
(assoc spec :handler
(catch-errors
(fn [ctx {:keys [file kind] :as e}]
(let [path (-> file .toPath)]
(let [path (.toPath ^File file)]
(if (and
(some #(.startsWith path %) paths)
(or (empty? files)
Expand Down Expand Up @@ -92,15 +93,16 @@
:watcher watcher}))

(defn stop! [watch]
(doto
(:thread watch) .interrupt .join)
(let [thread ^Thread (:thread watch)]
(.interrupt thread)
(.join thread))
(-> watch :watcher watcher/stop!))

(defn file? [_ {:keys [file]}]
(.isFile file))
(.isFile ^File file))

(defn directory? [_ {:keys [file]}]
(.isDirectory file))
(.isDirectory ^File file))

(defn created? [_ {:keys [kind]}]
(= kind :create))
Expand Down