From 744ba651f50341a998c97341809eeda4f8e181e0 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Sun, 7 Apr 2024 13:08:56 +0100 Subject: [PATCH] unstow_link_node(): don't register conflicts when unstowing unowned links --- lib/Stow.pm.in | 17 ++++------------- t/unstow.t | 41 ++++++----------------------------------- 2 files changed, 10 insertions(+), 48 deletions(-) diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index 40351bb..7647a42 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -830,19 +830,10 @@ sub unstow_link_node { my ($existing_pkg_path_from_cwd, $existing_stow_path, $existing_package) = $self->find_stowed_path($target_subpath, $link_dest); if (not $existing_pkg_path_from_cwd) { - if ($self->{compat}) { - # We're traversing the target tree not the package tree, - # so we definitely expect to find stuff not owned by stow. - # Therefore we can't flag a conflict. - return; - } - else { - $self->conflict( - 'unstow', - $package, - "existing target is not owned by stow: $target_subpath => $link_dest" - ); - } + # The user is unstowing the package, so they don't want links to it. + # Therefore we should allow them to have a link pointing elsewhere + # which would conflict with the package if they were stowing it. + debug(5, 3, "Ignoring unowned link $target_subpath => $link_dest"); return; } diff --git a/t/unstow.t b/t/unstow.t index 9fd7852..1c7f967 100755 --- a/t/unstow.t +++ b/t/unstow.t @@ -154,46 +154,17 @@ subtests("existing link is owned by stow but is invalid so it gets removed anywa ); }); -subtest("Existing link is not owned by stow", sub { - plan tests => 2; - $ENV{HOME} = $ABS_TEST_DIR; - cd($repo); - cd("$TEST_DIR/target"); - my $stow = new_Stow(); +subtests("Existing invalid link is not owned by stow", sub { + my ($stow) = @_; + plan tests => 3; make_path('../stow/pkg5/bin5'); make_invalid_link('bin5', '../not-stow'); $stow->plan_unstow('pkg5'); - is($stow->get_conflict_count, 1, 'conflict count'); - my %conflicts = $stow->get_conflicts(); - is_deeply( - \%conflicts, - { - 'unstow' => { - 'pkg5' => [ - 'existing target is not owned by stow: bin5 => ../not-stow' - ] - } - } - => "existing link not owned by stow" - ); -}); - -subtest("Existing link is not owned by stow (compat mode)", sub { - plan tests => 2; - $ENV{HOME} = $COMPAT_ABS_TEST_DIR; - cd($repo); - cd("$COMPAT_TEST_DIR/target"); - my $stow = new_compat_Stow(); - - make_path('../stow/pkg5/bin5'); - make_invalid_link('bin5', '../not-stow'); - - $stow->plan_unstow('pkg5'); - # Unlike the non-compat test above, this doesn't cause any conflicts. - ok(-l 'bin5'); - is(readlink('bin5'), '../not-stow' => "existing link not owned by stow"); + is($stow->get_conflict_count, 0, 'conflict count'); + ok(-l 'bin5', 'invalid link not removed'); + is(readlink('bin5'), '../not-stow' => "invalid link not changed"); }); subtests("Target already exists, is owned by stow, but points to a different package", sub {