Stow
view release on metacpan or search on metacpan
lib/Stow.pm.in view on Meta::CPAN
my $action = $self->{link_task_for}{$path}->{action};
internal_error("bad task action: $action")
unless $action eq 'remove' or $action eq 'create';
debug(4, 1, "link_task_action($path): link task exists with action $action");
return $action;
}
=head2 dir_task_action($path)
Finds the dir task action for the given path, if there is one.
=over 4
=item $path
=back
Returns C<'remove'>, C<'create'>, or C<''> if there is no action.
Throws a fatal exception if an invalid action is found.
=cut
sub dir_task_action {
my $self = shift;
my ($path) = @_;
if (! exists $self->{dir_task_for}{$path}) {
debug(4, 4, "| dir_task_action($path): no task");
return '';
}
my $action = $self->{dir_task_for}{$path}->{action};
internal_error("bad task action: $action")
unless $action eq 'remove' or $action eq 'create';
debug(4, 4, "| dir_task_action($path): dir task exists with action $action");
return $action;
}
=head2 parent_link_scheduled_for_removal($target_path)
Determine whether the given path or any parent thereof is a link
scheduled for removal
=over 4
=item $target_path
=back
Returns boolean
=cut
sub parent_link_scheduled_for_removal {
my $self = shift;
my ($target_path) = @_;
my $prefix = '';
for my $part (split m{/+}, $target_path) {
$prefix = join_paths($prefix, $part);
debug(5, 4, "| parent_link_scheduled_for_removal($target_path): prefix $prefix");
if (exists $self->{link_task_for}{$prefix} and
$self->{link_task_for}{$prefix}->{action} eq 'remove') {
debug(4, 4, "| parent_link_scheduled_for_removal($target_path): link scheduled for removal");
return 1;
}
}
debug(4, 4, "| parent_link_scheduled_for_removal($target_path): returning false");
return 0;
}
=head2 is_a_link($target_path)
Determine if the given path is a current or planned link.
=over 4
=item $target_path
=back
Returns false if an existing link is scheduled for removal and true if
a non-existent link is scheduled for creation.
=cut
sub is_a_link {
my $self = shift;
my ($target_path) = @_;
debug(4, 2, "is_a_link($target_path)");
if (my $action = $self->link_task_action($target_path)) {
if ($action eq 'remove') {
debug(4, 2, "is_a_link($target_path): returning 0 (remove action found)");
return 0;
}
elsif ($action eq 'create') {
debug(4, 2, "is_a_link($target_path): returning 1 (create action found)");
return 1;
}
}
if (-l $target_path) {
# Check if any of its parent are links scheduled for removal
# (need this for edge case during unfolding)
debug(4, 2, "is_a_link($target_path): is a real link");
return $self->parent_link_scheduled_for_removal($target_path) ? 0 : 1;
}
debug(4, 2, "is_a_link($target_path): returning 0");
return 0;
}
=head2 is_a_dir($target_path)
Determine if the given path is a current or planned directory
=over 4
( run in 0.673 second using v1.01-cache-2.11-cpan-71847e10f99 )