App-FileSync
view release on metacpan or search on metacpan
lib/App/FileSync/Verify.pm view on Meta::CPAN
push @{ $found{modified} }, { p => $path, expected => $entry->{h}, got => $have->{h} };
} else {
next;
}
$seen{$path} = 1;
}
for my $path (sort keys %{$manifest}) {
next if $entries->{$path} || $seen{$path};
push @{ $found{extra} }, { p => $path, t => $type_of->($manifest->{$path}) };
}
$found{seen} = \%seen;
return \%found;
}
# _sample_check
# Purpose: rehash a random sample of files the scan trusted.
# Entry: $wanted > 0; $found is _compare's result, updated in place.
# Exit: returns how many files were rehashed.
# Side effects: reads the sampled files; appends to $found->{modified}.
sub _sample_check :Private {
my ($root, $entries, $manifest, $wanted, $found) = @_;
# Only a file on both sides can be compared by content.
my @candidates = grep {
ref($entries->{$_}) eq 'HASH'
&& $type_of->($entries->{$_}) eq $TYPE_FILE
&& $manifest->{$_}
&& $type_of->($manifest->{$_}) eq $TYPE_FILE
} sort keys %{$entries};
my $sampled = 0;
for my $path (sample($wanted, @candidates)) {
my $got = sha256_file(File::Spec->catfile($root, split m{/}, $path));
next unless defined $got;
$sampled++;
my $expected = $entries->{$path}{h};
next if !defined $expected || $got eq $expected || $found->{seen}{$path};
push @{ $found->{modified} }, { p => $path, expected => $expected, got => $got, sampled => 1 };
$found->{seen}{$path} = 1;
}
return $sampled;
}
1;
__END__
=head1 LIMITATIONS
=over 4
=item * A shallow verify trusts size and mtime, so it cannot see a change that
kept both; use C<deep> or C<sample> for that.
=item * The report says what differs, not which side is right. After a
restore from backup the index, not the tree, is usually the stale one; see
C<filesync-admin reindex>.
=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 2.451 seconds using v1.01-cache-2.11-cpan-99fa8243a42 )