Merge pull request #9 from j0ni/checksums
Use checksums instead of last modified times.
This commit is contained in:
commit
98d93e7921
2 changed files with 35 additions and 25 deletions
33
project.clj
33
project.clj
|
@ -1,16 +1,17 @@
|
||||||
(defproject cryogen-core "0.1.10"
|
(defproject cryogen-core "0.1.11-SNAPSHOT"
|
||||||
:description "Cryogen's compiler"
|
:description "Cryogen's compiler"
|
||||||
:url "https://github.com/lacarmen/cryogen-core"
|
:url "https://github.com/lacarmen/cryogen-core"
|
||||||
:license {:name "Eclipse Public License"
|
:license {:name "Eclipse Public License"
|
||||||
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
:url "http://www.eclipse.org/legal/epl-v10.html"}
|
||||||
:dependencies [[org.clojure/clojure "1.6.0"]
|
:dependencies [[org.clojure/clojure "1.6.0"]
|
||||||
[clj-rss "0.1.9"]
|
[clj-rss "0.1.9"]
|
||||||
[me.raynes/fs "1.4.6"]
|
[me.raynes/fs "1.4.6"]
|
||||||
[crouton "0.1.2"]
|
[crouton "0.1.2"]
|
||||||
[cheshire "5.4.0"]
|
[cheshire "5.4.0"]
|
||||||
[clj-text-decoration "0.0.3"]
|
[clj-text-decoration "0.0.3"]
|
||||||
[io.aviso/pretty "0.1.13"]
|
[io.aviso/pretty "0.1.13"]
|
||||||
[hiccup "1.0.5"]
|
[hiccup "1.0.5"]
|
||||||
[selmer "0.7.8"]
|
[selmer "0.7.8"]
|
||||||
[markdown-clj "0.9.61"
|
[markdown-clj "0.9.61"
|
||||||
:exclusions [com.keminglabs/cljx]]])
|
:exclusions [com.keminglabs/cljx]]
|
||||||
|
[pandect "0.4.1"]])
|
||||||
|
|
|
@ -1,24 +1,33 @@
|
||||||
(ns cryogen-core.watcher
|
(ns cryogen-core.watcher
|
||||||
(:require [clojure.java.io :refer [file]]
|
(:require [clojure.java.io :refer [file]]
|
||||||
[cryogen-core.io :refer [ignore]]))
|
[cryogen-core.io :refer [ignore]]
|
||||||
|
[pandect.core :refer [md5]]
|
||||||
|
[clojure.set :as set]))
|
||||||
|
|
||||||
(defn get-assets [root ignored-files]
|
(defn get-assets [path ignored-files]
|
||||||
(->> root
|
(->> path
|
||||||
file
|
file
|
||||||
file-seq
|
file-seq
|
||||||
(filter #(not (.isDirectory %)))
|
(filter #(not (.isDirectory %)))
|
||||||
(filter (ignore ignored-files))))
|
(filter (ignore ignored-files))))
|
||||||
|
|
||||||
(defn sum-times [path ignored-files]
|
(defn checksums [path ignored-files]
|
||||||
(->> (get-assets path ignored-files) (map #(.lastModified %)) (reduce +)))
|
(let [files (get-assets path ignored-files)]
|
||||||
|
(zipmap (map md5 files) files)))
|
||||||
|
|
||||||
|
(defn find-changes [old-sums new-sums]
|
||||||
|
(let [old-sum-set (-> old-sums keys set)
|
||||||
|
new-sum-set (-> new-sums keys set)]
|
||||||
|
(when-some [changes (set/difference new-sum-set old-sum-set)]
|
||||||
|
(vals (select-keys new-sums changes)))))
|
||||||
|
|
||||||
(defn watch-assets [root ignored-files action]
|
(defn watch-assets [root ignored-files action]
|
||||||
(loop [times (sum-times root ignored-files)]
|
(loop [sums (checksums root ignored-files)]
|
||||||
(Thread/sleep 300)
|
(Thread/sleep 300)
|
||||||
(let [new-times (sum-times root ignored-files)]
|
(let [new-sums (checksums root ignored-files)]
|
||||||
(when-not (= times new-times)
|
(when (find-changes sums new-sums)
|
||||||
(action))
|
(action))
|
||||||
(recur new-times))))
|
(recur new-sums))))
|
||||||
|
|
||||||
(defn start-watcher! [root ignored-files action]
|
(defn start-watcher! [root ignored-files action]
|
||||||
(doto (Thread. #(watch-assets root ignored-files action))
|
(doto (Thread. #(watch-assets root ignored-files action))
|
||||||
|
|
Loading…
Reference in a new issue