1 From: Rusty Russell <rusty@rustcorp.com.au>
2 Date: Wed, 03 Apr 2002 17:08:57 +1000
4 Found old patch on google, and updated it for 2.5.4 (I know, but that's what
5 apt-get source gave me).
7 Compiles, otherwise untested.
10 [Updated for current CVS version by Wayne Davison. Passes *MOST* of the
11 test suite, but otherwise UNTESTED.]
13 Anyone who quotes me in their sig is an idiot. -- Rusty Russell.
15 --- Makefile.in 15 May 2004 00:48:11 -0000 1.101
16 +++ Makefile.in 15 May 2004 20:47:12 -0000
17 @@ -32,7 +32,7 @@ ZLIBOBJ=zlib/deflate.o zlib/infblock.o z
18 zlib/inflate.o zlib/inftrees.o zlib/infutil.o zlib/trees.o \
19 zlib/zutil.o zlib/adler32.o
20 OBJS1=rsync.o generator.o receiver.o cleanup.o sender.o exclude.o util.o \
21 - main.o checksum.o match.o syscall.o log.o backup.o
22 + main.o checksum.o match.o syscall.o log.o backup.o alternate.o
23 OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o \
24 fileio.o batch.o clientname.o
25 OBJS3=progress.o pipe.o
26 --- generator.c 15 May 2004 19:31:10 -0000 1.83
27 +++ generator.c 15 May 2004 20:47:12 -0000
28 @@ -51,6 +51,7 @@ extern int list_only;
29 extern int only_existing;
30 extern int orig_umask;
31 extern int safe_symlinks;
35 /* choose whether to skip a particular file */
36 @@ -256,7 +257,61 @@ static void generate_and_send_sums(struc
40 +/* Returns -1 for can't open (null file), -2 for skip */
41 +static int open_base_file(struct file_struct *file, char *fname, int statret,
47 + if (S_ISREG(st->st_mode)) {
49 + && cmp_modtime(st->st_mtime, file->modtime) > 0) {
51 + rprintf(FINFO, "%s is newer\n", fname);
54 + if (skip_file(fname, file, st)) {
55 + set_perms(fname, file, st, PERMS_REPORT);
58 + fd = do_open(fname, O_RDONLY, 0);
60 + rsyserr(FERROR, errno, "failed to open %s, continuing",
66 + /* Try to use symlink contents */
67 + if (S_ISLNK(st->st_mode)) {
68 + fd = do_open_regular(fname);
69 + /* Don't delete yet; receiver will need it */
71 + if (delete_file(fname) != 0) {
80 + if (fd == -1 && compare_dest != NULL)
81 + fd = open_alternate_base_comparedir(fname);
83 + if (fd == -1 && fuzzy)
84 + fd = open_alternate_base_fuzzy(fname);
86 + /* Update stat to understand size */
88 + if (do_fstat(fd, st) != 0) {
89 + rsyserr(FERROR, errno, "fstat %s", full_fname(fname));
97 * Acts on file number @p i from @p flist, whose name is @p fname.
98 @@ -272,8 +327,6 @@ void recv_generator(char *fname, struct
100 struct map_struct *mapbuf;
103 - char fnamecmpbuf[MAXPATHLEN];
107 @@ -400,107 +453,39 @@ void recv_generator(char *fname, struct
111 - if (preserve_hard_links && hard_link_check(file, HL_CHECK_MASTER))
114 - if (!S_ISREG(file->mode)) {
115 - rprintf(FINFO, "skipping non-regular file \"%s\"\n",fname);
121 - if (statret == -1 && compare_dest != NULL) {
122 - /* try the file at compare_dest instead */
123 - int saveerrno = errno;
124 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf, compare_dest, fname);
125 - statret = link_stat(fnamecmpbuf,&st);
126 - if (!S_ISREG(st.st_mode))
131 - else if (link_dest && !dry_run) {
132 - if (do_link(fnamecmpbuf, fname) != 0) {
134 - rsyserr(FINFO, errno, "link %s => %s",
135 - fnamecmpbuf, fname);
138 - fnamecmp = fnamecmpbuf;
142 - fnamecmp = fnamecmpbuf;
145 - if (statret == -1) {
146 - if (preserve_hard_links && hard_link_check(file, HL_SKIP))
148 - if (errno == ENOENT) {
149 - write_int(f_out,i);
150 - if (!dry_run) write_sum_head(f_out, NULL);
151 - } else if (verbose > 1) {
152 + /* Failed to stat for some reason besides "not found". */
153 + if (statret == -1 && errno != ENOENT) {
155 rsyserr(FERROR, errno,
156 - "recv_generator: failed to open %s",
157 + "recv_generator failed to stat %s",
163 - if (!S_ISREG(st.st_mode)) {
164 - if (delete_file(fname) != 0) {
168 - /* now pretend the file didn't exist */
169 - if (preserve_hard_links && hard_link_check(file, HL_SKIP))
171 - write_int(f_out,i);
172 - if (!dry_run) write_sum_head(f_out, NULL);
176 - if (opt_ignore_existing && fnamecmp == fname) {
178 - rprintf(FINFO,"%s exists\n",fname);
179 + if ((fd = open_base_file(file, fname, statret, &st)) == -2)
183 - if (update_only && cmp_modtime(st.st_mtime,file->modtime)>0 && fnamecmp == fname) {
185 - rprintf(FINFO,"%s is newer\n",fname);
187 + if ((disable_deltas_p() || dry_run) && fd != -1) {
192 - if (skip_file(fname, file, &st)) {
193 - if (fnamecmp == fname)
194 - set_perms(fname, file, &st, PERMS_REPORT);
199 - write_int(f_out,i);
203 - if (disable_deltas_p()) {
204 - write_int(f_out,i);
205 - write_sum_head(f_out, NULL);
209 - /* open the file */
210 - fd = do_open(fnamecmp, O_RDONLY, 0);
213 - rsyserr(FERROR, errno, "failed to open %s, continuing",
214 - full_fname(fnamecmp));
215 - /* pretend the file didn't exist */
216 + /* the file didn't exist, or we can pretend it doesn't */
217 if (preserve_hard_links && hard_link_check(file, HL_SKIP))
219 - write_int(f_out,i);
220 - write_sum_head(f_out, NULL);
221 + write_int(f_out, i);
223 + write_sum_head(f_out, NULL);
227 + if (preserve_hard_links && hard_link_check(file, HL_CHECK_MASTER))
230 + if (!S_ISREG(file->mode)) {
231 + rprintf(FINFO, "skipping non-regular file \"%s\"\n",fname);
235 @@ -510,7 +495,7 @@ void recv_generator(char *fname, struct
239 - rprintf(FINFO,"gen mapped %s of size %.0f\n", fnamecmp,
240 + rprintf(FINFO, "gen mapped %s of size %.0f\n", fname,
244 --- options.c 6 May 2004 21:08:01 -0000 1.148
245 +++ options.c 15 May 2004 20:47:13 -0000
246 @@ -91,6 +91,7 @@ int ignore_errors = 0;
247 int modify_window = 0;
248 int blocking_io = -1;
249 int checksum_seed = 0;
251 unsigned int block_size = 0;
254 @@ -290,6 +291,7 @@ void usage(enum logcode F)
255 rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
256 rprintf(F," --write-batch=PREFIX write batch fileset starting with PREFIX\n");
257 rprintf(F," --read-batch=PREFIX read batch fileset starting with PREFIX\n");
258 + rprintf(F," --fuzzy use similar file as basis if it does't exist\n");
260 rprintf(F," -4 --ipv4 prefer IPv4\n");
261 rprintf(F," -6 --ipv6 prefer IPv6\n");
262 @@ -385,6 +387,7 @@ static struct poptOption long_options[]
263 {"files-from", 0, POPT_ARG_STRING, &files_from, 0, 0, 0 },
264 {"from0", '0', POPT_ARG_NONE, &eol_nulls, 0, 0, 0},
265 {"no-implied-dirs", 0, POPT_ARG_VAL, &implied_dirs, 0, 0, 0 },
266 + {"fuzzy", 0, POPT_ARG_NONE, &fuzzy, 0, 0, 0 },
267 {"protocol", 0, POPT_ARG_INT, &protocol_version, 0, 0, 0 },
269 {"ipv4", '4', POPT_ARG_VAL, &default_af_hint, AF_INET, 0, 0 },
270 @@ -964,6 +967,9 @@ void server_options(char **args,int *arg
271 args[ac++] = "--from0";
275 + if (fuzzy && am_sender)
276 + args[ac++] = "--fuzzy";
280 --- receiver.c 15 May 2004 19:31:10 -0000 1.78
281 +++ receiver.c 15 May 2004 20:47:13 -0000
282 @@ -46,6 +46,7 @@ extern int module_id;
283 extern int ignore_errors;
284 extern int orig_umask;
285 extern int keep_partial;
288 static void delete_one(char *fn, int is_dir)
290 @@ -294,8 +295,6 @@ int recv_files(int f_in,struct file_list
291 char *fname, fbuf[MAXPATHLEN];
292 char template[MAXPATHLEN];
293 char fnametmp[MAXPATHLEN];
295 - char fnamecmpbuf[MAXPATHLEN];
296 struct map_struct *mapbuf;
298 struct file_struct *file;
299 @@ -358,35 +357,31 @@ int recv_files(int f_in,struct file_list
301 rprintf(FINFO,"recv_files(%s)\n",fname);
306 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
307 + fd1 = do_open(fname, O_RDONLY, 0);
309 - if (fd1 == -1 && compare_dest != NULL) {
310 - /* try the file at compare_dest instead */
311 - pathjoin(fnamecmpbuf, sizeof fnamecmpbuf,
312 - compare_dest, fname);
313 - fnamecmp = fnamecmpbuf;
314 - fd1 = do_open(fnamecmp, O_RDONLY, 0);
316 + if (fd1 == -1 && compare_dest != NULL)
317 + fd1 = open_alternate_base_comparedir(fname);
319 + if (fd1 == -1 && fuzzy)
320 + fd1 = open_alternate_base_fuzzy(fname);
322 if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
323 rsyserr(FERROR, errno, "fstat %s failed",
324 - full_fname(fnamecmp));
325 + full_fname(fname));
326 receive_data(f_in,NULL,-1,NULL,file->length);
331 - if (fd1 != -1 && S_ISDIR(st.st_mode) && fnamecmp == fname) {
332 + if (fd1 != -1 && S_ISDIR(st.st_mode)) {
333 /* this special handling for directories
334 * wouldn't be necessary if robust_rename()
335 * and the underlying robust_unlink could cope
338 rprintf(FERROR,"recv_files: %s is a directory\n",
339 - full_fname(fnamecmp));
340 + full_fname(fname));
341 receive_data(f_in, NULL, -1, NULL, file->length);
344 @@ -407,8 +402,10 @@ int recv_files(int f_in,struct file_list
346 if (fd1 != -1 && st.st_size > 0) {
347 mapbuf = map_file(fd1,st.st_size);
349 - rprintf(FINFO,"recv mapped %s of size %.0f\n",fnamecmp,(double)st.st_size);
351 + rprintf(FINFO, "recv mapped %s of size %.0f\n",
352 + fname, (double)st.st_size);