sub mkbasepath {
my ($self,$path,$opts) = @_;
+ cluck "ERROR: mkbasepath called without opts, so user is root!" unless $opts;
+ if ( $ENV{DEBUG} ) {
+ warn "# mkbasepath $path ",dump($opts);
+ $opts->{verbose} ||= 1;
+ }
$path =~ s{/[^/]+$}{};
- make_path $path unless -d $path;
+ if ( ! -d $path ) {
+ make_path $path, $opts;
+ }
}
sub user_dir {
$user = $self->user_info($user) unless ref $user eq 'HASH';
my $usage_path = $user->{dir} . '/.meta/files.usage';
- if ( -e $usage_path ) {
+ $self->mkbasepath( $usage_path, { uid => $user->{uid} } );
+ if ( ! -e $usage_path ) {
warn "# usage $usage_path missing";
$self->list_files($user);
}
my $size = <$fh>;
chomp $size;
- warn "# usage $user->{login} usage: $size\n";
+ warn "# usage $user->{login} $size bytes\n";
return $size;
=for slow and broken
$user = $self->user_info($user) unless ref $user eq 'HASH';
my $full_path = "$user->{dir}/$path";
- return -s $full_path;
+ my $size = -s $full_path;
+ warn "# file_size $full_path = $size bytes\n";
+ return $size;
}
sub list_files {
die "no dir for ",dump($user) unless exists $user->{dir};
my $files = $user->{dir} . '/.meta/files';
- if ( -e $files && -s $files > 0) {
+ $self->mkbasepath( $files, { uid => $user->{uid} } );
+ if ( -e $files && -s $files > 0 && -e "$files.usage") {
local $/ = undef;
open(my $fh, '<', $files);
my $list = <$fh>;
close($fh);
- warn "# list_files $user->{login} cached ", length($list), " bytes";
+ warn "# list_files $user->{login} from cache ", length($list), " bytes\n";
return $list;
}
my $list_txt;
while(<$pipe>) {
chomp;
- my ( $type, $size, $name ) = split(/\s/, $_);
+ my ( $type, $size, $name ) = split(/\s/, $_, 3);
$name =~ s{$dir}{./};
$name =~ s{//+}{/}g;
my $line = "$type $size $name\n";