refactor: alert when file in the db is not equal to the file on the disk

pull/1686/head
Tienson Qin 2021-04-19 11:53:00 +08:00
parent d3f88d8b66
commit f696b5ca73
2 changed files with 22 additions and 30 deletions

View File

@ -105,8 +105,7 @@
(and local-file (.text local-file))))) (and local-file (.text local-file)))))
(write-file! [this repo dir path content opts] (write-file! [this repo dir path content opts]
(let [{:keys [old-content]} opts (let [last-modified-at (db/get-file-last-modified-at repo path)
last-modified-at (db/get-file-last-modified-at repo path)
parts (string/split path "/") parts (string/split path "/")
basename (last parts) basename (last parts)
sub-dir (->> (butlast parts) sub-dir (->> (butlast parts)
@ -135,32 +134,26 @@
(config/get-file-format)) (config/get-file-format))
pending-writes (state/get-write-chan-length) pending-writes (state/get-write-chan-length)
draw? (and path (string/ends-with? path ".excalidraw"))] draw? (and path (string/ends-with? path ".excalidraw"))]
(do (p/let [_ (verify-permission repo file-handle true)
(p/let [_ (verify-permission repo file-handle true) _ (utils/writeFile file-handle content)
_ (utils/writeFile file-handle content) file (.getFile file-handle)]
file (.getFile file-handle)] (if (and local-content new?
(when file (or
(nfs-saved-handler repo path file)))) draw?
;; (if (and local-content (or old-content ;; Writing not finished
;; ;; temporally fix (> pending-writes 0)
;; draw?) new? ;; not changed by other editors
;; (or not-changed?
;; draw? new-created?))
;; ;; Writing not finished (do
;; (> pending-writes 0) (p/let [_ (verify-permission repo file-handle true)
;; ;; not changed by other editors _ (utils/writeFile file-handle content)
;; not-changed? file (.getFile file-handle)]
;; new-created?)) (when file
;; (do (nfs-saved-handler repo path file))))
;; (p/let [_ (verify-permission repo file-handle true) (do
;; _ (utils/writeFile file-handle content) (js/alert (str "The file has been modified on your local disk! File path: " path
;; file (.getFile file-handle)] ", please save your changes and click the refresh button to reload it."))))))
;; (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."))))
)
;; create file handle ;; create file handle
(-> (->
(p/let [handle (idb/get-item handle-path)] (p/let [handle (idb/get-item handle-path)]

View File

@ -27,8 +27,7 @@
[repo dir path content {:keys [ok-handler error-handler] :as opts} stat] [repo dir path content {:keys [ok-handler error-handler] :as opts} stat]
(p/let [disk-mtime (when stat (gobj/get stat "mtime")) (p/let [disk-mtime (when stat (gobj/get stat "mtime"))
db-mtime (db/get-file-last-modified-at repo path)] db-mtime (db/get-file-last-modified-at repo path)]
(if false (if (not= disk-mtime db-mtime)
;; (not= disk-mtime db-mtime)
(js/alert (str "The file has been modified on your local disk! File path: " path (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.")) ", please save your changes and click the refresh button to reload it."))
(-> (->