Make cleanup_invalid_links() more explicit

And add some debug.
This commit is contained in:
Adam Spiers 2020-11-02 00:54:15 +00:00
parent 86f4694d96
commit 832135e269

View file

@ -1003,6 +1003,9 @@ sub cleanup_invalid_links {
my $self = shift; my $self = shift;
my ($dir) = @_; my ($dir) = @_;
my $cwd = getcwd();
debug(2, 1, "cleanup_invalid_links for $dir (pwd=$cwd)");
if (not -d $dir) { if (not -d $dir) {
error("cleanup_invalid_links() called with a non-directory: $dir"); error("cleanup_invalid_links() called with a non-directory: $dir");
} }
@ -1019,7 +1022,13 @@ sub cleanup_invalid_links {
my $node_path = join_paths($dir, $node); my $node_path = join_paths($dir, $node);
if (-l $node_path and not exists $self->{link_task_for}{$node_path}) { next unless -l $node_path;
debug(2, 2, "checking validity of link $node_path");
if (exists $self->{link_task_for}{$node_path}) {
die "huh? link_task_for $node_path";
}
# Where is the link pointing? # Where is the link pointing?
# (don't use read_a_link() here) # (don't use read_a_link() here)
@ -1028,16 +1037,22 @@ sub cleanup_invalid_links {
error("Could not read link $node_path"); error("Could not read link $node_path");
} }
if ( if (-e join_paths($dir, $source)) {
not -e join_paths($dir, $source) and # bad link debug(4, 3, "link target $source exists; skipping clean up");
$self->path_owned_by_package($node_path, $source) # owned by stow next;
){ }
debug(2, 2,
"checking whether valid link $node_path -> $source is " .
"owned by stow");
if ($self->path_owned_by_package($node_path, $source)) {
# owned by stow
debug(2, 0, "--- removing stale link: $node_path => " . debug(2, 0, "--- removing stale link: $node_path => " .
join_paths($dir, $source)); join_paths($dir, $source));
$self->do_unlink($node_path); $self->do_unlink($node_path);
} }
} }
}
return; return;
} }