Merge branch 'master' of git.rot13.org:/git/cloudstore
authorDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2012 16:54:22 +0000 (18:54 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 11 Apr 2012 17:09:54 +0000 (19:09 +0200)
Conflicts:
t/API.t

gearman/list_files [new file with mode: 0755]
init.d/s1-stunnel
lib/CloudStore/API.pm
t/API.t
t/Gearman.t

diff --git a/gearman/list_files b/gearman/list_files
new file mode 100755 (executable)
index 0000000..ff11c69
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+while read path ; do
+       if [ -e $path/.meta/files ] ; then
+               cat $path/.meta/files
+       else
+               find -L $path -printf "%y %s %p\n" | tee $path/.meta/files
+       fi
+done
index fa3c849..7ccfe49 100755 (executable)
@@ -3,7 +3,7 @@
 . /srv/cloudstore/init.d/_start_stop
 BACKGROUND=0
 
-DAEMON="/usr/bin/stunnel -d 213.186.16.27:443 -r 6501 -P /tmp/$NAME.pid -o /tmp/$NAME.log -p /etc/ssl/rsync1.maxxo.com.pem"
+DAEMON="/usr/bin/stunnel -d 91.233.36.2:443 -r 6501 -P /tmp/$NAME.pid -o /tmp/$NAME.log -p /etc/ssl/rsync1.maxxo.com.pem"
 
 _start_stop $*
 
index 0b5d36e..a166b74 100644 (file)
@@ -197,25 +197,33 @@ sub send_file {
 
        $self->delete( $t, $t_path ) if -e $t_full;
 
-       my $ok = link $f_full, $t_full; 
-       $self->append( $t, 'recv', -s $t_full, $f->{uid}, $t_path );
-
-       $ok = -s $t_full if $ok; # replace true with file size
-
+       my $size = -s $f_full;
        my $md5;
-       if ( $f->{uid} == $self->{md5}->{uid} ) {
-               $md5 = $f_path; # we don't have local md5sum db for md5 user!
+
+       my $ok;
+       {
+               no autodie qw(link);
+               $ok = link $f_full, $t_full
+       };
+       if ( ! $ok || $! =~ m/cross-link/ ) {
+               $ok = symlink $f_full, $t_full;
        } else {
-               $md5 = $self->md5_get($f_full);
-       }
-       if ( ! $md5 ) {
-               warn "ERROR: no md5 for $f_path";
-               return $ok;
+               $size = -s $t_full;
+
+               if ( $f->{uid} == $self->{md5}->{uid} ) {
+                       $md5 = $f_path; # we don't have local md5sum db for md5 user!
+               } else {
+                       $md5 = $self->md5_get($f_full);
+               }
+
        }
 
-       $self->append_meta('md5sum', $t, $md5 => $t_path ); # md5sum for received files!
+       if ( $ok ) {
+               $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
+       }
 
-       return $ok;
+       return $size;
 }
 
 sub rename_file {
diff --git a/t/API.t b/t/API.t
index 7a22ef8..ecfe29a 100755 (executable)
--- a/t/API.t
+++ b/t/API.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 25;
+use Test::More tests => 26;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -49,6 +49,8 @@ ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', $uid => 'bar.txt' ), 'send_file
 usage $uid;
 usage $uid2;
 
+ok $o->send_file( $uid2 => 'dir1/dir2/bar.txt', 2004 => 'bar.txt' ), 'send_file cross-slice';
+
 ok $o->delete( $uid, 'foo.txt' );
 usage $uid;
 
index 9c03296..6983d67 100755 (executable)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 15;
+use Test::More tests => 19;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -16,7 +16,7 @@ my $user = $ARGV[0] || 2001;
 
 sub gearman {
        my ( $function, $args ) = @_;
-       ok my $o = CloudStore::Gearman->gearman_do( @_ ), $_[0];
+       ok my $o = CloudStore::Gearman->gearman_do( @_ ), join(' ',@_);
        diag dump $o;
        return $o;
 }
@@ -43,6 +43,13 @@ cmp_ok
 gearman( file_size => '~u2001/foo.txt' ), '==',
 gearman( file_size => '~u2002/baz.txt' ), 'size_same';
 
+diag "test symlink to other shard";
+gearman send_file => '~u2001/foo.txt#~u2004/foo.txt';
+my $size_1 = gearman( file_size => '~u2001/foo.txt' );
+my $size_2 = gearman( file_size => '~u2004/foo.txt' );
+
+cmp_ok $size_1, '==', $size_2, 'symlink size same';
+
 gearman delete => '~u2002/baz.txt';
 
 ok ! CloudStore::Gearman->gearman_do( file_size => '~u2002/baz.txt' ), 'deleted file size';