From 456424c560daad8b059b981ca5db9d85a18d4cb5 Mon Sep 17 00:00:00 2001 From: Adam Spiers Date: Mon, 1 Apr 2024 12:12:27 +0100 Subject: [PATCH] unstow_node_orig: replace a bunch of duplicated code with unstow_link_node() --- lib/Stow.pm.in | 55 ++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/lib/Stow.pm.in b/lib/Stow.pm.in index 7fdd2ee..bebca44 100755 --- a/lib/Stow.pm.in +++ b/lib/Stow.pm.in @@ -782,40 +782,7 @@ sub unstow_node_orig { # Does the target exist? if ($self->is_a_link($target)) { - debug(4, 1, "Evaluate existing link: $target"); - - # Where is the link pointing? - my $existing_source = $self->read_a_link($target); - if (not $existing_source) { - error("Could not read link: $target"); - } - - # Does it point to a node under any stow directory? - my ($existing_path, $existing_stow_path, $existing_package) = - $self->find_stowed_path($target, $existing_source); - if (not $existing_path) { - # We're traversing the target tree not the package tree, - # so we definitely expect to find stuff not owned by stow. - # Therefore we can't flag a conflict. - return; # XXX # - } - - # Does the existing $target actually point to anything? - if (-e $existing_path) { - # Does link point to the right place? - if ($existing_path eq $path) { - $self->do_unlink($target); - } - elsif ($self->override($target)) { - debug(2, 0, "--- overriding installation of: $target"); - $self->do_unlink($target); - } - # else leave it alone - } - else { - debug(2, 0, "--- removing invalid link into a stow directory: $path"); - $self->do_unlink($target); - } + $self->unstow_link_node($package, $target, $path); } elsif (-d $target) { $self->unstow_contents_orig($package, $target); @@ -966,12 +933,20 @@ sub unstow_link_node { my ($existing_path, $existing_stow_path, $existing_package) = $self->find_stowed_path($target, $existing_source); if (not $existing_path) { - $self->conflict( - 'unstow', - $package, - "existing target is not owned by stow: $target => $existing_source" - ); - return; # XXX # + if ($self->{compat}) { + # We're traversing the target tree not the package tree, + # so we definitely expect to find stuff not owned by stow. + # Therefore we can't flag a conflict. + return; + } + else { + $self->conflict( + 'unstow', + $package, + "existing target is not owned by stow: $target => $existing_source" + ); + } + return; } # Does the existing $target actually point to anything?