Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Mar 8, 2022

Conversation

tiensonqin
Copy link
Contributor

@tiensonqin tiensonqin commented Mar 2, 2022

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

  1. Only a few 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 files in DB with timestamp suffixes instead of
logesq/bak, and only keep the latest 10 versions of any changed file.

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.
@github-actions github-actions bot added the :type/enhancement Enhancement to product. Does not affect the overall basic use. label Mar 2, 2022
(let [dir (path/dirname file-path)
files (fs/readdirSync dir (clj->js {:withFileTypes true}))
files (map #(.-name %) files)
prefix (str (path/basename file-path) ".")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A special case for this prefix check:

what if a user creates a page "A" and then "A/md".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

basename will return the file name with the suffix, e.g. a.md, prefix here has an ending . so that a.md will not be deleted if we want to truncate the history files for the page A.

@tiensonqin tiensonqin merged commit 06fc422 into master Mar 8, 2022
@tiensonqin tiensonqin deleted the enhance/versioned-files branch March 8, 2022 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:type/enhancement Enhancement to product. Does not affect the overall basic use.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants