浏览代码

fix: the file has been modified...

Tienson Qin 4 年之前
父节点
当前提交
5097f23f84

+ 1 - 1
src/main/frontend/db.cljs

@@ -42,7 +42,7 @@
   get-block-page-end-pos get-block-parent get-block-parents get-block-referenced-blocks get-block-refs-count
   get-blocks-by-priority get-blocks-contents get-collapsed-blocks get-custom-css
   get-date-scheduled-or-deadlines get-db-type get-empty-pages get-file
-  get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id
+  get-file-blocks get-file-contents get-file-last-modified-at get-file-no-sub get-file-page get-file-page-id file-exists?
   get-file-pages get-files get-files-blocks get-files-full get-files-that-referenced-page get-journals-length
   get-latest-journals get-marker-blocks get-matched-blocks get-page get-page-alias get-page-alias-names get-page-blocks get-page-linked-refs-refed-pages
   get-page-blocks-count get-page-blocks-no-cache get-page-file get-page-format get-page-name get-page-properties

+ 6 - 0
src/main/frontend/db/model.cljs

@@ -211,6 +211,12 @@
       (-> (d/entity (d/db conn) [:file/path path])
           :file/last-modified-at))))
 
+(defn file-exists?
+  [repo path]
+  (when (and repo path)
+    (when-let [conn (conn/get-conn repo false)]
+      (d/entity (d/db conn) [:file/path path]))))
+
 (defn get-file
   ([path]
    (get-file (state/get-current-repo) path))

+ 12 - 18
src/main/frontend/fs/nfs.cljs

@@ -137,29 +137,23 @@
             (p/let [_ (verify-permission repo file-handle true)
                     _ (utils/writeFile file-handle content)
                     file (.getFile file-handle)]
-              (do
+              (if (and local-content new?
+                       (or
+                        draw?
+                        ;; Writing not finished
+                        (> pending-writes 0)
+                        ;; not changed by other editors
+                        not-changed?
+                        new-created?))
+                (do
                   (p/let [_ (verify-permission repo file-handle true)
                           _ (utils/writeFile file-handle content)
                           file (.getFile file-handle)]
                     (when file
                       (nfs-saved-handler repo path file))))
-              ;; (if (and local-content new?
-              ;;          (or
-              ;;           draw?
-              ;;           ;; Writing not finished
-              ;;           (> pending-writes 0)
-              ;;           ;; not changed by other editors
-              ;;           not-changed?
-              ;;           new-created?))
-              ;;   (do
-              ;;     (p/let [_ (verify-permission repo file-handle true)
-              ;;             _ (utils/writeFile file-handle content)
-              ;;             file (.getFile file-handle)]
-              ;;       (when file
-              ;;         (nfs-saved-handler repo path file))))
-              ;;   (do
-              ;;     (js/alert (str "The file has been modified on your local disk! File path: " path
-              ;;                    ", please save your changes and click the refresh button to reload it."))))
+                (do
+                  (js/alert (str "The file has been modified on your local disk! File path: " path
+                                 ", please save your changes and click the refresh button to reload it."))))
               ))
            ;; create file handle
           (->

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

@@ -20,18 +20,10 @@
       (when (and content (not (encrypt/content-encrypted? content)))
         (cond
           (= "add" type)
-          (let [db-content (db/get-file path)]
-            (when (and (not= content db-content)
-                       ;; Avoid file overwrites
-                       ;; 1. create a new page which writes a new file
-                       ;; 2. add some new content
-                       ;; 3. file watcher notified it with the old content
-                       ;; 4. old content will overwrites the new content in step 2
-                       (not (and db-content
-                                 (string/starts-with? db-content content))))
+          (when-not (db/file-exists? repo path)
               (let [_ (file-handler/alter-file repo path content {:re-render-root? true
-                                                                  :from-disk? true})]
-                (db/set-file-last-modified-at! repo path mtime))))
+                                                               :from-disk? true})]
+             (db/set-file-last-modified-at! repo path mtime)))
 
           (and (= "change" type)
                (nil? (db/get-file path)))

+ 4 - 3
src/main/frontend/modules/datascript_report/core.cljs

@@ -10,9 +10,10 @@
   (let [r (d/pull db-after '[*] db-id)]
     (if (= keys-of-deleted-entity (count r))
       (let [r (d/pull db-before '[*] db-id)]
-        (if (= keys-of-deleted-entity (count r))
-          (log/error :outliner-pipeline/cannot-find-entity {:entity r})
-          r))
+        (when (= keys-of-deleted-entity (count r))
+          ;; TODO: What can cause this happen?
+          (log/error :outliner-pipeline/cannot-find-entity {:entity r}))
+        r)
       r)))
 
 (defn get-blocks-and-pages