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 @@ -785,6 +786,15 @@ static struct file_struct *recv_file_ent
28 memcpy(bp, F_SUM(first), checksum_len);
30 read_buf(f, bp, checksum_len);
31 + if (pre_checksum && sum_len) {
33 + char *fname = f_name(file, NULL);
34 + if (stat(fname, &st) == 0 && st.st_size == file_length) {
35 + file_checksum(fname, tmp_sum, st.st_size);
36 + if (memcmp(bp, tmp_sum, checksum_len) != 0)
37 + file->flags |= FLAG_SUM_DIFFERS;
45 @@ -70,6 +70,7 @@ extern int ignore_timeout;
46 extern int protocol_version;
47 extern int fuzzy_basis;
48 extern int always_checksum;
49 +extern int pre_checksum;
50 extern int checksum_len;
51 extern char *partial_dir;
52 extern char *basis_dir[];
53 @@ -577,7 +578,8 @@ void itemize(struct file_struct *file, i
56 /* Perform our quick-check heuristic for determining if a file is unchanged. */
57 -int unchanged_file(char *fn, struct file_struct *file, STRUCT_STAT *st)
58 +int unchanged_file(char *fn, int fnamecmp_type, struct file_struct *file,
61 if (st->st_size != F_LENGTH(file))
63 @@ -586,6 +588,8 @@ int unchanged_file(char *fn, struct file
64 of the file time to determine whether to sync */
65 if (always_checksum && S_ISREG(st->st_mode)) {
66 char sum[MD4_SUM_LENGTH];
67 + if (pre_checksum && fnamecmp_type == FNAMECMP_FNAME)
68 + return !(file->flags & FLAG_SUM_DIFFERS);
69 file_checksum(fn, sum, st->st_size);
70 return memcmp(sum, F_SUM(file), checksum_len) == 0;
72 @@ -825,7 +829,7 @@ static int try_dests_reg(struct file_str
76 - if (!unchanged_file(cmpbuf, file, stp))
77 + if (!unchanged_file(cmpbuf, 0, file, stp))
81 @@ -1511,7 +1515,7 @@ static void recv_generator(char *fname,
83 else if (fnamecmp_type == FNAMECMP_FUZZY)
85 - else if (unchanged_file(fnamecmp, file, &st)) {
86 + else if (unchanged_file(fnamecmp, fnamecmp_type, file, &st)) {
88 do_unlink(partialptr);
89 handle_partial_dir(partialptr, PDIR_DELETE);
92 @@ -448,7 +448,7 @@ int hard_link_check(struct file_struct *
96 - if (!unchanged_file(cmpbuf, file, &alt_st))
97 + if (!unchanged_file(cmpbuf, 0, file, &alt_st))
103 @@ -47,6 +47,7 @@ extern int copy_dirlinks;
104 extern int keep_dirlinks;
105 extern int preserve_hard_links;
106 extern int protocol_version;
107 +extern int always_checksum;
109 extern int relative_paths;
110 extern int sanitize_paths;
111 @@ -71,6 +72,9 @@ extern char *batch_name;
112 extern char curr_dir[MAXPATHLEN];
113 extern struct filter_list_struct server_filter_list;
115 +extern char curr_dir[MAXPATHLEN];
117 +int pre_checksum = 0;
118 int local_server = 0;
119 int new_root_dir = 0;
120 mode_t orig_umask = 0;
121 @@ -788,6 +792,7 @@ static void do_server_recv(int f_in, int
122 struct file_list *flist;
123 char *local_name = NULL;
125 + char olddir[sizeof curr_dir];
126 int save_verbose = verbose;
128 if (filesfrom_fd >= 0) {
129 @@ -831,6 +836,10 @@ static void do_server_recv(int f_in, int
133 + strlcpy(olddir, curr_dir, sizeof olddir);
134 + if (always_checksum && !local_server && argc > 0)
135 + pre_checksum = push_dir(argv[0], 0);
137 flist = recv_file_list(f_in);
138 verbose = save_verbose;
140 @@ -839,6 +848,9 @@ static void do_server_recv(int f_in, int
142 the_file_list = flist;
148 local_name = get_local_name(flist,argv[0]);
150 @@ -918,6 +930,7 @@ int client_run(int f_in, int f_out, pid_
152 struct file_list *flist = NULL;
153 int exit_code = 0, exit_code2 = 0;
154 + char olddir[sizeof curr_dir];
155 char *local_name = NULL;
157 cleanup_child_pid = pid;
158 @@ -992,11 +1005,18 @@ int client_run(int f_in, int f_out, pid_
162 + strlcpy(olddir, curr_dir, sizeof olddir);
163 + if (always_checksum && !local_server)
164 + pre_checksum = push_dir(argv[0], 0);
166 if (write_batch && !am_server)
167 start_write_batch(f_in);
168 flist = recv_file_list(f_in);
169 the_file_list = flist;
174 if (flist && flist->count > 0) {
175 local_name = get_local_name(flist, argv[0]);
180 #define FLAG_HLINK_LAST (1<<7) /* receiver/generator */
181 #define FLAG_HLINK_DONE (1<<8) /* receiver/generator */
182 #define FLAG_LENGTH64 (1<<9) /* sender/receiver/generator */
183 +#define FLAG_SUM_DIFFERS (1<<10)/* receiver/generator */
185 #define BITS_SET(val,bits) (((val) & (bits)) == (bits))
186 #define BITS_SETnUNSET(val,onbits,offbits) (((val) & ((onbits)|(offbits))) == (onbits))