fix: the file has been modified...

This commit is contained in:
Tienson Qin
2021-04-28 23:48:09 +08:00
parent e7318336e3
commit 5097f23f84
5 changed files with 26 additions and 33 deletions

View File

@@ -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)))