|
|
@@ -25,6 +25,16 @@
|
|
|
(when-not (= (str id-property) (str block-id))
|
|
|
(editor/set-block-property! block-id "id" block-id)))))))
|
|
|
|
|
|
+(defn- handle-add-and-change!
|
|
|
+ [repo path content db-content mtime backup?]
|
|
|
+ (p/let [
|
|
|
+ ;; save the previous content in a bak file to avoid data overwritten.
|
|
|
+ _ (when backup? (ipc/ipc "backupDbFile" (config/get-local-dir repo) path db-content))
|
|
|
+ _ (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)))
|
|
|
+
|
|
|
(defn handle-changed!
|
|
|
[type {:keys [dir path content stat] :as payload}]
|
|
|
(when dir
|
|
|
@@ -38,10 +48,8 @@
|
|
|
(and (= "add" type)
|
|
|
(not= (string/trim content) (string/trim db-content))
|
|
|
(not (string/includes? path "logseq/pages-metadata.edn")))
|
|
|
- (p/let [_ (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))
|
|
|
+ (let [backup? (not (string/blank? db-content))]
|
|
|
+ (handle-add-or-changed! repo path content db-content mtime backup?))
|
|
|
|
|
|
(and (= "change" type)
|
|
|
(not (db/file-exists? repo path)))
|
|
|
@@ -57,13 +65,7 @@
|
|
|
(string/trim (or (state/get-default-journal-template) "")))
|
|
|
(= (string/trim content) "-")
|
|
|
(= (string/trim content) "*")))
|
|
|
- (p/let [
|
|
|
- ;; save the previous content in a bak file to avoid data overwritten.
|
|
|
- _ (ipc/ipc "backupDbFile" (config/get-local-dir repo) path db-content)
|
|
|
- _ (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)))
|
|
|
+ (handle-add-or-changed! repo path content db-content mtime true))
|
|
|
|
|
|
(and (= "unlink" type)
|
|
|
(db/file-exists? repo path))
|