Repository navigation
fix: atomic writes, volatile journal, ASCII console banners - #56
Merged
Merged
Conversation
Power-loss safety improvements for the Raspberry Pi deployment: 1. Atomic file writes (new zeclock/atomic_write.py): - All config/state writes now use temp file + fsync + rename - Guarantees files are either old or new, never truncated - Applied to: zeclock.ini, plugins.yaml, update version/history 2. Journald switched to volatile (RAM-only): - Continuous journal writes were the #1 source of f2fs corruption - Logs no longer survive reboots but /data stays healthy - RuntimeMaxUse=10M caps RAM usage Files using atomic writes: - clock.py (_persist_wifi_addr) - rest_remote.py (save config, save plugins, persist brightness, import) - updater.py (version file, history.json) - plugin_config.py (create default config)
Terminal on RPi does not support emoji (width=2) or Unicode box-drawing characters, causing misaligned banner borders. Use plain ASCII characters (+, |, =) instead.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Repeated f2fs corruption on the Raspberry Pi after power loss. Root cause: direct file writes (
open(path, 'w')) and continuous journald writes to/data.Additionally, console banners displayed on the RPi terminal (tty1) were misaligned because emoji and Unicode box-drawing characters have inconsistent widths on the Linux framebuffer console.
Changes
1. Atomic file writes (
zeclock/atomic_write.py)New utility module implementing the crash-safe write pattern:
fsync()the file descriptoros.replace()(atomic POSIX rename)fsync()the directoryApplied to all config/state writes:
zeclock.ini(brightness, wifi_addr, full config save, import)plugins.yaml(plugin config save, default creation)current-version(OTA updater)history.json(OTA update history)2. Journald switched to volatile (RAM)
Storage=volatilereplacesStorage=persistent/data3. ASCII-only console banners
_show_console_bannerand_show_connected_bannerwith plain ASCII (+,|,=)main()print statementsResult
/dataare guaranteed to be either the previous valid version or the new complete version at any point during a power cut.