Skip to content

Settings survive a crash while they are being saved - #95

Merged
seaweeduk merged 2 commits into
masterfrom
fix/safe-config-writes
Nov 22, 2026
Merged

seaweeduk merged 2 commits into
masterfrom
fix/safe-config-writes

Conversation

@seaweeduk

@seaweeduk seaweeduk commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Settings and other config files were saved by truncating the file and writing it again in place. If the app crashed or was killed during that write, the file could be left empty or cut short, and the next start lost those settings.

Now every config file is saved to a temporary file beside it, synced to disk, and renamed over the old one. A crash leaves either the old file or the new one, never part of one.

Files saved this way:

  • settings.conf
  • saved SMB and SFTP logins, SFTP known hosts and key
  • pinned places (pinned_folders.conf) and per-folder memory (folders.conf)
  • pinned Stash and XBVR lists
  • presets and their order
  • the first-run marker (setup.conf)
  • the offline downloads list (offline.json, which already renamed but did not sync)
flowchart LR
  A["contents"] --> B["file.new.&lt;pid&gt;.&lt;n&gt;<br/>(O_EXCL, 0600 or umask)"]
  B --> C["write, fsync, close"]
  C -- ok --> D["rename over file<br/>fsync the folder"]
  C -- error --> E["remove the temporary file<br/>keep the old one"]
Loading
  • One helper, replaceFile(), replaces the copy that only the SFTP code had.
  • A config file that is a symlink stays one: the app replaces its target, and saves nothing while the target can't be found (a drive not mounted).
  • Pinned places were saved by a new thread per save; they now go through the same config queue as the other settings.
  • Renaming a preset, or saving one under a name that differs only in case, no longer deletes the original if writing the new one failed.
  • File formats don't change.

Known and left as is

  • Atomic replacement doesn't preserve manual file modes, and can replace a read-only file if its directory is writable. Credential files use 0600; other config files follow the process umask.
  • A process killed mid-save may leave an unused temporary file next to the config. Later saves don't reuse it.

Important

AI disclosure

Model Variant Role
anthropic/claude-opus-5-5 high Implementation
openai/gpt-6.2-astra high Independent review

Agent harness OpenCode 2.3.2

@seaweeduk seaweeduk added the fix Bug fix (release notes: Fixes) label Nov 22, 2026
@opencode-agent

Copy link
Copy Markdown
  1. Low — A save can permanently replace a temporarily unresolved config symlink. In src/file_util.cpp:275–279, if settings.conf points to a file on an unmounted drive, canonical() fails and leaves target set to the symlink’s own path. The rename at line 297 then replaces the link with a regular file. Even after the drive is remounted, the app no longer reads the original settings. The previous in-place write left the link intact on failure. Once is_symlink() succeeds, return false if canonical() fails rather than renaming over the link.

github run

@seaweeduk
seaweeduk force-pushed the fix/safe-config-writes branch from a3d771d to fc2ea37 Compare November 22, 2026 20:14
@seaweeduk

Copy link
Copy Markdown
Owner Author

/oc Please re-review the change since the first review.

  1. A symlink whose target can't be found was replaced: fixed in fc2ea37. replaceFile() returns false when fs::is_symlink() succeeds but fs::canonical() fails, so the link is kept and nothing is written. The description now says a config symlink stays one and that nothing is saved while its target can't be found.

@opencode-agent

Copy link
Copy Markdown

The symlink finding is resolved in fc2ea371. At src/file_util.cpp:276–280, replaceFile() returns false if the symlink target can’t be resolved, before creating a temporary file or writing anything. If resolution succeeds, the rename uses the target path, leaving the symlink intact.

The updated PR description matches the code. No new findings in this follow-up.

github run

@seaweeduk
seaweeduk force-pushed the fix/free-decoder-from-steam branch from 22680ca to 0c86ba5 Compare November 22, 2026 20:58
@seaweeduk
seaweeduk force-pushed the fix/safe-config-writes branch from fc2ea37 to b71d3b6 Compare November 22, 2026 20:58
@seaweeduk
seaweeduk changed the base branch from fix/free-decoder-from-steam to master November 22, 2026 20:58
@seaweeduk
seaweeduk merged commit 1c99d30 into master Nov 22, 2026
@seaweeduk
seaweeduk deleted the fix/safe-config-writes branch November 22, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix (release notes: Fixes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant