The patches for 3.1.1pre1.
[rsync-patches.git] / checksum-xattr.diff
index 1f8d6bc3854e1a8bd92b4130b94099a036501527..0fef5523b4a1af439d82561d28c817361680fce8 100644 (file)
@@ -8,11 +8,11 @@ To use this patch, run these commands for a successful build:
     ./configure                               (optional if already run)
     make
 
-based-on: 181c9faf928faad08ef095f4667afe460ec3bef6
+based-on: 8946cfc6f8018e30740ee1db4cc2e2008e4f7e7e
 diff --git a/flist.c b/flist.c
 --- a/flist.c
 +++ b/flist.c
-@@ -1277,7 +1277,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
+@@ -1303,7 +1303,8 @@ struct file_struct *make_file(const char *fname, struct file_list *flist,
  #endif
  
        if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
@@ -25,7 +25,7 @@ diff --git a/flist.c b/flist.c
 diff --git a/generator.c b/generator.c
 --- a/generator.c
 +++ b/generator.c
-@@ -531,7 +531,8 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
+@@ -572,7 +572,8 @@ int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
           of the file time to determine whether to sync */
        if (always_checksum > 0 && S_ISREG(st->st_mode)) {
                char sum[MAX_DIGEST_LEN];
@@ -36,10 +36,10 @@ diff --git a/generator.c b/generator.c
        }
  
 diff --git a/support/xsums b/support/xsums
-new file mode 100644
+new file mode 100755
 --- /dev/null
 +++ b/support/xsums
-@@ -0,0 +1,118 @@
+@@ -0,0 +1,204 @@
 +#!/usr/bin/perl -w
 +use strict;
 +
@@ -49,15 +49,15 @@ new file mode 100644
 +use Digest::MD5;
 +use File::ExtAttr ':all';
 +
-+our($recurse_opt, $help_opt);
-+our $verbosity = 0;
-+
 +&Getopt::Long::Configure('bundling');
 +&usage if !&GetOptions(
-+    'recurse|r' => \$recurse_opt,
-+    'verbose|v+' => \$verbosity,
-+    'help|h' => \$help_opt,
-+) || $help_opt;
++    'recurse|r' => \( my $recurse_opt ),
++    'list|l' => \( my $list_opt ),
++    'check|c' => \( my $check_opt ),
++    'verbose|v+' => \( my $verbosity = 0 ),
++    'help|h' => \( my $help_opt ),
++);
++&usage if $help_opt;
 +
 +my $start_dir = cwd();
 +
@@ -69,6 +69,8 @@ new file mode 100644
 +
 +$| = 1;
 +
++my $exit_code = 0;
++
 +my $md4 = Digest::MD4->new;
 +my $md5 = Digest::MD5->new;
 +
@@ -84,13 +86,13 @@ new file mode 100644
 +      next;
 +    }
 +
-+    if ($verbosity) {
-+      my $reldir = $dir;
-+      $reldir =~ s#^$start_dir(/|$)# $1 ? '' : '.' #eo;
-+      print "scanning $reldir\n";
-+    }
++    my $reldir = $dir;
++    $reldir =~ s#^$start_dir(/|$)# $1 ? '' : '.' #eo;
++    print "$reldir ... " if $verbosity;
 +
 +    my @subdirs;
++    my $d_cnt = 0;
++    my $need_newline = $verbosity;
 +    while (defined(my $fn = readdir(DP))) {
 +      next if $fn =~ /^\.\.?$/ || -l $fn;
 +      if (-d _) {
@@ -98,13 +100,15 @@ new file mode 100644
 +          next;
 +      }
 +      next unless -f _;
++      $d_cnt++;
 +
-+      my($size,$mtime) = (stat(_))[7,9];
++      my($size,$mtime,$ctime) = (stat(_))[7,9,10];
 +
-+      my $sum4 = getfattr($fn, 'rsync.%md4');
-+      my $sum5 = getfattr($fn, 'rsync.%md5');
++      my $xsum4 = getfattr($fn, 'rsync.%md4');
++      my $xsum5 = getfattr($fn, 'rsync.%md5');
 +
-+      foreach ($sum4, $sum5) {
++      my $sum_count = 0;
++      foreach ($xsum4, $xsum5) {
 +          if (defined $_) {
 +              if (length($_) == 24) {
 +                  my($sz,$mt,$sum) = unpack('V2a16', $_);
@@ -113,28 +117,98 @@ new file mode 100644
 +                      $_ = undef;
 +                  } else {
 +                      $_ = $sum;
++                      $sum_count++;
 +                  }
 +              } else {
 +                  $_ = undef;
 +              }
 +          }
 +      }
-+      if (!defined($sum4) || !defined($sum5)) {
-+          if (!open(IN, $fn)) {
-+              print STDERR "Unable to read $fn: $!\n";
++
++      if ($list_opt) {
++          if ($need_newline) {
++              print "\n";
++              $need_newline = 0;
++          }
++          if (defined $xsum4) {
++              print ' ', unpack('H32', $xsum4);
++          } else {
++              print ' ' x (1 + 32);
++          }
++          if (defined $xsum5) {
++              print ' ', unpack('H32', $xsum5);
++          } else {
++              print ' ' x (1 + 32);
++          }
++          print $verbosity ? ' ' : " $reldir/";
++          print $fn, "\n";
++          next;
++      }
++
++      if ($check_opt) {
++          if (!$sum_count) {
++              if ($need_newline) {
++                  print "\n";
++                  $need_newline = 0;
++              }
++              print ' ' x (1 + 32 + 1 + 32) if $verbosity > 2;
++              print $verbosity ? ' ' : "$reldir/";
++              print $fn, " MISSING\n";
 +              next;
 +          }
++      } else {
++          next if $sum_count == 2;
++          print 'UPDATING' if $need_newline && $verbosity == 1;
++      }
++
++      if ($need_newline && (!$check_opt || $verbosity > 1)) {
++          print "\n";
++          $need_newline = 0;
++      }
 +
++      if (!open(IN, $fn)) {
++          print STDERR "Unable to read $fn: $!\n";
++          next;
++      }
++
++      my($sum4, $sum5);
++      while (1) {
 +          while (sysread(IN, $_, 64*1024)) {
 +              $md4->add($_);
 +              $md5->add($_);
 +          }
-+          close IN;
-+
 +          $sum4 = $md4->digest;
 +          $sum5 = $md5->digest;
-+          print " $fn\n" if $verbosity > 1;
++          print ' ', unpack('H32', $sum4), ' ', unpack('H32', $sum5) if $verbosity > 2;
++          print " $fn" if $verbosity > 1;
++          my($size2,$mtime2,$ctime2) = (stat(IN))[7,9,10];
++          last if $size == $size2 && $mtime == $mtime2 && $ctime == $ctime2;
++          $size = $size2;
++          $mtime = $mtime2;
++          $ctime = $ctime2;
++          sysseek(IN, 0, 0);
++          print " REREADING\n" if $verbosity > 1;
++      }
++
++      close IN;
 +
++      if ($check_opt) {
++          if ((!defined $xsum4 || $xsum4 eq $sum4) && (!defined $xsum5 || $xsum5 eq $sum5)) {
++              print " OK\n" if $verbosity > 1;
++              next;
++          }
++          if ($need_newline) {
++              print "\n";
++              $need_newline = 0;
++          }
++          if ($verbosity < 2) {
++              print $verbosity ? ' ' : "$reldir/";
++              print $fn;
++          }
++          print " FAILED\n";
++          $exit_code = 1;
++      } else {
++          print "\n" if $verbosity > 1;
 +          my $szmt = pack('V2', $size, $mtime); # 32-bits, may truncate
 +          setfattr($fn, 'rsync.%md4', $szmt.$sum4);
 +          setfattr($fn, 'rsync.%md5', $szmt.$sum5);
@@ -142,11 +216,21 @@ new file mode 100644
 +      }
 +    }
 +
++    if ($need_newline) {
++      if ($d_cnt) {
++          print "ok\n";
++      } else {
++          print "empty\n";
++      }
++    }
++
 +    closedir DP;
 +
 +    unshift(@dirs, sort @subdirs) if $recurse_opt;
 +}
 +
++exit $exit_code;
++
 +sub usage
 +{
 +    die <<EOT;
@@ -154,6 +238,8 @@ new file mode 100644
 +
 +Options:
 + -r, --recurse     Update checksums in subdirectories too.
++ -l, --list        List the checksums for each file (doesn't update).
++ -c, --check       Check if the checksums are right (doesn't update).
 + -v, --verbose     Mention what we're doing.  Repeat for more info.
 + -h, --help        Display this help message.
 +EOT
@@ -161,16 +247,16 @@ new file mode 100644
 diff --git a/xattrs.c b/xattrs.c
 --- a/xattrs.c
 +++ b/xattrs.c
-@@ -34,6 +34,8 @@ extern int read_only;
- extern int list_only;
- extern int preserve_xattrs;
+@@ -37,6 +37,8 @@ extern int preserve_links;
+ extern int preserve_devices;
+ extern int preserve_specials;
  extern int checksum_seed;
 +extern int checksum_len;
 +extern int protocol_version;
  
  #define RSYNC_XAL_INITIAL 5
  #define RSYNC_XAL_LIST_INITIAL 100
-@@ -69,6 +71,10 @@ extern int checksum_seed;
+@@ -72,6 +74,10 @@ extern int checksum_seed;
  #define XACC_ACL_ATTR RSYNC_PREFIX "%" XACC_ACL_SUFFIX
  #define XDEF_ACL_SUFFIX "dacl"
  #define XDEF_ACL_ATTR RSYNC_PREFIX "%" XDEF_ACL_SUFFIX
@@ -181,7 +267,7 @@ diff --git a/xattrs.c b/xattrs.c
  
  typedef struct {
        char *datum, *name;
-@@ -241,7 +247,9 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
+@@ -247,7 +253,9 @@ static int rsync_xal_get(const char *fname, item_list *xalp)
                         || (am_root < 0
                          && (strcmp(name+RPRE_LEN+1, XSTAT_SUFFIX) == 0
                           || strcmp(name+RPRE_LEN+1, XACC_ACL_SUFFIX) == 0
@@ -192,7 +278,7 @@ diff --git a/xattrs.c b/xattrs.c
                                continue;
                }
  
-@@ -914,6 +922,39 @@ int del_def_xattr_acl(const char *fname)
+@@ -958,6 +966,39 @@ int del_def_xattr_acl(const char *fname)
  }
  #endif