|
|
@@ -205,6 +205,54 @@
|
|
|
:modified modified
|
|
|
:deleted deleted}))
|
|
|
|
|
|
+(defn- handle-diffs!
|
|
|
+ [repo nfs? old-files new-files handle-path path-handles re-index?]
|
|
|
+ (let [get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
|
|
|
+ {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files)
|
|
|
+ ;; Use the same labels as isomorphic-git
|
|
|
+ rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file}) col))
|
|
|
+ _ (when (and nfs? (seq deleted))
|
|
|
+ (let [deleted (doall
|
|
|
+ (-> (map (fn [path] (if (= "/" (first path))
|
|
|
+ path
|
|
|
+ (str "/" path))) deleted)
|
|
|
+ (distinct)))]
|
|
|
+ (p/all (map (fn [path]
|
|
|
+ (let [handle-path (str handle-path path)]
|
|
|
+ (idb/remove-item! handle-path)
|
|
|
+ (nfs/remove-nfs-file-handle! handle-path))) deleted))))
|
|
|
+ added-or-modified (set (concat added modified))
|
|
|
+ _ (when (and nfs? (seq added-or-modified))
|
|
|
+ (p/all (map (fn [path]
|
|
|
+ (when-let [handle (get @path-handles path)]
|
|
|
+ (idb/set-item! (str handle-path path) handle))) added-or-modified)))]
|
|
|
+ (-> (p/all (map (fn [path]
|
|
|
+ (when-let [file (get-file-f path new-files)]
|
|
|
+ (p/let [content (if nfs?
|
|
|
+ (.text (:file/file file))
|
|
|
+ (:file/content file))]
|
|
|
+ (assoc file :file/content content)))) added-or-modified))
|
|
|
+ (p/then (fn [result]
|
|
|
+ (let [files (map #(dissoc % :file/file :file/handle) result)
|
|
|
+ non-modified? (fn [file]
|
|
|
+ (let [content (:file/content file)
|
|
|
+ old-content (:file/content (get-file-f (:file/path file) old-files))]
|
|
|
+ (= content old-content)))
|
|
|
+ non-modified-files (->> (filter non-modified? files)
|
|
|
+ (map :file/path))
|
|
|
+ [modified-files modified] (if re-index?
|
|
|
+ [files (set modified)]
|
|
|
+ [(remove non-modified? files) (set/difference (set modified) (set non-modified-files))])
|
|
|
+ diffs (concat
|
|
|
+ (rename-f "remove" deleted)
|
|
|
+ (rename-f "add" added)
|
|
|
+ (rename-f "modify" modified))]
|
|
|
+ (when (or (and (seq diffs) (seq modified-files))
|
|
|
+ (seq diffs))
|
|
|
+ (repo-handler/load-repo-to-db! repo
|
|
|
+ {:diffs diffs
|
|
|
+ :nfs-files modified-files}))))))))
|
|
|
+
|
|
|
(defn- reload-dir!
|
|
|
([repo]
|
|
|
(reload-dir! repo false))
|
|
|
@@ -236,53 +284,8 @@
|
|
|
(contains? file-paths
|
|
|
(string/replace-first path (str dir-name "/") ""))))
|
|
|
(into {})))))
|
|
|
- (set-files! @path-handles))
|
|
|
- get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files))
|
|
|
- {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files)
|
|
|
- ;; Use the same labels as isomorphic-git
|
|
|
- rename-f (fn [typ col] (mapv (fn [file] {:type typ :path file}) col))
|
|
|
- _ (when (and nfs? (seq deleted))
|
|
|
- (let [deleted (doall
|
|
|
- (-> (map (fn [path] (if (= "/" (first path))
|
|
|
- path
|
|
|
- (str "/" path))) deleted)
|
|
|
- (distinct)))]
|
|
|
- (p/all (map (fn [path]
|
|
|
- (let [handle-path (str handle-path path)]
|
|
|
- (idb/remove-item! handle-path)
|
|
|
- (nfs/remove-nfs-file-handle! handle-path))) deleted))))
|
|
|
- added-or-modified (set (concat added modified))
|
|
|
- _ (when (and nfs? (seq added-or-modified))
|
|
|
- (p/all (map (fn [path]
|
|
|
- (when-let [handle (get @path-handles path)]
|
|
|
- (idb/set-item! (str handle-path path) handle))) added-or-modified)))]
|
|
|
- (-> (p/all (map (fn [path]
|
|
|
- (when-let [file (get-file-f path new-files)]
|
|
|
- (p/let [content (if nfs?
|
|
|
- (.text (:file/file file))
|
|
|
- (:file/content file))]
|
|
|
- (assoc file :file/content content)))) added-or-modified))
|
|
|
- (p/then (fn [result]
|
|
|
- (let [files (map #(dissoc % :file/file :file/handle) result)
|
|
|
- non-modified? (fn [file]
|
|
|
- (let [content (:file/content file)
|
|
|
- old-content (:file/content (get-file-f (:file/path file) old-files))]
|
|
|
- (= content old-content)))
|
|
|
- non-modified-files (->> (filter non-modified? files)
|
|
|
- (map :file/path))
|
|
|
- [modified-files modified] (if re-index?
|
|
|
- [files (set modified)]
|
|
|
- [(remove non-modified? files) (set/difference (set modified) (set non-modified-files))])
|
|
|
- diffs (concat
|
|
|
- (rename-f "remove" deleted)
|
|
|
- (rename-f "add" added)
|
|
|
- (rename-f "modify" modified))]
|
|
|
- (when (or (and (seq diffs) (seq modified-files))
|
|
|
- (seq diffs) ; delete
|
|
|
-)
|
|
|
- (repo-handler/load-repo-to-db! repo
|
|
|
- {:diffs diffs
|
|
|
- :nfs-files modified-files})))))))))
|
|
|
+ (set-files! @path-handles))]
|
|
|
+ (handle-diffs! repo nfs? old-files new-files handle-path path-handles re-index?))))
|
|
|
(p/catch (fn [error]
|
|
|
(log/error :nfs/load-files-error error)))
|
|
|
(p/finally (fn [_]
|