Browse Source

fix: save the previous content in Logseq first and commit it

to avoid overwritten when syncing with iCloud/Dropbox/syncthing.
Tienson Qin 4 years ago
parent
commit
0b55d119aa
1 changed files with 11 additions and 3 deletions
  1. 11 3
      src/main/frontend/fs/watcher_handler.cljs

+ 11 - 3
src/main/frontend/fs/watcher_handler.cljs

@@ -49,9 +49,17 @@
           (js/console.warn "Can't get file in the db: " path)
 
           (and (= "change" type)
-               (not= (string/trim content) (string/trim db-content)))
-          (p/let [_ (file-handler/alter-file repo path content {:re-render-root? true
-                                                                :from-disk? true})]
+               (not= (string/trim content) (string/trim db-content))
+               (not (string/includes? path "logseq/pages-metadata.edn")))
+          (p/let [
+                  ;; save the previous content in Logseq first and commit it to avoid
+                  ;; any data-loss.
+                  _ (file-handler/alter-file repo path db-content {:re-render-root? false
+                                                                   :reset? false
+                                                                   :skip-compare? true})
+                  _ (ipc/ipc "gitCommitAll" "Save the file from Logseq's database")
+                  _ (file-handler/alter-file repo path content {:re-render-root? true
+                                                                :skip-compare? true})]
             (set-missing-block-ids! content)
             (db/set-file-last-modified-at! repo path mtime))