mkbasepath now correctly creates paths with uid
authorDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Mon, 23 Apr 2012 15:34:55 +0000 (17:34 +0200)
committerDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Mon, 23 Apr 2012 15:34:55 +0000 (17:34 +0200)
lib/CloudStore/API.pm
t/API.t

index 5dea04e..1b2625d 100644 (file)
@@ -111,8 +111,15 @@ sub create_user {
 
 sub mkbasepath {
        my ($self,$path,$opts) = @_;
 
 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{/[^/]+$}{};
        $path =~ s{/[^/]+$}{};
-       make_path $path unless -d $path;
+       if ( ! -d $path ) {
+               make_path $path, $opts;
+       }
 }
 
 sub user_dir {
 }
 
 sub user_dir {
diff --git a/t/API.t b/t/API.t
index 99d1831..4f81d1f 100755 (executable)
--- a/t/API.t
+++ b/t/API.t
@@ -2,8 +2,9 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Test::More tests => 26;
+use Test::More tests => 29;
 use Data::Dump qw(dump);
 use Data::Dump qw(dump);
+use File::Path;
 
 use lib 'lib';
 
 
 use lib 'lib';
 
@@ -11,6 +12,8 @@ use_ok 'CloudStore::API';
 
 ok my $o = CloudStore::API->new('s1'), 'new';
 
 
 ok my $o = CloudStore::API->new('s1'), 'new';
 
+die 'You need to run this test as root' unless $> == 0;
+
 cmp_ok $o->create_user('md5@example.com','md5sum',0), 'eq', 'u2000', 'create_user md5';
 
 ok my $info = $o->user_info( 'md5' ), 'user_info';
 cmp_ok $o->create_user('md5@example.com','md5sum',0), 'eq', 'u2000', 'create_user md5';
 
 ok my $info = $o->user_info( 'md5' ), 'user_info';
@@ -60,3 +63,15 @@ usage $uid2;
 ok $o->delete( $uid, 'bar.txt' );
 usage $uid;
 
 ok $o->delete( $uid, 'bar.txt' );
 usage $uid;
 
+my $path = "/tmp/test.$$/base/dir/path";
+ok $o->mkbasepath( $path, { uid => $info->{uid} } ), "mkbasepath $path";
+
+ok ! $o->mkbasepath( $path, { uid => $info->{uid} } ), "exists $path";
+
+$path =~ s{/path}{}; # strip file
+my $uid = (stat($path))[4];
+diag "uid $path = $uid";
+cmp_ok $uid, '==', $info->{uid}, "owner $info->{uid}";
+
+File::Path::remove_tree("/tmp/test.$$"); # cleanup
+