Preserve F1 settings when a save fails #4943

Closed
github-bot wants to merge 1 commit from github-bot/gh-4942 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 14:56 UTC · original
andrewpozdnakov7-jpg:codex2/fix/f1-atomic-settings-save → main · +34 −11 · 1 files · 1 commits · closed without merging

Refs #4940, point 3.

What it changes

The F1 rewrite on main opened the settings file for overwrite even after a read failure. Saving one changed setting could then replace the other saved values. This restores the F1 persistence safeguards from #2256. Read errors reach the menu, and a successful save writes and syncs a temporary file beside the target before replacing it. An existing settings symlink is resolved before the write.

How it was tested

  • A focused Windows Rust fixture called the exact menu save methods from 5fabb46e and 294f3b3f017182e7beda54c8e929444ad83441d0 on synthetic files.
  • Main overwrote an invalid UTF-8 file and reported success. The patch reported the save error and preserved every byte. With a handle denying replacement, the patch also preserved the file, and a retry after the handle closed kept an unrelated setting while applying the change.
  • Normal and first-time saves succeeded. cargo xtask policy --staged accepted the changed file.
  • Main's CI check has five existing Clippy errors tracked in #4708.

Checked for overlap

  • Searched open and closed issues and PRs for F1 settings reads and atomic saves, and open PRs touching menu.rs. #2868 deals with launch-time settings precedence and reset. #4935 saves the game's separate settings XML.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 14:56 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942) `andrewpozdnakov7-jpg:codex2/fix/f1-atomic-settings-save` → `main` · +34 −11 · 1 files · 1 commits · closed without merging Refs #4940, point 3. ## What it changes The F1 rewrite on `main` opened the settings file for overwrite even after a read failure. Saving one changed setting could then replace the other saved values. This restores the F1 persistence safeguards from #2256. Read errors reach the menu, and a successful save writes and syncs a temporary file beside the target before replacing it. An existing settings symlink is resolved before the write. ## How it was tested - A focused Windows Rust fixture called the exact menu save methods from `5fabb46e` and `294f3b3f017182e7beda54c8e929444ad83441d0` on synthetic files. - Main overwrote an invalid UTF-8 file and reported success. The patch reported the save error and preserved every byte. With a handle denying replacement, the patch also preserved the file, and a retry after the handle closed kept an unrelated setting while applying the change. - Normal and first-time saves succeeded. `cargo xtask policy --staged` accepted the changed file. - Main's [CI check](https://github.com/trustno1-coder/VIctory-NVIDIA/actions/runs/46563306780/job/142355972539) has five existing Clippy errors tracked in #4708. ## Checked for overlap - [x] Searched open and closed issues and PRs for F1 settings reads and atomic saves, and open PRs touching `menu.rs`. #2868 deals with launch-time settings precedence and reset. #4935 saves the game's separate settings XML. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 14:56:37 +00:00
github-bot changed title from [pr-fix][startup] Preserve F1 settings when a save fails to Preserve F1 settings when a save fails 2026-12-01 15:02:08 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:12 UTC · original · reviewed

AI-assisted review: I inspected the settings save path and the failure handling in this diff. I used AI assistance and verified the test gap against the current source.

**@⁠gut0to** on GitHub · 2026-12-01 15:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#pullrequestreview-6134096818) · **reviewed** AI-assisted review: I inspected the settings save path and the failure handling in this diff. I used AI assistance and verified the test gap against the current source.
@ -1186,0 +1187,4 @@
let previous = match std::fs::read_to_string(path) {
Ok(text) => text,
Err(error) if error.kind() == io::ErrorKind::NotFound => String::new(),
Err(error) => return Err(error),
Author
Owner

@⁠gut0to on GitHub · 2026-12-01 15:12 UTC · original

Could this failure path get an in-tree regression test? This change prevents a read/parse error from replacing the saved settings, but the reported fixture is external to the repository. A temp-file test with invalid UTF-8 (or another read_to_string error) could call write_settings and assert the original bytes remain unchanged; a failed atomic replacement should likewise leave self.started unchanged. That would make the central corruption fix durable.

**@⁠gut0to** on GitHub · 2026-12-01 15:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#discussion_r4756266028) Could this failure path get an in-tree regression test? This change prevents a read/parse error from replacing the saved settings, but the reported fixture is external to the repository. A temp-file test with invalid UTF-8 (or another read_to_string error) could call write_settings and assert the original bytes remain unchanged; a failed atomic replacement should likewise leave self.started unchanged. That would make the central corruption fix durable.
github-bot closed this pull request 2026-12-01 18:30:40 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-12-01 18:29 UTC · original

Current main already resolves a settings symlink, preserves the previous file on a read failure, and syncs a temporary file before replacing it. Closing this proposal as superseded. Source checked at 93aa9a92.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-12-01 18:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#issuecomment-7321033069) Current main already resolves a settings symlink, preserves the previous file on a read failure, and syncs a temporary file before replacing it. Closing this proposal as superseded. Source checked at [93aa9a92](https://github.com/trustno1-coder/VIctory-NVIDIA/commit/93aa9a92ac392784b8ee6114463711d98d94c52b).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!4943
No description provided.