unstow_link_node(): don't register conflicts when unstowing unowned links

This commit is contained in:
Adam Spiers 2024-04-07 13:08:56 +01:00
parent 06fdfc185f
commit 744ba651f5
2 changed files with 10 additions and 48 deletions

View file

@ -830,19 +830,10 @@ sub unstow_link_node {
my ($existing_pkg_path_from_cwd, $existing_stow_path, $existing_package) = my ($existing_pkg_path_from_cwd, $existing_stow_path, $existing_package) =
$self->find_stowed_path($target_subpath, $link_dest); $self->find_stowed_path($target_subpath, $link_dest);
if (not $existing_pkg_path_from_cwd) { if (not $existing_pkg_path_from_cwd) {
if ($self->{compat}) { # The user is unstowing the package, so they don't want links to it.
# We're traversing the target tree not the package tree, # Therefore we should allow them to have a link pointing elsewhere
# so we definitely expect to find stuff not owned by stow. # which would conflict with the package if they were stowing it.
# Therefore we can't flag a conflict. debug(5, 3, "Ignoring unowned link $target_subpath => $link_dest");
return;
}
else {
$self->conflict(
'unstow',
$package,
"existing target is not owned by stow: $target_subpath => $link_dest"
);
}
return; return;
} }

View file

@ -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 { subtests("Existing invalid link is not owned by stow", sub {
plan tests => 2; my ($stow) = @_;
$ENV{HOME} = $ABS_TEST_DIR; plan tests => 3;
cd($repo);
cd("$TEST_DIR/target");
my $stow = new_Stow();
make_path('../stow/pkg5/bin5'); make_path('../stow/pkg5/bin5');
make_invalid_link('bin5', '../not-stow'); make_invalid_link('bin5', '../not-stow');
$stow->plan_unstow('pkg5'); $stow->plan_unstow('pkg5');
is($stow->get_conflict_count, 1, 'conflict count'); is($stow->get_conflict_count, 0, 'conflict count');
my %conflicts = $stow->get_conflicts(); ok(-l 'bin5', 'invalid link not removed');
is_deeply( is(readlink('bin5'), '../not-stow' => "invalid link not changed");
\%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");
}); });
subtests("Target already exists, is owned by stow, but points to a different package", sub { subtests("Target already exists, is owned by stow, but points to a different package", sub {