enhance: backup files when there're differences between db and disk

Previously, files are backuped to logseq/bak when logseq detects
there're differences between the db and disk. But it has two problems:

1. Only a few of users know `logseq/bak`, other users think that their
data has been lost.
2. Files in the logseq/bak folder are never truncated.

This PR backups old file in DB with timestamp suffixes instead of
logesq/bak, and only keep the latest 10 versions of any changed file.
This commit is contained in:
Tienson Qin
2022-03-02 11:58:20 +08:00
parent 2e46a6bcb7
commit 8e6fb5613d
4 changed files with 38 additions and 15 deletions

View File

@@ -33,8 +33,8 @@
(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))
;; save the previous content in a versioned bak file to avoid data overwritten.
_ (when backup? (ipc/ipc "backupDbFile" (config/get-local-dir repo) path db-content content))
_ (file-handler/alter-file repo path content {:re-render-root? true
:from-disk? true})]
(set-missing-block-ids! content)