unstow_node: extract new unstow_valid_link() sub

This commit is contained in:
Adam Spiers 2024-04-01 11:40:26 +01:00
parent 1f752a3c94
commit cc592bdc44

View file

@ -962,6 +962,40 @@ sub unstow_node {
# Does the existing $target actually point to anything? # Does the existing $target actually point to anything?
if (-e $existing_path) { if (-e $existing_path) {
$self->unstow_valid_link($path, $target, $existing_path);
}
else {
debug(2, 0, "--- removing invalid link into a stow directory: $path");
$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;
my ($path, $target, $existing_path) = @_;
# Does link points to the right place? # Does link points to the right place?
# Adjust for dotfile if necessary. # Adjust for dotfile if necessary.
@ -992,34 +1026,6 @@ sub unstow_node {
# ); # );
#} #}
} }
else {
debug(2, 0, "--- removing invalid link into a stow directory: $path");
$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;
}
=head2 link_owned_by_package($target, $source) =head2 link_owned_by_package($target, $source)