new .sync/send/timestamp
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 8 Oct 2011 23:24:03 +0000 (01:24 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 8 Oct 2011 23:24:03 +0000 (01:24 +0200)
lib/CloudStore/Store.pm
test.sh

index b4cc2c4..52c7ee7 100644 (file)
@@ -38,22 +38,54 @@ sub user_get {
 sub modify_file {
        my ( $self,$data ) = @_;
 
-#      if ( my $old = $self->file_get( $data ) ) {
-#              $self->usage_decr( $data );
-#      }
+       if ( $data->{file} =~ m{^(.*/).sync/send/([^/]+)$} ) {
+               my $from_dir = $1;
+               warn "SEND $2 from $from_dir";
+               my $sent_files;
+               open(my $send, '<', $self->blob_path($data) );
+               while(<$send>) {
+warn $_;
+                       chomp;
+                       my ( $to, $file ) = split(/\s+/,$_,2);
+                       my ( undef, undef, $uid, $gid, undef, undef, $email, $dir, $shell ) =
+                               getpwnam $to;
+
+                       my $from = $data;
+                       $from->{file} = $from_dir . $file;
+                       my $from_path = $self->blob_path($from);
+
+                       if ( ! -r $from_path ) {
+                               warn "ERROR: $from_path: $!";
+                               next;
+                       }
+
+                       my $to_path = "$dir/received/$file";
+                       my $to_dir = $to_path;
+                       $to_dir =~ s{/[^/]+$}{};
+                       mkdir $to_dir unless -e $to_dir;
+
+                       warn "SEND $from_path -> $to_path";
+                       $sent_files->{$to} += link $from_path, $to_path;
+                       # FIXME cross-shard
+               }
+
+               warn "SENT ",dump $sent_files;
+
+               return 0; # skip dedup
+       }
 
-       $self->new_file($data);
+       #return $file->{size} > 4096 ? 1 : 0; # FIXME
+       return 1; # dedup
 }
 
+# never called by rsync directly!
 sub new_file {
        my ( $self,$data ) = @_;
 #      $self->file_set($data);
-#      $self->usage_incr($data);
 }
 
 sub remove_file {
        my ( $self, $data ) = @_;
-#      $self->usage_decr( $data );
 
        my $md5sum = $self->md5sum($data);
        my $md5 = $md5sum->{ $data->{file} } || return; # directories don't have md5sums
@@ -202,7 +234,7 @@ sub rsync_transfer {
                my $type = $1;
 
                if ( $type eq 'f' ) {
-                       $self->modify_file( $data );
+                       $self->modify_file( $data ) && # selective dedup
                        $self->dedup( $data, $path );
                } elsif ( $type eq 'd' ) {
                        $self->make_dir( $data );
diff --git a/test.sh b/test.sh
index c6b2e04..8677ce6 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -28,9 +28,10 @@ rm -Rf "$dir"
 mkdir /tmp/test
 cd $dir
 
-if true ; then # skip tests if false
-
 push . --recursive --delete -v
+
+if false ; then # skip tests if false
+
 ps ax > foo
 push foo -v
 push foo -v
@@ -72,8 +73,6 @@ md5sum clone/* | sed -e 's!  !  _import/foo/bar/baz!' > md5sum
 cat md5sum
 push md5sum -v
 
-fi # skip tests
-
 # test unused md5 pool quota
 
 ps ax > tmp
@@ -81,14 +80,23 @@ push tmp -v
 rm tmp
 push . -r --delete -v
 
-exit
+fi # skip tests
 
 # test send
 
-ps ax >> sent-to-$RSYNC_LOGIN2
-push sent-to-$RSYNC_LOGIN2 # must be done before first send
+ps ax >> send
+mkdir dir1
+ps ax >> dir1/send
+mkdir dir2
+ps ax >> dir2/send
+
+mkdir -p .sync/send
+cat << __SEND__ > .sync/send/timestamp
+$RSYNC_LOGIN2 send
+$RSYNC_LOGIN2 dir1/send
+$RSYNC_LOGIN2 dir2/send
+__SEND__
 
-mkdir -p .send/$RSYNC_LOGIN2/received
-ln -s ../../../sent-to-$RSYNC_LOGIN2 .send/$RSYNC_LOGIN2/received/new-name
+# order is important! .sync must be last!
+push send dir1 dir2 .sync -rv
 
-push .send -rvl