unstow_node: extract new unstow_link_node() sub

This commit is contained in:
Adam Spiers 2024-04-01 11:46:10 +01:00
parent cc592bdc44
commit 42cc1d2e60

View file

@ -935,6 +935,35 @@ sub unstow_node {
# Does the target exist?
if ($self->is_a_link($target)) {
$self->unstow_link_node($package, $target, $path);
}
elsif (-e $target) {
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",
);
}
}
else {
debug(2, 1, "$target did not exist to be unstowed");
}
return;
}
sub unstow_link_node {
my $self = shift;
my ($package, $target, $path) = @_;
debug(4, 2, "Evaluate existing link: $target");
# Where is the link pointing?
@ -969,29 +998,6 @@ sub unstow_node {
$self->do_unlink($target);
}
}
elsif (-e $target) {
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",
);
}
}
else {
debug(2, 1, "$target did not exist to be unstowed");
}
return;
}
sub unstow_valid_link {
my $self = shift;