From: Dobrica Pavlinusic Date: Thu, 8 Sep 2011 22:27:07 +0000 (+0000) Subject: first working /.send/ implementation for all cases X-Git-Url: http://git.rot13.org/?p=cloudstore.git;a=commitdiff_plain;h=20718e6856f13fc76968560136e746d0fff5c7a2 first working /.send/ implementation for all cases It doesn't die on non-existing files, but just on fatal errors, create files in storage for sent file --- diff --git a/lib/CloudStore/Couchbase.pm b/lib/CloudStore/Couchbase.pm index d2a0c39..c59a1ac 100644 --- a/lib/CloudStore/Couchbase.pm +++ b/lib/CloudStore/Couchbase.pm @@ -188,18 +188,23 @@ sub new_link { 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} ) { - - while ( $file =~ s{/[^/]+/../}{/} ) { - warn "cleanup parent dir /../ $file"; + my $link_to = readlink $path; + warn "$link_to"; + if ( $link_to =~ s{^\Q/rsyncd-munged/\E}{/} ) { + + my $s = $path; + $s =~ s{/[^/]+$}{}; # strip filename + while ( $link_to =~ s{/../}{/} ) { + $s =~ s{/[^/]+$}{} || die "can't strip $s"; + warn "## simplify $s $link_to\n"; } + $s .= $link_to; - warn "SEND To:$to Name:$name File:$file\n"; - my $s = "users/$data->{login}/blob/$file"; my $d = "users/$to/blob"; - die "no user $to" unless -e $d; + if ( ! -e $d ) { + warn "ERROR: no to user $to in $d"; + return; + } $d .= "/$name"; # $name can contain directories so we must create them @@ -207,18 +212,26 @@ sub new_link { $to_dir =~ s{/[^/]+$}{}; make_path $to_dir if ! -e $to_dir; - warn "link $s -> $d\n"; - link $s, $d; + if ( ! -e $s ) { + warn "ERROR: can't find source $s"; + } else { + + warn "link $s -> $d\n"; + link $s, $d; + + my ($l,$f) = ($1,$2) if $s =~ m{users/([^/]+)/blob/(.+)}; + + my $origin = $self->file_get({ + login => $l, + file => $f, + }); + $self->new_file($origin); + warn "INFO: sent file ",dump($origin); + } - my $origin = $self->file_get({ - login => $data->{login}, - file => $file, - }); - $self->new_file($origin); - warn "INFO: sent file ",dump($origin); } else { - warn "ERROR: can't SEND To:$to Name:$name File:$file"; + warn "ERROR: can't SEND To:$to Name:$name Link:$link_to"; } } } diff --git a/test.sh b/test.sh index 5c92167..5667336 100755 --- a/test.sh +++ b/test.sh @@ -73,10 +73,12 @@ push md5sum -v # test send ps ax >> sent-to-test2 +push sent-to-test2 # must be done before first send + mkdir -p .send/test2/received -ln -s ../../../sent-to-test2 .send/test2/received/ +ln -s ../../../sent-to-test2 .send/test2/received/new-name -push send-to-test2 .send -rvl +push .send -rvl tail -20 $user_dir/log/*