浏览代码

fix: backup the file in db when moving a file with a different case

Tienson Qin 2 年之前
父节点
当前提交
160c09851f
共有 2 个文件被更改,包括 19 次插入2 次删除
  1. 14 1
      src/main/frontend/fs.cljs
  2. 5 1
      src/main/frontend/handler/common/file.cljs

+ 14 - 1
src/main/frontend/fs.cljs

@@ -15,7 +15,8 @@
             [frontend.db :as db]
             [frontend.db :as db]
             [clojure.string :as string]
             [clojure.string :as string]
             [frontend.state :as state]
             [frontend.state :as state]
-            [logseq.graph-parser.util :as gp-util]))
+            [logseq.graph-parser.util :as gp-util]
+            [electron.ipc :as ipc]))
 
 
 (defonce nfs-record (nfs/->Nfs))
 (defonce nfs-record (nfs/->Nfs))
 (defonce bfs-record (bfs/->Bfs))
 (defonce bfs-record (bfs/->Bfs))
@@ -229,3 +230,15 @@
 (defn dir-exists?
 (defn dir-exists?
   [dir]
   [dir]
   (file-exists? dir ""))
   (file-exists? dir ""))
+
+(defn backup-db-file!
+  [repo path db-content disk-content]
+  (cond
+    (util/electron?)
+    (ipc/ipc "backupDbFile" (config/get-local-dir repo) path db-content disk-content)
+
+    (mobile-util/native-platform?)
+    (capacitor-fs/backup-file repo :backup-dir path db-content)
+
+    ;; TODO: nfs
+    ))

+ 5 - 1
src/main/frontend/handler/common/file.cljs

@@ -10,8 +10,10 @@
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.util :as gp-util]
             [logseq.graph-parser.config :as gp-config]
             [logseq.graph-parser.config :as gp-config]
             [frontend.fs.capacitor-fs :as capacitor-fs]
             [frontend.fs.capacitor-fs :as capacitor-fs]
+            [frontend.fs :as fs]
             [frontend.context.i18n :refer [t]]
             [frontend.context.i18n :refer [t]]
-            [clojure.string :as string]))
+            [clojure.string :as string]
+            [promesa.core :as p]))
 
 
 (defn- page-exists-in-another-file
 (defn- page-exists-in-another-file
   "Conflict of files towards same page"
   "Conflict of files towards same page"
@@ -30,6 +32,8 @@
            (string/lower-case file-path))
            (string/lower-case file-path))
         ;; case renamed
         ;; case renamed
         (when-let [file (db/pull [:file/path current-file])]
         (when-let [file (db/pull [:file/path current-file])]
+          (p/let [disk-content (fs/read-file "" current-file)]
+            (fs/backup-db-file! repo-url current-file (:file/content file) disk-content))
           (db/transact! repo-url [{:db/id (:db/id file)
           (db/transact! repo-url [{:db/id (:db/id file)
                                    :file/path file-path}]))
                                    :file/path file-path}]))