Skip to content

Commit

Permalink
Warn on fileset merge conflicts
Browse files Browse the repository at this point in the history
- fixes #361
- fixes #364
  • Loading branch information
micha committed Dec 19, 2015
1 parent 5a2e91d commit d5810ba
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions boot/pod/src/boot/tmpdir.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
(set! *warn-on-reflection* true)

(def CACHE_VERSION "1.0.0")
(def state (atom {:prev {} :cache {}}))
(def state (atom {:prev {} :cache {}}))

;; records and protocols ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Expand Down Expand Up @@ -208,6 +208,15 @@
:removed (->> (set/difference x y) (select-keys t1) (assoc after :tree))
:changed (->> (set/intersection x y) (select-keys t2) (assoc after :tree))})))

(defn- fatal-conflict?
[^File dest]
(if (.isDirectory dest)
(let [tree (->> dest file-seq reverse)]
(or (not (every? #(.isDirectory ^File %) tree))
(doseq [^File f tree] (.delete f))))
(not (let [d (.getParentFile dest)]
(or (.isDirectory d) (.mkdirs d))))))

;; fileset implementation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defrecord TmpFileSet [dirs tree blob scratch]
Expand All @@ -225,9 +234,14 @@
(when (.exists ^File (file prev))
(util/dbug "Removing %s...\n" (path prev))
(file/delete-file (file prev))))
(doseq [tmpf (set/union (ls added) (ls changed))]
(doseq [tmpf (->> (set/union (ls added) (ls changed))
(sort-by (comp count path) >))]
(util/dbug "Adding %s...\n" (path tmpf))
(file/copy-with-lastmod (io/file (bdir tmpf) (id tmpf)) (file tmpf)))
(let [src (io/file (bdir tmpf) (id tmpf))
dst (file tmpf)]
(if (fatal-conflict? dst)
(util/warn "Merge conflict: %s\n" (path tmpf))
(file/hard-link src dst))))
(swap! state assoc-in [:prev dirs] this))))

(rm [this tmpfiles]
Expand Down

0 comments on commit d5810ba

Please sign in to comment.