From 41f09c162e94d471e0eef75e5814d6398523bc8e Mon Sep 17 00:00:00 2001 From: Andelf Date: Wed, 15 Mar 2023 01:25:36 +0800 Subject: [PATCH] fix(fs): refine init fs-watcher --- src/main/frontend/fs/watcher_handler.cljs | 52 +++++++++++------------ 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/src/main/frontend/fs/watcher_handler.cljs b/src/main/frontend/fs/watcher_handler.cljs index e33dabcdb..e875346fc 100644 --- a/src/main/frontend/fs/watcher_handler.cljs +++ b/src/main/frontend/fs/watcher_handler.cljs @@ -6,13 +6,11 @@ [frontend.db :as db] [frontend.db.model :as model] [frontend.fs :as fs] - [frontend.fs.capacitor-fs :as capacitor-fs] [frontend.fs2.path :as fs2-path] [frontend.handler.editor :as editor] [frontend.handler.file :as file-handler] [frontend.handler.page :as page-handler] [frontend.handler.ui :as ui-handler] - [frontend.mobile.util :as mobile-util] [frontend.state :as state] [frontend.util :as util] [frontend.util.fs :as fs-util] @@ -51,7 +49,6 @@ (defn handle-changed! [type {:keys [dir path content stat global-dir] :as payload}] - (prn ::wather payload) (when dir (let [;; Global directory events don't know their originating repo so we rely ;; on the client to correctly identify it @@ -128,28 +125,27 @@ (map first) (filter #(string/starts-with? % (config/get-repo-dir graph))))] (p/let [files (fs/readdir dir :path-only? true) - _ (prn ::read-files files) - files (map #(fs2-path/relative-path dir %) files) ;; FIXME(andelf): readdir returns full paths - files (remove #(fs-util/ignored-path? dir %) files)] - (let [deleted-files (set/difference (set db-files) (set files))] - (when (seq deleted-files) - (let [delete-tx-data (->> (db/delete-files deleted-files) - (concat (db/delete-blocks graph deleted-files nil)) - (remove nil?))] - (db/transact! graph delete-tx-data {:delete-files? true}))) - (doseq [file-rpath files] - (prn ::init-watcher file-rpath) - (when-let [_ext (util/get-file-ext file-rpath)] - (-> - (p/let [content (fs/read-file dir file-rpath) - stat (fs/stat dir file-rpath) - type (if (db/file-exists? graph file-rpath) - "change" - "add")] - (handle-changed! type - {:dir dir - :path file-rpath - :content content - :stat stat})) - (p/catch (fn [error] - (js/console.dir error))))))))))) + files (map #(fs2-path/relative-path dir %) files) + files (remove #(fs-util/ignored-path? dir %) files) + deleted-files (set/difference (set db-files) (set files))] + (when (seq deleted-files) + (let [delete-tx-data (->> (db/delete-files deleted-files) + (concat (db/delete-blocks graph deleted-files nil)) + (remove nil?))] + (db/transact! graph delete-tx-data {:delete-files? true}))) + (doseq [file-rpath files] + (prn ::init-watcher file-rpath) + (when-let [_ext (util/get-file-ext file-rpath)] + (-> + (p/let [content (fs/read-file dir file-rpath) + stat (fs/stat dir file-rpath) + type (if (db/file-exists? graph file-rpath) + "change" + "add")] + (handle-changed! type + {:dir dir + :path file-rpath + :content content + :stat stat})) + (p/catch (fn [error] + (js/console.dir error))))))))))