Brackup
view release on metacpan or search on metacpan
lib/Brackup/Root.pm view on Meta::CPAN
sub chunk_size {
my $self = shift;
return $self->{chunk_size} || (64 * 2**20); # default to 64MB
}
sub publicname {
# FIXME: let users define the public (obscured) name of their roots. s/porn/media/, etc.
# because their metafile key names (which contain the root) aren't encrypted.
return $_[0]{name};
}
sub name {
return $_[0]{name};
}
sub ignore {
my ($self, $pattern) = @_;
push @{ $self->{ignore} }, qr/$pattern/;
}
sub path {
return $_[0]{dir};
}
sub noatime {
return $_[0]{noatime};
}
sub foreach_file {
my ($self, $cb) = @_;
chdir $self->{dir} or die "Failed to chdir to $self->{dir}";
my %statcache; # file -> statobj
find({
no_chdir => 1,
preprocess => sub {
my $dir = $File::Find::dir;
my @good_dentries;
DENTRY:
foreach my $dentry (@_) {
next if $dentry eq "." || $dentry eq "..";
my $path = "$dir/$dentry";
$path =~ s!^\./!!;
# skip the digest database file. not sure if this is smart or not.
# for now it'd be kinda nice to have, but it's re-creatable from
# the backup meta files later, so let's skip it.
next if $self->{digcache_file} && $path eq $self->{digcache_file};
# GC: seems to work fine as of at least gpg 1.4.5, so commenting out
# gpg seems to barf on files ending in whitespace, blowing
# stuff up, so we just skip them instead...
#if ($self->gpg_rcpts && $path =~ /\s+$/) {
# warn "Skipping file ending in whitespace: <$path>\n";
# next;
#}
my $statobj = File::stat::lstat($path);
my $is_dir = -d _;
foreach my $pattern (@{ $self->{ignore} }) {
next DENTRY if $path =~ /$pattern/;
next DENTRY if $is_dir && "$path/" =~ /$pattern/;
next DENTRY if $path =~ m!(^|/)\.brackup-digest\.db(-journal)?$!;
}
$statcache{$path} = $statobj;
push @good_dentries, $dentry;
}
# to let it recurse into the good directories we didn't
# already throw away:
return sort @good_dentries;
},
wanted => sub {
my $path = $_;
$path =~ s!^\./!!;
my $stat_obj = delete $statcache{$path};
my $file = Brackup::File->new(root => $self,
path => $path,
stat => $stat_obj,
);
$cb->($file);
},
}, ".");
}
sub as_string {
my $self = shift;
return $self->{name} . "($self->{dir})";
}
sub du_stats {
my $self = shift;
my $show_all = $ENV{BRACKUP_DU_ALL};
my @dir_stack;
my %dir_size;
my $pop_dir = sub {
my $dir = pop @dir_stack;
printf("%-20d%s\n", $dir_size{$dir} || 0, $dir);
delete $dir_size{$dir};
};
my $start_dir = sub {
my $dir = shift;
unless ($dir eq ".") {
my @parts = (".", split(m!/!, $dir));
while (@dir_stack >= @parts) {
$pop_dir->();
}
}
push @dir_stack, $dir;
};
$self->foreach_file(sub {
my $file = shift;
my $path = $file->path;
( run in 2.397 seconds using v1.01-cache-2.11-cpan-5c0b1e786e0 )