create directories in /.send/login/some/dir/file
[cloudstore.git] / lib / CloudStore / Couchbase.pm
index f29db0a..ddd5c8b 100644 (file)
@@ -182,16 +182,25 @@ sub new_link {
 
        warn "# new_link ",dump $data;
 
-       if ( $data->{file} =~ m{^(.*/?)\.send/([^/]+)/(.+)} ) {
+       if ( $data->{file} =~ m{^(.*/?)\.send/([^/]+)/(.+)$} ) {
                my ( $dir, $to, $name ) = ( $1, $2, $3 );
                my $path = "users/$data->{login}/blob/" . $data->{file};
                my $file = readlink $path;
+               warn "## $path -> $file";
                if ( $file =~ s{^\Q/rsyncd-munged/../../\E}{$dir} ) {
                        warn "SEND To:$to Name:$name File:$file\n";
                        my $s = "users/$data->{login}/blob/$file";
-                       my $d = "users/$to/blob/$name";
-                       link $s, $d;
+                       my $d = "users/$to/blob";
+                       die "no user $to" unless -e $d;
+                       $d .= "/$name";
+
+                       # since $name can contain directories we must create them
+                       my $to_dir = $d;
+                       $to_dir =~ s{/[^/]+$}{};
+                       make_path $to_dir if ! -e $to_dir;
+
                        warn "link $s -> $d\n";
+                       link $s, $d;
                } else {
                        warn "ERROR: can't SEND To:$to Name:$name File:$file";
                }