Here File::create truncates the file before serde_json writes the pastas into it. If power fails or microbin crashes in between those calls all pasta's are lost.
Solution: open a new file for writing next to the current. Write the pasta's to it then rename the new file to become the old. The rename is atomic.
Given the
save_to_file
method: https://github.com/szabodanika/microbin/blob/b8a0c5490d681550d982ad02d67a1aaa0897f503/src/util/db_json.rs#L17Here
File::create
truncates the file before serde_json writes the pastas into it. If power fails or microbin crashes in between those calls all pasta's are lost.Solution: open a new file for writing next to the current. Write the pasta's to it then rename the new file to become the old. The rename is atomic.