Trash-Park
view release on metacpan or search on metacpan
lib/Trash/Park.pm view on Meta::CPAN
my $f_own = (stat($file))[4] == $>;
my $f_wr = -w $file;
my $d_wr = -w $dir;
return 1 if ($f_wr or $f_own) and
($d_wr or $d_own);
return;
}
###########################################
sub _db_init {
###########################################
my($self) = @_;
if(! -d $self->{trash_idx_dir}) {
mkd($self->{trash_idx_dir});
cd $self->{trash_idx_dir};
DEBUG "Creating db table trash ",
"in $self->{trash_idx_dir}";
$self->{dbh}->do(q{
CREATE TABLE trash (
path char(256),
move_time int,
uid int,
mode int,
)}) or die $self->{dbh}->errstr();
cdback;
}
}
###########################################
package Trash::Park::Element;
###########################################
use Stat::lsMode;
use base qw(Class::Accessor);
Trash::Park::Element->mk_accessors(qw(file move_time uid mode));
###########################################
sub new {
###########################################
my($class, @options) = @_;
# mode, move_time, user, file coming in
my $self = { @options };
bless $self, $class;
}
###########################################
sub as_string {
###########################################
my($self) = @_;
return sprintf "%s %s %10s %s",
scalar format_mode($self->{mode} & 07777),
nice_time($self->{move_time}),
getpwuid($self->{uid}) || $self->{uid},
$self->{file};
}
###########################################
sub nice_time {
###########################################
my($time) = @_;
my ($sec,$min,$hour,$mday,$mon,$year,
$wday,$yday,$isdst) = localtime($time);
return sprintf
"%d-%02d-%02d %02d:%02d:%02d",
$year + 1900, $mon+1, $mday, $hour,
$min, $sec;
}
1;
__END__
=head1 NAME
Trash::Park - Store deleted files safely with querying capability
=head1 SYNOPSIS
# Command line:
$ trashpark some/file/somewhere.dat
$ trashpark -l
# API
use Trash::Park;
my $trasher = Trash::Park->new();
# Move foo.dat to trash can
$trasher->trash("foo.dat");
# List content of trashcan
for my $item (@{$trasher->history()}) {
print $item->as_string(), "\n";
}
# Expire items with move dates older than 3 days
$trasher->expire(3 * 24 * 3600);
=head1 DESCRIPTION
C<Trash::Park> helps removing files by hiding them in a safe location
and querying details of these parking moves.
C<Trash::Park> comes with a command line utility, C<trashpark>.
=head1 METHODS
=over 4
=item C<my $trasher = Trash::Park-E<gt>new()>
( run in 1.443 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )