Skip to content
This repository was archived by the owner on Jul 12, 2026. It is now read-only.

fix: write Config.ini atomically via tmp + File.Replace#22

Merged
dary1337 merged 2 commits into
masterfrom
release/1.1.0.0
May 30, 2026
Merged

fix: write Config.ini atomically via tmp + File.Replace#22
dary1337 merged 2 commits into
masterfrom
release/1.1.0.0

Conversation

@dary1337

@dary1337 dary1337 commented May 30, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • Bug Fixes
    • Improved INI file write reliability by performing atomic writes via a temporary file and safe replacement of the target file. Ensures cleanup of temporary files on failure, logs cleanup errors, and preserves original exceptions to surface write failures.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 30, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d7c89ec6-fea1-465b-bf06-0877e0625717

📥 Commits

Reviewing files that changed from the base of the PR and between 3d0184f and 4e5e476.

📒 Files selected for processing (1)
  • src/Utilities/IniFile.cs

Walkthrough

IniFile.WriteValues now writes output to path + ".tmp" and then installs it over path with File.Replace (if destination exists) or File.Move (otherwise); on error it best-effort deletes the temp file, logs deletion failures via AppLogger.Error, and rethrows.

Changes

Atomic file write in IniFile.WriteValues

Layer / File(s) Summary
Atomic write with tmp-file swap and cleanup
src/Utilities/IniFile.cs
WriteValues writes to path + ".tmp" first, then atomically swaps via File.Replace or File.Move, with try/finally cleanup of the temp file on exception and rethrow (src/Utilities/IniFile.cs:81–109).

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes


Suggested Labels

security, needs-tests

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title directly and accurately summarizes the main change: atomic write to Config.ini using temporary file + File.Replace pattern.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch release/1.1.0.0

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Utilities/IniFile.cs`:
- Around line 96-105: The inner empty catch after attempting
File.Delete(tempPath) silently swallows exceptions; change it to catch Exception
(e.g., cleanupEx) and call AppLogger.Error(...) with the tempPath and cleanupEx
so filesystem failures are logged, while leaving the outer catch's original
exception behavior intact (do not replace or suppress the original exception
thrown in the outer catch — rethrow or allow it to propagate as before). Ensure
you reference tempPath and File.Delete in the modified catch and use
AppLogger.Error to record the cleanup exception.
- Around line 86-94: The code currently builds a deterministic tempPath
(tempPath = path + ".tmp") which is race-prone; change the logic that writes and
swaps the file (the block using tempPath, File.WriteAllLines, File.Replace and
File.Move) to create a unique temp file name in the same directory (e.g., use
Path.GetRandomFileName() or a GUID combined with Path.GetDirectoryName(path)),
write to that unique temp file, then atomically replace or move it into place
using File.Replace when the original exists or File.Move otherwise, and ensure
any created temp file is cleaned up on exceptions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 98b8d323-9e8a-4918-867d-be03da19fc02

📥 Commits

Reviewing files that changed from the base of the PR and between b977b80 and 3d0184f.

📒 Files selected for processing (1)
  • src/Utilities/IniFile.cs

Comment thread src/Utilities/IniFile.cs
Comment thread src/Utilities/IniFile.cs
@dary1337
dary1337 merged commit c70b4c7 into master May 30, 2026
3 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant