✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)
Bug fix.
⤵️ What is the current behavior?
On Windows, JsonCacheInfoRepository's atomic write (temp file + rename, since 3.4.3) fails with PathAccessException: Cannot rename file ... (OS Error: The process cannot access the file because it is being used by another process, errno = 32) whenever another process has the cache info file or the fresh temp file open without delete sharing. Antivirus and the search indexer routinely do that just after a file is written. The write is reported through FlutterError and stays pending until the next change, so it's lost if the app exits first. We see this in production at app startup.
🆕 What is the new behavior (if this is a feature change)?
When the rename fails with ERROR_SHARING_VIOLATION (32) or ERROR_ACCESS_DENIED (5), it's retried four times, with pauses of 50, 100, 200 and 400 ms (about 750 ms in all), before the failure is reported as before. Other errors are not retried.
💥 Does this PR introduce a breaking change?
No
🐛 Recommendations for testing
New tests use a forwarding file system whose rename fails a set number of times: a refusal that clears is retried and persisted with no error reported, persistent refusals are reported after five attempts, and other error codes are not retried. The first two fail without the change. flutter test, flutter analyze and dart format --set-exit-if-changed . pass locally. Not run on a Windows machine with a real file lock.
📝 Links to relevant issues/docs
MoveFileEx (used by File.rename on Windows), system error codes.
🤔 Checklist before submitting
- All projects build
- Follows style guide lines (code style guide)
- Relevant documentation was updated
- Rebased onto current main
- Version bumped and dated CHANGELOG entry added