Fix --force and --adopt creating empty directories instead of symlinks #128
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.
Summary
Fixes #127 -
--forceand--adoptoptions exhibit destructive behavior that creates empty directories instead of symlinks.Changes
1. Fix symlink/file removal in
remove_files_and_decide_if_adopt()Before: The removal logic only handled
is_dir()andis_file(), missing symlinks that don't resolve:After: Uses
exists() || is_symlink()to properly handle all file types including broken symlinks.2. Fix --adopt deleting source when target doesn't exist
Before: The source file in the dotfiles repo was deleted unconditionally before checking if the target existed.
After: Now checks if target exists before deleting source, with a warning message if adopt is not possible.
3. Fix directory creation in
SymlinkHandler::add()Before: After removing a file,
target_path.is_file()returns false, causingcreate_dir_all(&target_path)to create the target as a directory:After: Always uses
.parent()to only create parent directories.Testing
cargo checkpassescargo testpasses (except for pre-existing unrelated failure inignore_garbage_files)add_and_remove_symlinktest passesImpact
These bugs caused 185+ files to become empty directories when using
--force, affecting SSH keys, shell configs, fonts, and other critical dotfiles.