瀏覽代碼

fix(sync): check sync-state is valid to accept filewatcher events

rcmerci 3 年之前
父節點
當前提交
41b4cdb938
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      src/main/frontend/fs/sync.cljs

+ 9 - 1
src/main/frontend/fs/sync.cljs

@@ -1591,6 +1591,7 @@
    (map #(partition-all n %))
    cat))
 
+(declare sync-state--valid-to-accept-filewatcher-event?)
 (defonce local-changes-chan (chan (async/dropping-buffer 1000)))
 (defn file-watch-handler
   "file-watcher callback"
@@ -1598,7 +1599,7 @@
   (when-let [current-graph (state/get-current-repo)]
     (when (string/ends-with? current-graph dir)
       (let [sync-state (state/get-file-sync-state current-graph)]
-        (when (and sync-state (not (sync-state--stopped? sync-state)))
+        (when (and sync-state (sync-state--valid-to-accept-filewatcher-event? sync-state))
           (when (or (:mtime stat) (= type "unlink"))
             (go
               (let [path (remove-dir-prefix dir path)
@@ -2039,6 +2040,13 @@
   {:pre [(s/valid? ::sync-state sync-state)]}
   (= ::stop (:state sync-state)))
 
+(defn sync-state--valid-to-accept-filewatcher-event?
+  [sync-state]
+  {:pre [(s/valid? ::sync-state sync-state)]}
+  (contains? #{::idle ::local->remote ::remote->local ::local->remote-full-sync ::remote->local-full-sync}
+             (:state sync-state)))
+
+
 ;;; ### remote->local syncer & local->remote syncer
 
 (defprotocol IRemote->LocalSync