1 This patch changes the way the --checksum option works by having the
2 receiving side perform a checksum-read of every file in the file list
3 as the list is received (if the sizes are equal), marking non-matching
4 items with a flag. The idea is that the checksum pass on the sender and
5 the receiver can then happen in parallel instead of having the reciever
6 to its checksum pass during its normal find-the-different-files pass.
8 I have benchmarked this a little, and it appears to slow things down
9 for a local copy, so the old algorithm is used for local copies.
11 To use this patch, run these commands for a successful build:
13 patch -p1 <patches/early-checksum.diff
14 ./configure (optional if already run)
19 @@ -31,6 +31,7 @@ extern int am_daemon;
21 extern int do_progress;
22 extern int always_checksum;
23 +extern int pre_checksum;
25 extern int ignore_errors;
26 extern int numeric_ids;
27 @@ -697,6 +698,16 @@ static struct file_struct *receive_file_
30 read_buf(f, sum, checksum_len);
32 + char sum2[MD4_SUM_LENGTH];
34 + char *fname = f_name(file, NULL);
35 + if (stat(fname, &st) == 0 && st.st_size == file_length) {
36 + file_checksum(fname, sum2, st.st_size);
37 + if (memcmp(sum, sum2, checksum_len) != 0)
38 + file->flags |= FLAG_SUM_DIFFERS;
46 @@ -70,6 +70,7 @@ extern int ignore_timeout;
47 extern int protocol_version;
48 extern int fuzzy_basis;
49 extern int always_checksum;
50 +extern int pre_checksum;
51 extern int checksum_len;
52 extern char *partial_dir;
53 extern char *basis_dir[];
54 @@ -376,7 +377,8 @@ void itemize(struct file_struct *file, i
57 /* Perform our quick-check heuristic for determining if a file is unchanged. */
58 -int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
59 +int unchanged_file(char *fn, int fnamecmp_type, struct file_struct *file,
62 if (st->st_size != file->length)
64 @@ -385,6 +387,8 @@ int unchanged_file(char *fn, struct file
65 of the file time to determine whether to sync */
66 if (always_checksum && S_ISREG(st->st_mode)) {
67 char sum[MD4_SUM_LENGTH];
68 + if (pre_checksum && fnamecmp_type == FNAMECMP_FNAME)
69 + return !(file->flags & FLAG_SUM_DIFFERS);
70 file_checksum(fn, sum, st->st_size);
71 return memcmp(sum, file->u.sum, checksum_len) == 0;
73 @@ -622,7 +626,7 @@ static int try_dests_reg(struct file_str
77 - if (!unchanged_file(cmpbuf, file, stp))
78 + if (!unchanged_file(cmpbuf, 0, file, stp))
82 @@ -1215,7 +1219,7 @@ static void recv_generator(char *fname,
84 else if (fnamecmp_type == FNAMECMP_FUZZY)
86 - else if (unchanged_file(fnamecmp, file, &st)) {
87 + else if (unchanged_file(fnamecmp, fnamecmp_type, file, &st)) {
89 do_unlink(partialptr);
90 handle_partial_dir(partialptr, PDIR_DELETE);
93 @@ -224,7 +224,7 @@ int hard_link_check(struct file_struct *
97 - if (!unchanged_file(cmpbuf, file, &st3))
98 + if (!unchanged_file(cmpbuf, 0, file, &st3))
104 @@ -47,6 +47,7 @@ extern int copy_dirlinks;
105 extern int keep_dirlinks;
106 extern int preserve_hard_links;
107 extern int protocol_version;
108 +extern int always_checksum;
110 extern int relative_paths;
111 extern int sanitize_paths;
112 @@ -71,6 +72,9 @@ extern char *batch_name;
113 extern char curr_dir[MAXPATHLEN];
114 extern struct filter_list_struct server_filter_list;
116 +extern char curr_dir[MAXPATHLEN];
118 +int pre_checksum = 0;
119 int local_server = 0;
120 int new_root_dir = 0;
121 mode_t orig_umask = 0;
122 @@ -784,6 +788,7 @@ static void do_server_recv(int f_in, int
123 struct file_list *flist;
124 char *local_name = NULL;
126 + char olddir[sizeof curr_dir];
127 int save_verbose = verbose;
129 if (filesfrom_fd >= 0) {
130 @@ -827,6 +832,10 @@ static void do_server_recv(int f_in, int
134 + strlcpy(olddir, curr_dir, sizeof olddir);
135 + if (always_checksum && !local_server && argc > 0)
136 + pre_checksum = push_dir(argv[0], 0);
138 flist = recv_file_list(f_in);
139 verbose = save_verbose;
141 @@ -835,6 +844,9 @@ static void do_server_recv(int f_in, int
143 the_file_list = flist;
149 local_name = get_local_name(flist,argv[0]);
151 @@ -916,6 +928,7 @@ int client_run(int f_in, int f_out, pid_
153 struct file_list *flist = NULL;
154 int exit_code = 0, exit_code2 = 0;
155 + char olddir[sizeof curr_dir];
156 char *local_name = NULL;
158 cleanup_child_pid = pid;
159 @@ -990,11 +1003,18 @@ int client_run(int f_in, int f_out, pid_
163 + strlcpy(olddir, curr_dir, sizeof olddir);
164 + if (always_checksum && !local_server)
165 + pre_checksum = push_dir(argv[0], 0);
167 if (write_batch && !am_server)
168 start_write_batch(f_in);
169 flist = recv_file_list(f_in);
170 the_file_list = flist;
175 if (flist && flist->count > 0) {
176 local_name = get_local_name(flist, argv[0]);
181 #define FLAG_HLINK_TOL (1<<4) /* receiver/generator */
182 #define FLAG_NO_FUZZY (1<<5) /* generator */
183 #define FLAG_MISSING (1<<6) /* generator */
184 +#define FLAG_SUM_DIFFERS (1<<7) /* receiver/generator */
186 /* update this if you make incompatible changes */
187 #define PROTOCOL_VERSION 29