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)))))
(write-file! [this repo dir path content opts]
(let [{:keys [old-content]} opts
last-modified-at (db/get-file-last-modified-at repo path)
(let [last-modified-at (db/get-file-last-modified-at repo path)
parts (string/split path "/")
basename (last parts)
sub-dir (->> (butlast parts)
@ -135,32 +134,26 @@
(config/get-file-format))
pending-writes (state/get-write-chan-length)
draw? (and path (string/ends-with? path ".excalidraw"))]
(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 (or old-content
;; ;; temporally fix
;; draw?) 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."))))
)
(p/let [_ (verify-permission repo file-handle true)
_ (utils/writeFile file-handle content)
file (.getFile file-handle)]
(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."))))))
;; create file handle
(->
(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]
(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)
(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."))
(->