[patch] paranoid checksum checking

Nick Burrett nick at sqrt.co.uk
Tue Jul 26 17:19:08 GMT 2005


The attached patch provides an additional check for the checksumming 
mode to ensure that a file that is actually written out to disk can be 
read back and has the same MD4 sum as the file on at the originating 
location.

Regards,


Nick.
-------------- next part --------------
*** rsync-2.6.6pre1/receiver.c	2005-04-14 02:42:13.000000000 +0100
--- rsync-new/receiver.c	2005-07-26 18:06:56.000000000 +0100
*************** extern int module_id;
*** 46,51 ****
--- 46,52 ----
  extern int ignore_errors;
  extern int orig_umask;
  extern int keep_partial;
+ extern int always_checksum;
  extern int checksum_seed;
  extern int inplace;
  extern int delay_updates;
*************** int recv_files(int f_in, struct file_lis
*** 649,654 ****
--- 650,669 ----
  			exit_cleanup(RERR_FILEIO);
  		}
  
+                 /* Check that the file written to local disk has the same
+                    checksum as the file in the originating location.  This
+                    is a further paranoia check, just to make sure that
+                    we really have successfully transferred the file.  */
+                 if (recv_ok && ! am_server && always_checksum) {
+                         char csum[MD4_SUM_LENGTH + 1];
+                         file_checksum (fnametmp, csum, file->length);
+                         if (memcmp(csum, file->u.sum, MD4_SUM_LENGTH) != 0) {
+                                 rprintf (FERROR, "%s checksum does not match remote checksum\n",
+                                          full_fname (fnametmp));
+                                 recv_ok = 0;
+                         }
+                 }
+ 
  		if ((recv_ok && (!delay_updates || !partialptr)) || inplace) {
  			finish_transfer(fname, fnametmp, file, recv_ok, 1);
  			if (partialptr != fname && fnamecmp == partialptr) {


More information about the rsync mailing list