unstow_node: extract new unstow_existing_node() sub

This commit is contained in:
Adam Spiers 2024-04-01 11:49:07 +01:00
parent 42cc1d2e60
commit 517384407b

View file

@ -938,22 +938,7 @@ sub unstow_node {
$self->unstow_link_node($package, $target, $path); $self->unstow_link_node($package, $target, $path);
} }
elsif (-e $target) { elsif (-e $target) {
debug(4, 2, "Evaluate existing node: $target"); $self->unstow_existing_node($package, $target, $source);
if (-d $target) {
$self->unstow_contents($package, $target, $source);
# This action may have made the parent directory foldable
if (my $parent = $self->foldable($target)) {
$self->fold_tree($target, $parent);
}
}
else {
$self->conflict(
'unstow',
$package,
"existing target is neither a link nor a directory: $target",
);
}
} }
else { else {
debug(2, 1, "$target did not exist to be unstowed"); debug(2, 1, "$target did not exist to be unstowed");
@ -1033,6 +1018,27 @@ sub unstow_valid_link {
#} #}
} }
sub unstow_existing_node {
my $self = shift;
my ($package, $target, $source) = @_;
debug(4, 2, "Evaluate existing node: $target");
if (-d $target) {
$self->unstow_contents($package, $target, $source);
# This action may have made the parent directory foldable
if (my $parent = $self->foldable($target)) {
$self->fold_tree($target, $parent);
}
}
else {
$self->conflict(
'unstow',
$package,
"existing target is neither a link nor a directory: $target",
);
}
}
=head2 link_owned_by_package($target, $source) =head2 link_owned_by_package($target, $source)
Determine whether the given link points to a member of a stowed Determine whether the given link points to a member of a stowed