Preserve F1 settings when a save fails #4942

Closed
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/4942 into main
andrewpozdnakov7-jpg commented 2026-12-01 14:56:24 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T14:56:24Z.


Refs #4939, 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 #4707.

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. #4934 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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5588258806 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-12-01T14:56:24Z. --- Refs #4939, 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 #4707. ## 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. #4934 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.
gut0to commented 2026-12-01 15:12:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gut0to on 2026-12-01T15:12:17Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review:6134096818 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#pullrequestreview-6134096818). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T15:12:17Z. **Review:** COMMENTED --- 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 commented 2026-12-01 15:12:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by gut0to on 2026-12-01T15:12:17Z.

Code review location: crates/victory-gpu/src/host/menu.rs; line 1190

@@ -1173,16 +1175,21 @@ impl Menu {
         }
     }
 
-    fn save(&mut self) -> bool {
-        let Some(path) = settings_file() else {
-            self.note = "NO FOLDER FOR THE SETTINGS FILE".to_owned();
-            return false;
+    fn write_settings(&self, path: &Path) -> io::Result<()> {
+        // Keep a settings symlink and replace its target.
+        let target;
+        let path = if std::fs::symlink_metadata(path).is_ok_and(|entry| entry.is_symlink()) {
+            target = std::fs::canonicalize(path)?;
+            target.as_path()
+        } else {
+            path
         };
-        if let Some(dir) = path.parent() {
-            let _ = std::fs::create_dir_all(dir);
-        }
-        let mut kept: Vec<(String, String)> = std::fs::read_to_string(&path)
-            .unwrap_or_default()
+        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),

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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:review-comment:4756266028 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#discussion_r4756266028). Originally posted by [gut0to](https://github.com/gut0to) on 2026-12-01T15:12:17Z. **Code review location:** `crates/victory-gpu/src/host/menu.rs`; line 1190 ~~~~diff @@ -1173,16 +1175,21 @@ impl Menu { } } - fn save(&mut self) -> bool { - let Some(path) = settings_file() else { - self.note = "NO FOLDER FOR THE SETTINGS FILE".to_owned(); - return false; + fn write_settings(&self, path: &Path) -> io::Result<()> { + // Keep a settings symlink and replace its target. + let target; + let path = if std::fs::symlink_metadata(path).is_ok_and(|entry| entry.is_symlink()) { + target = std::fs::canonicalize(path)?; + target.as_path() + } else { + path }; - if let Some(dir) = path.parent() { - let _ = std::fs::create_dir_all(dir); - } - let mut kept: Vec<(String, String)> = std::fs::read_to_string(&path) - .unwrap_or_default() + 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), ~~~~ --- 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.
andrewpozdnakov7-jpg commented 2026-12-01 18:29:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by andrewpozdnakov7-jpg on 2026-12-01T18:29:38Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321033069 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4942#issuecomment-7321033069). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-12-01T18:29:38Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

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