App-FileSync
view release on metacpan or search on metacpan
lib/App/FileSync/Scan.pm view on Meta::CPAN
my $names = list_dir($abs);
unless ($names) {
_skip($context, length $rel ? $rel : '.', 'scan.cannot_list', os_error());
return 0;
}
my $entries = 0;
for my $name (@{$names}) {
my $child_rel = length $rel ? "$rel/$name" : $name;
next if $context->{ignore} && $context->{ignore}->match($child_rel);
my $child_abs = File::Spec->catfile($abs, $name);
my @stat = Time::HiRes::lstat($child_abs);
if (!@stat) {
_skip($context, $child_rel, 'scan.cannot_stat', os_error());
} elsif (-d _) {
# An empty directory is worth syncing; a non-empty one is implied
# by the files inside it.
$entries++;
if (_walk($context, $child_abs, $child_rel) == 0) {
$context->{manifest}{$child_rel} = { t => $TYPE_DIR };
$context->{stats}{dirs}++;
}
} elsif (-f _) {
my $entry = $file_entry->($context, $child_abs, $child_rel, \@stat) or next;
$context->{manifest}{$child_rel} = $entry;
$context->{stats}{files}++;
$context->{stats}{bytes} += $entry->{s};
$entries++;
} else {
_skip($context, $child_rel, -l _ ? 'scan.symlink' : 'scan.special');
}
}
return $entries;
}
# _skip
# Purpose: record a path the manifest leaves out, and why.
# Entry: $key names the reason in the catalogue; $error is the OS
# reason where there is one.
# Exit: returns 1.
# Side effects: updates $context->{skipped} and the skipped count.
sub _skip :Private {
my ($context, $rel, $key, $error) = @_;
$context->{skipped}{$rel} = message($key, { error => $error });
$context->{stats}{skipped}++;
return 1;
}
1;
__END__
=head1 LIMITATIONS
=over 4
=item * The cache trusts size and mtime. A tool that rewrites a file and
restores its mtime (some backup restorers do) goes unnoticed until a
C<verify --deep>.
=item * Every run stats every file; there is no change notification. On a
very large tree the walk, not the transfer, dominates a quiet run.
=item * Directory order is sorted, which costs an O(n log n) per directory
but makes manifests and logs reproducible.
=back
=head1 AUTHOR
Nigel Horne, C<< <njh at nigelhorne.com> >>
=head1 LICENCE AND COPYRIGHT
Copyright 2026 Nigel Horne.
Usage is subject to the GPL2 licence terms.
If you use it,
please let me know.
=cut
( run in 1.113 second using v1.01-cache-2.11-cpan-99fa8243a42 )