Răsfoiți Sursa

fix: [wip] wrong warning on changed files

Tienson Qin 4 ani în urmă
părinte
comite
24e4350ae5

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

@@ -282,7 +282,8 @@
            (let [v (some->> (name (nth e 2))
                             (text/page-ref-un-brackets!))
                  sym '?v]
-             [['?p :block/properties '?prop]
+             [['?p :block/name]
+              ['?p :block/properties '?prop]
               [(list 'get '?prop (keyword (nth e 1))) sym]
               (list
                'or

+ 15 - 21
src/main/frontend/fs/nfs.cljs

@@ -137,27 +137,21 @@
             (p/let [_ (verify-permission repo file-handle true)
                     _ (utils/writeFile file-handle content)
                     file (.getFile file-handle)]
-              (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?))
-              ;;   (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)))
-              ;;   (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.")))
-              ))
+              (if (and local-content new?
+                       (or
+                        draw?
+                        ;; Writing not finished
+                        (> pending-writes 0)
+                        ;; not changed by other editors
+                        not-changed?
+                        new-created?))
+                (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)))
+                (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
           (->
            (p/let [handle (idb/get-item handle-path)]

+ 11 - 7
src/main/frontend/fs/node.cljs

@@ -24,12 +24,16 @@
            (str "/" (string/replace path #"^/" ""))))))
 
 (defn- write-file-impl!
-  [repo dir path content {:keys [ok-handler error-handler] :as opts} stat]
+  [this repo dir path content {:keys [ok-handler error-handler] :as opts} stat]
   (p/let [disk-mtime (when stat (gobj/get stat "mtime"))
-          db-mtime (db/get-file-last-modified-at repo path)]
-    (if
-        false
-        ;; (not= disk-mtime db-mtime)
+          db-mtime (db/get-file-last-modified-at repo path)
+          old-content (protocol/read-file this dir path nil)]
+    ;; (prn {:equal (= (string/trim old-content) (string/trim content))
+    ;;       :disk-mtime disk-mtime
+    ;;       :db-mtime db-mtime
+    ;;       :old-content old-content
+    ;;       :new-content content})
+    (if (not= disk-mtime db-mtime)
       (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."))
       (->
@@ -62,11 +66,11 @@
       (->
        (p/let [stat (protocol/stat this dir path)]
          ;; update
-         (write-file-impl! repo dir path content opts stat))
+         (write-file-impl! this repo dir path content opts stat))
        (p/catch
         (fn [_error]
              ;; create
-          (write-file-impl! repo dir path content opts nil))))))
+          (write-file-impl! this repo dir path content opts nil))))))
   (rename! [this repo old-path new-path]
     (ipc/ipc "rename" old-path new-path))
   (stat [this dir path]