cross slice send_file using symlink
authorDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Thu, 15 Mar 2012 21:53:04 +0000 (22:53 +0100)
committerDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Thu, 15 Mar 2012 21:53:04 +0000 (22:53 +0100)
lib/CloudStore/API.pm
t/API.t

index ef39524..0f709c9 100644 (file)
@@ -183,25 +183,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 74a2b55..0b31f9c 100755 (executable)
--- a/t/API.t
+++ b/t/API.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 26;
+use Test::More tests => 27;
 use Data::Dump qw(dump);
 
 use lib 'lib';
@@ -51,6 +51,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;