Make moving files across different partitions possible by adding fallback to copy-and-delete #51
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
This PR refactors the file moving logic to use the
move
function, which checks if the source and destination reside on the same partition before deciding whether to perform a simpleos.Rename()
or fall back to acopy-and-delete
approach. Themove
function handles the logic of ensuring the destination directory exists and correctly handles partition checks, providing a more robust and flexible solution for moving files across different filesystems.Why
The
os.Rename
function is designed for file moves within the same file system. When attempting to move files across different partitions or mount points, it results in an "invalid cross-device link" error. To address this, I’ve added a fallback mechanism that uses a copy-and-delete approach when the source and destination are on different partitions. This ensures that files can still be "moved" by copying them to the new location and deleting the original, effectively simulating a move even across different file systemsfix #38