From bfab7a952b5a81832822807b0bdb818af19924cd Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 15 Mar 2012 22:53:04 +0100 Subject: [PATCH] cross slice send_file using symlink --- lib/CloudStore/API.pm | 36 ++++++++++++++++++++++-------------- t/API.t | 4 +++- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/CloudStore/API.pm b/lib/CloudStore/API.pm index ef39524..0f709c9 100644 --- a/lib/CloudStore/API.pm +++ b/lib/CloudStore/API.pm @@ -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 --- 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; -- 2.20.1