fix: write Config.ini atomically via tmp + File.Replace#22
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughIniFile.WriteValues now writes output to ChangesAtomic file write in IniFile.WriteValues
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested Labels
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/Utilities/IniFile.cs
Summary by CodeRabbit