Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make moving files across different partitions possible by adding fallback to copy-and-delete #51

Merged
merged 7 commits into from
Jan 28, 2025

Conversation

babarot
Copy link
Owner

@babarot babarot commented Jan 27, 2025

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 simple os.Rename() or fall back to a copy-and-delete approach. The move 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 systems

fix #38

@github-actions github-actions bot added the no-update-changelog Used in case of no need to update changelog label Jan 27, 2025
@github-actions github-actions bot removed the no-update-changelog Used in case of no need to update changelog label Jan 27, 2025
@babarot babarot changed the title WIP Make moving files across different partitions possible by adding fallback to copy-and-delete Jan 27, 2025
@babarot babarot added the kind/feature A feature request; new or enhanced behavior label Jan 27, 2025
@babarot babarot merged commit b7f0aab into main Jan 28, 2025
5 checks passed
@babarot babarot deleted the babarot/move branch January 28, 2025 10:10
@github-actions github-actions bot mentioned this pull request Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature A feature request; new or enhanced behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rename {source-path} {dest-path}: invalid cross-device link by removing Windows files with WSL2
1 participant