App-FileSync
view release on metacpan or search on metacpan
lib/App/FileSync/Trash.pm view on Meta::CPAN
year => $year,
month => $month,
day => $day,
date => "$year-$month-$day",
};
}
}
}
return \@buckets;
}
# _restore_entry
# Purpose: copy a trashed file or directory tree out of the trash.
# Entry: $src exists; $to does not (or is a directory being filled).
# Exit: returns 1.
# Side effects: creates $to; raises trash.cannot_stat or trash.not_regular.
sub _restore_entry :Private {
my ($src, $to) = @_;
my @stat = Time::HiRes::lstat($src);
throw('trash.cannot_stat', { path => $src, error => os_error() }) unless @stat;
if (-d _) {
ensure_dir($to);
_restore_entry(File::Spec->catfile($src, $_), File::Spec->catfile($to, $_))
for @{ list_dir($src) || [] };
# Directory metadata last: filling it changed its mtime.
chmod($stat[2] & $MODE_MASK, $to) if $HAS_MODES;
utime($stat[9], $stat[9], $to);
return 1;
}
throw('trash.not_regular', { path => $src }) unless -f _;
copy_preserving($src, $to, \@stat);
return 1;
}
# _midnight_epoch
# Purpose: the UTC epoch at the start of a bucket's day.
# Entry: numeric year, month (1-12) and day strings from a bucket path.
# Exit: returns the epoch.
# Side effects: none.
sub _midnight_epoch :Private {
my ($year, $month, $day) = @_;
return Time::Local::timegm(0, 0, 0, $day, $month - 1, $year);
}
1;
__END__
=head1 LIMITATIONS
=over 4
=item * A same-day collision is stored as C<PATH.N>. A real file whose name
already ends in C<.N> (C<backup.1>) deleted the same day as C<backup> is
therefore listed as a version of C<backup> too.
=item * Moving a directory across filesystems is not supported; files are
copied and removed, directories must rename.
=item * Pruning works in whole UTC days, so retention is accurate to a day.
=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.234 second using v1.01-cache-2.11-cpan-99fa8243a42 )