From 517384407b5fa5b60be8edadd4515cfd81972694 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Mon, 1 Apr 2024 11:49:07 +0100 Subject: [PATCH] unstow_node: extract new unstow_existing_node() sub --- lib/Stow.pm.in | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index 3be67ed..7fdd2ee 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -938,22 +938,7 @@ sub unstow_node { $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", - ); - } + $self->unstow_existing_node($package, $target, $source); } else { 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) Determine whether the given link points to a member of a stowed