enhance: don't overwrite logseq's file if changes from journal file

is empty or the default template content.

To prevent overwritten when using iCloud/OneDrive/GDrive.
This commit is contained in:
Tienson Qin
2021-09-15 21:47:05 +08:00
parent f5cdfaa2f1
commit f59f59b9ae
3 changed files with 21 additions and 18 deletions

View File

@@ -9,7 +9,8 @@
[frontend.handler.file :as file-handler]
[lambdaisland.glogi :as log]
[electron.ipc :as ipc]
[promesa.core :as p]))
[promesa.core :as p]
[frontend.state :as state]))
(defn- set-missing-block-ids!
[content]
@@ -46,17 +47,24 @@
(and (= "change" type)
(not= (string/trim content) (string/trim db-content))
(not (string/includes? path "logseq/pages-metadata.edn")))
(p/let [
;; save the previous content in Logseq first and commit it to avoid
;; any data-loss.
_ (file-handler/alter-file repo path db-content {:re-render-root? false
:reset? false
:skip-compare? true})
_ (ipc/ipc "gitCommitAll" "Save the file from Logseq's database")
_ (file-handler/alter-file repo path content {:re-render-root? true
:skip-compare? true})]
(set-missing-block-ids! content)
(db/set-file-last-modified-at! repo path mtime))
(when-not (and
(string/includes? path (str "/" (config/get-journals-directory) "/"))
(or
(= (string/trim content)
(string/trim (or (state/get-default-journal-template) "")))
(= (string/trim content) "-")
(= (string/trim content) "*")))
(p/let [
;; save the previous content in Logseq first and commit it to avoid
;; any data-loss.
_ (file-handler/alter-file repo path db-content {:re-render-root? false
:reset? false
:skip-compare? true})
_ (ipc/ipc "gitCommitAll" "Save the file from Logseq's database")
_ (file-handler/alter-file repo path content {:re-render-root? true
:skip-compare? true})]
(set-missing-block-ids! content)
(db/set-file-last-modified-at! repo path mtime)))
(contains? #{"add" "change" "unlink"} type)
nil