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.
13 @@ -31,6 +31,7 @@ extern int am_daemon;
15 extern int do_progress;
16 extern int always_checksum;
17 +extern int pre_checksum;
19 extern int ignore_errors;
20 extern int numeric_ids;
21 @@ -701,6 +702,16 @@ static struct file_struct *receive_file_
24 read_buf(f, sum, checksum_len);
26 + char sum2[MD4_SUM_LENGTH];
28 + char *fname = f_name(file, NULL);
29 + if (stat(fname, &st) == 0 && st.st_size == file_length) {
30 + file_checksum(fname, sum2, st.st_size);
31 + if (memcmp(sum, sum2, checksum_len) != 0)
32 + file->flags |= FLAG_SUM_DIFFERS;
40 @@ -71,6 +71,7 @@ extern int ignore_timeout;
41 extern int protocol_version;
42 extern int fuzzy_basis;
43 extern int always_checksum;
44 +extern int pre_checksum;
45 extern int checksum_len;
46 extern char *partial_dir;
47 extern char *basis_dir[];
48 @@ -374,7 +375,8 @@ void itemize(struct file_struct *file, i
51 /* Perform our quick-check heuristic for determining if a file is unchanged. */
52 -int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
53 +int unchanged_file(char *fn, int fnamecmp_type, struct file_struct *file,
56 if (st->st_size != file->length)
58 @@ -383,6 +385,8 @@ int unchanged_file(char *fn, struct file
59 of the file time to determine whether to sync */
60 if (always_checksum && S_ISREG(st->st_mode)) {
61 char sum[MD4_SUM_LENGTH];
62 + if (pre_checksum && fnamecmp_type == FNAMECMP_FNAME)
63 + return !(file->flags & FLAG_SUM_DIFFERS);
64 file_checksum(fn, sum, st->st_size);
65 return memcmp(sum, file->u.sum, checksum_len) == 0;
67 @@ -620,7 +624,7 @@ static int try_dests_reg(struct file_str
71 - if (!unchanged_file(cmpbuf, file, stp))
72 + if (!unchanged_file(cmpbuf, 0, file, stp))
76 @@ -1182,7 +1186,7 @@ static void recv_generator(char *fname,
78 else if (fnamecmp_type == FNAMECMP_FUZZY)
80 - else if (unchanged_file(fnamecmp, file, &st)) {
81 + else if (unchanged_file(fnamecmp, fnamecmp_type, file, &st)) {
83 do_unlink(partialptr);
84 handle_partial_dir(partialptr, PDIR_DELETE);
87 @@ -212,7 +212,7 @@ int hard_link_check(struct file_struct *
91 - if (!unchanged_file(cmpbuf, file, &st3))
92 + if (!unchanged_file(cmpbuf, 0, file, &st3))
98 @@ -47,6 +47,7 @@ extern int copy_dirlinks;
99 extern int keep_dirlinks;
100 extern int preserve_hard_links;
101 extern int protocol_version;
102 +extern int always_checksum;
104 extern int relative_paths;
105 extern int sanitize_paths;
106 @@ -68,6 +69,7 @@ extern char *batch_name;
108 extern char curr_dir[MAXPATHLEN];
110 +int pre_checksum = 0;
111 int local_server = 0;
112 mode_t orig_umask = 0;
113 struct file_list *the_file_list;
114 @@ -736,6 +738,7 @@ static void do_server_recv(int f_in, int
115 struct file_list *flist;
116 char *local_name = NULL;
118 + char olddir[sizeof curr_dir];
119 int save_verbose = verbose;
121 if (filesfrom_fd >= 0) {
122 @@ -779,6 +782,10 @@ static void do_server_recv(int f_in, int
126 + strlcpy(olddir, curr_dir, sizeof olddir);
127 + if (always_checksum && !local_server && argc > 0)
128 + pre_checksum = push_dir(argv[0]);
130 flist = recv_file_list(f_in);
131 verbose = save_verbose;
133 @@ -787,6 +794,9 @@ static void do_server_recv(int f_in, int
135 the_file_list = flist;
141 local_name = get_local_name(flist,argv[0]);
143 @@ -848,6 +858,7 @@ int client_run(int f_in, int f_out, pid_
145 struct file_list *flist = NULL;
146 int exit_code = 0, exit_code2 = 0;
147 + char olddir[sizeof curr_dir];
148 char *local_name = NULL;
150 cleanup_child_pid = pid;
151 @@ -922,11 +933,18 @@ int client_run(int f_in, int f_out, pid_
155 + strlcpy(olddir, curr_dir, sizeof olddir);
156 + if (always_checksum && !local_server)
157 + pre_checksum = push_dir(argv[0]);
159 if (write_batch && !am_server)
160 start_write_batch(f_in);
161 flist = recv_file_list(f_in);
162 the_file_list = flist;
167 if (flist && flist->count > 0) {
168 local_name = get_local_name(flist, argv[0]);
173 #define FLAG_DEL_HERE (1<<3) /* receiver/generator */
174 #define FLAG_HLINK_TOL (1<<4) /* receiver/generator */
175 #define FLAG_NO_FUZZY (1<<5) /* generator */
176 +#define FLAG_SUM_DIFFERS (1<<6) /* receiver/generator */
178 /* update this if you make incompatible changes */
179 #define PROTOCOL_VERSION 29