mirror of
https://github.com/logseq/logseq.git
synced 2026-05-05 19:36:35 +00:00
fix: detect "file modified" with file contents instead mtime
This commit is contained in:
@@ -37,16 +37,14 @@
|
||||
(error-handler error)
|
||||
(log/error :write-file-failed error))))
|
||||
|
||||
(p/let [disk-mtime (when stat (gobj/get stat "mtime"))
|
||||
db-mtime (db/get-file-last-modified-at repo path)
|
||||
file-exists? (-> (protocol/stat this dir path)
|
||||
(p/catch (fn [_error] false)))
|
||||
(p/let [db-mtime (db/get-file-last-modified-at repo path)
|
||||
disk-content (-> (protocol/read-file this dir path nil)
|
||||
(p/catch (fn [error] nil)))
|
||||
disk-content (or disk-content "")
|
||||
ext (string/lower-case (util/get-file-ext path))
|
||||
file-page (db/get-file-page-id path)
|
||||
page-empty? (and file-page (db/page-empty? repo file-page))]
|
||||
page-empty? (and file-page (db/page-empty? repo file-page))
|
||||
db-content (or (db/get-file repo path) "")]
|
||||
(cond
|
||||
;; (and (not page-empty?) (nil? disk-content) )
|
||||
;; (notification/show!
|
||||
@@ -56,9 +54,8 @@
|
||||
;; false)
|
||||
|
||||
(and
|
||||
file-exists?
|
||||
(not= disk-mtime db-mtime)
|
||||
(not= (string/trim disk-content) (string/trim content))
|
||||
(not= (string/trim disk-content)
|
||||
(string/trim db-content))
|
||||
;; FIXME:
|
||||
(not (contains? #{"excalidraw" "edn"} ext)))
|
||||
(notification/show!
|
||||
@@ -72,6 +69,7 @@
|
||||
(p/let [result (ipc/ipc "writeFile" path content)
|
||||
mtime (gobj/get result "mtime")]
|
||||
(db/set-file-last-modified-at! repo path mtime)
|
||||
(db/set-file-content! repo path content)
|
||||
(when ok-handler
|
||||
(ok-handler repo path result))
|
||||
result)
|
||||
|
||||
@@ -50,15 +50,16 @@
|
||||
(js/console.warn "Can't get file in the db: " path)
|
||||
|
||||
(and (= "change" type)
|
||||
(when-let [last-modified-at (db/get-file-last-modified-at repo path)]
|
||||
(> mtime last-modified-at)))
|
||||
(when-not (string/blank? content)
|
||||
(p/let [result (ipc/ipc "gitCommitAll")
|
||||
_ (file-handler/alter-file repo path content {:re-render-root? true
|
||||
:from-disk? true})]
|
||||
(set-missing-block-ids! content)
|
||||
(db/set-file-last-modified-at! repo path mtime)
|
||||
nil))
|
||||
;; ignore truncate
|
||||
(not (string/blank? content))
|
||||
(not= (string/trim content)
|
||||
(string/trim (or (db/get-file repo path) ""))))
|
||||
(p/let [result (ipc/ipc "gitCommitAll")
|
||||
_ (file-handler/alter-file repo path content {:re-render-root? true
|
||||
:from-disk? true})]
|
||||
(set-missing-block-ids! content)
|
||||
(db/set-file-last-modified-at! repo path mtime)
|
||||
nil)
|
||||
|
||||
(contains? #{"add" "change" "unlink"} type)
|
||||
nil
|
||||
|
||||
Reference in New Issue
Block a user