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

Fix Json db losing already saved pasta's on crash/power failure #281

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

dvdsk
Copy link
Contributor

@dvdsk dvdsk commented Oct 22, 2024

The database file was truncated before writes the complete list of pastas from memory back into it. If power failed in between or microbin crashed all pasta's would be lost.

This creates a new file then replaces the old with it once the writing is done. Note the replace (rename) is usually (definitly on linux) atomic. Therefore it either succeeds or fails and only the new changes are lost.

The database file was truncated before writes the complete list of
pastas from memory back into it. If power failed in between or microbin
crashed all pasta's would be lost.

This creates a new file then replaces the old with it once the writing
is done. Note the replace (rename) is usually (definitly on linux)
atomic. Therefore it either succeeds or fails and only the new changes
are lost.
Comment on lines +23 to +25
let tmp_file = File::create(&tmp_file_path).expect(&format!(
"failed to create temporary database file for writing. path: {tmp_file_path}"
));

Check warning

Code scanning / clippy

use of expect followed by a function call Warning

use of expect followed by a function call
@szabodanika szabodanika merged commit 6e08eed into szabodanika:master Oct 24, 2024
3 checks passed
@szabodanika
Copy link
Owner

This fixes #278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants