Skip to content

fix: delete existing destination file before rename in DiskObjectStorage#187

Merged
pdeffendol merged 2 commits intomainfrom
fix-builtin-file-replace-method
Dec 22, 2025
Merged

fix: delete existing destination file before rename in DiskObjectStorage#187
pdeffendol merged 2 commits intomainfrom
fix-builtin-file-replace-method

Conversation

@maestro957
Copy link
Copy Markdown
Contributor

Description

Add check to delete destination file if it exists before moving file in RenameAsync method. This prevents IOException when attempting to rename/move a file to a path that already exists.

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Tests
  • 🤖 Build/CI
  • 📦 Chore (Version bump, release, etc.)
  • ⏩ Revert

Related Tickets & Documents

Fixes RRPS-9896

Changes Made

  • Added existence check for destinationfile in RenameAsync(StoragePath, StoragePath, CancellationToken) method before calling File.Move
  • Added File.Delete(newFilePath) to remove existing destination file if present
  • This prevents IOException that occurss when File.Move attempts to move a file to a path that already exists

Quality Checklist

  • I have added or updated automated tests as needed.
  • I have reviewed the code changes myself.
  • I have used commit messages that adequately explain my changes.
  • I have removed any extra logging, debugging code, and commented out code.
  • I have updated any related documentation (if necessary).

Additional Notes

Context

The File.Move method on Windows/.NET throws an IOException when the destination file already exists. This fix ensures that RenameAsync(StoragePath, StoragePath, CancellationToken) behaves consistently by explicitly deleting any existing destination file before performing the move operation.

Testing Considerations

Reviewers should verify:

  • Behavior when renaming to a non-existent destination (should work as before)
  • Behavior when renaming to an existing destination (should now overwrite successfully)
  • Proper handling of edge cases (locked files, permission issues, etc.)

Related

This fix aligns with the expected behavior of a "rename/replace" operation where the destination is overwritten if it exists.

Add check to delete destination file if it exists before moving file in RenameAsync method.
This prevents IOException when attempting to rename/move a file to a path that already exists.
@maestro957 maestro957 self-assigned this Dec 22, 2025
@pdeffendol
Copy link
Copy Markdown
Contributor

Looks good, thanks for finding this and providing a fix!

@pdeffendol pdeffendol merged commit 0262944 into main Dec 22, 2025
1 check passed
@pdeffendol pdeffendol deleted the fix-builtin-file-replace-method branch December 22, 2025 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants