report errors in send_file
[cloudstore.git] / lib / CloudStore / API.pm
index 6902520..c290794 100644 (file)
@@ -36,6 +36,7 @@ sub new {
 sub slice_dir_port {
        my ($self,$slice) = @_;
        my ( undef, $dir, $port, undef ) = getgrnam($slice);
+       die "getgrnam $slice: $!" if $!;
        warn "# slice_dir_port $slice = $dir $port\n";
        return ( $dir, $port );
 }
@@ -77,8 +78,12 @@ sub create_user {
        close($fh);
 
        my $slice = $ENV{SLICE} || 's1';
+       $slice =~ s{/.+/(\w+)$}{$1};
        my ( $dir, $port ) = $self->slice_dir_port( $slice );
 
+       $dir ||= $ENV{SLICE};
+       $port ||= 6501;
+
        if ( ! $found ) {
                $max_uid++;
                $dir .= "/$max_uid";
@@ -101,7 +106,7 @@ sub create_user {
        # FIXME update quota only on create?
        $self->gearman_do( $self->dir2gearman( $dir, 'quota', 'set' ) => "$found $new_quota" );
 
-       return $found;
+       return 'u' . $found;
 }
 
 sub mkbasepath {
@@ -222,6 +227,8 @@ sub send_file {
                $self->append( $t, 'recv', $size, $f->{uid}, $t_path );
                $self->append_meta('md5sum', $t, $md5 => $t_path ) if $md5; # md5sum for received files! FIXME -- cross-slice md5
                $self->refresh_file_list( $t );
+       } else {
+               warn "ERROR: send_file $f_full -> $t_full: $!";
        }
 
        return $size;
@@ -302,7 +309,9 @@ sub refresh_file_list {
        my $full_path = "$user->{dir}/.meta/files";
        if ( -e $full_path ) {
                warn "## refresh_file_list $full_path";
-               unlink $full_path;
+               unlink $full_path || warn "unlink $full_path: $!";
+       } else {
+               warn "## refresh_file_list $full_path missing";
        }
 }