1 This adds a sender optimization feature that allows a cache of checksums
2 to be used when the client specifies the --checksum option, and creates
3 and/or updates the .rsyncsums files when --checksum-updating is
6 To use this patch, run these commands for a successful build:
8 patch -p1 <patches/checksum-updating.diff
9 ./configure (optional if already run)
12 TODO: when sending individual files (as opposed to an entire directory),
13 we should still update the .rsyncsums file if we compute a new checksum.
14 (The file is currently only written if we send an entire dir.)
16 --- old/clientserver.c
17 +++ new/clientserver.c
18 @@ -37,6 +37,7 @@ extern int sanitize_paths;
19 extern int filesfrom_fd;
20 extern int remote_protocol;
21 extern int protocol_version;
22 +extern int checksum_updating;
23 extern int io_timeout;
25 extern int default_af_hint;
26 @@ -634,6 +635,8 @@ static int rsync_module(int f_in, int f_
27 else if (am_root < 0) /* Treat --fake-super from client as --super. */
30 + checksum_updating = lp_checksum_updating(i);
32 if (filesfrom_fd == 0)
45 @@ -57,6 +58,7 @@ extern int implied_dirs;
46 extern int file_extra_cnt;
47 extern int ignore_perishable;
48 extern int non_perishable_cnt;
49 +extern int checksum_updating;
50 extern int prune_empty_dirs;
51 extern int copy_links;
52 extern int copy_unsafe_links;
53 @@ -79,6 +81,9 @@ extern iconv_t ic_send, ic_recv;
55 #define PTR_SIZE (sizeof (struct file_struct *))
57 +#define FLAG_SUM_MISSING (1<<1)
58 +#define FLAG_SUM_FOUND (1<<2)
62 dev_t filesystem_dev; /* used to implement -x */
63 @@ -101,6 +106,9 @@ static char tmp_sum[MAX_DIGEST_LEN];
64 static char empty_sum[MAX_DIGEST_LEN];
65 static int flist_count_offset; /* for --delete --progress */
66 static int dir_count = 0;
67 +static struct file_list *checksum_flist = NULL;
68 +static int checksum_matches = 0;
69 +static int regular_skipped = 0;
71 static void clean_flist(struct file_list *flist, int strip_root);
72 static void output_flist(struct file_list *flist);
73 @@ -317,6 +325,275 @@ static void flist_done_allocating(struct
74 flist->pool_boundary = ptr;
77 +/* The len count is the length of the basename + 1 for the null. */
78 +static void add_checksum(const char *dirname, const char *basename, int len,
79 + OFF_T file_length, time_t mtime, time_t ctime,
80 + const char *sum, const char *alt_sum, int flags)
82 + struct file_struct *file;
83 + int alloc_len, extra_len;
86 + if (len == 10+1 && *basename == '.' && strcmp(basename, ".rsyncsums") == 0)
90 + len = strlen(basename) + 1;
92 + extra_len = (file_extra_cnt + (file_length > 0xFFFFFFFFu)
93 + + SUM_EXTRA_CNT + TIME_EXTRA_CNT)
95 +#if EXTRA_ROUNDING > 0
96 + if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
97 + extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN;
99 + alloc_len = FILE_STRUCT_LEN + extra_len + len + checksum_len*2 + 1;
100 + bp = pool_alloc(checksum_flist->file_pool, alloc_len, "add_checksum");
102 + memset(bp, 0, extra_len + FILE_STRUCT_LEN);
104 + file = (struct file_struct *)bp;
105 + bp += FILE_STRUCT_LEN;
107 + memcpy(bp, basename, len);
109 + strlcpy(bp+len, alt_sum, checksum_len*2 + 1);
111 + memset(bp+len, '=', checksum_len*2);
112 + bp[len+checksum_len*2] = '\0';
115 + file->flags = flags;
116 + file->mode = S_IFREG;
117 + file->modtime = mtime;
118 + file->len32 = (uint32)file_length;
119 + if (file_length > 0xFFFFFFFFu) {
120 + file->flags |= FLAG_LENGTH64;
121 + OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32);
123 + file->dirname = dirname;
124 + bp = (char*)F_SUM(file);
125 + memcpy(bp, sum, checksum_len);
126 + memcpy(bp - SIZEOF_TIME_T, &ctime, SIZEOF_TIME_T);
128 + flist_expand(checksum_flist, 1);
129 + checksum_flist->files[checksum_flist->count++] = file;
131 + checksum_flist->sorted = checksum_flist->files;
134 +/* The direname value must remain unchanged during the lifespan of the
135 + * created checksum_flist object because we use it directly. */
136 +static void read_checksums(const char *dirname)
138 + char line[MAXPATHLEN+1024], fbuf[MAXPATHLEN], sum[MAX_DIGEST_LEN];
139 + const char *alt_sum = NULL;
141 + time_t mtime, ctime;
142 + int len, dlen, i, flags;
146 + if (checksum_flist) {
147 + /* Reset the pool memory and empty the file-list array. */
148 + pool_free_old(checksum_flist->file_pool,
149 + pool_boundary(checksum_flist->file_pool, 0));
150 + checksum_flist->count = 0;
152 + checksum_flist = flist_new(FLIST_TEMP, "read_checksums");
154 + checksum_flist->low = 0;
155 + checksum_flist->high = -1;
156 + checksum_matches = 0;
157 + regular_skipped = 0;
160 + dlen = strlcpy(fbuf, dirname, sizeof fbuf);
161 + if (dlen >= (int)sizeof fbuf)
163 + fbuf[dlen++] = '/';
166 + strlcpy(fbuf+dlen, ".rsyncsums", sizeof fbuf - dlen);
167 + if (!(fp = fopen(fbuf, "r")))
170 + while (fgets(line, sizeof line, fp)) {
172 + if (protocol_version >= 30) {
175 + while (*++cp == '=') {}
177 + while (isXDigit(cp)) cp++;
178 + if (cp - alt_sum != MD4_DIGEST_LEN*2 || *cp != ' ')
180 + while (*++cp == ' ') {}
184 + for (i = 0; i < checksum_len*2; i++, cp++) {
190 + memset(sum, 0, checksum_len);
191 + flags = FLAG_SUM_MISSING;
193 + for (i = 0; i < checksum_len*2; i++, cp++) {
195 + if (isXDigit(cp)) {
199 + x = (*cp & 0xF) + 9;
213 + while (*++cp == ' ') {}
215 + if (protocol_version < 30) {
218 + while (*++cp == '=') {}
220 + while (isXDigit(cp)) cp++;
221 + if (cp - alt_sum != MD5_DIGEST_LEN*2 || *cp != ' ')
223 + while (*++cp == ' ') {}
227 + while (isDigit(cp))
228 + file_length = file_length * 10 + *cp++ - '0';
231 + while (*++cp == ' ') {}
234 + while (isDigit(cp))
235 + mtime = mtime * 10 + *cp++ - '0';
238 + while (*++cp == ' ') {}
241 + while (isDigit(cp))
242 + ctime = ctime * 10 + *cp++ - '0';
245 + while (*++cp == ' ') {}
248 + while (len && (cp[len-1] == '\n' || cp[len-1] == '\r'))
252 + cp[len++] = '\0'; /* len now counts the null */
253 + if (strchr(cp, '/') || len > MAXPATHLEN)
256 + strlcpy(fbuf+dlen, cp, sizeof fbuf - dlen);
257 + if (is_excluded(fbuf, 0, ALL_FILTERS)) {
258 + flags |= FLAG_SUM_FOUND;
259 + checksum_matches++;
262 + add_checksum(dirname, cp, len, file_length, mtime, ctime,
263 + sum, alt_sum, flags);
267 + clean_flist(checksum_flist, 0);
270 +static void write_checksums(const char *dirname)
272 + char fbuf[MAXPATHLEN];
273 + int count = checksum_flist->count;
274 + int new_entries = count > checksum_flist->high + 1;
275 + int counts_match = count == checksum_matches;
276 + int no_skipped = regular_skipped == 0;
277 + time_t latest_time = 0;
281 + clean_flist(checksum_flist, 0);
283 + checksum_flist->count = 0;
284 + checksum_matches = 0;
285 + regular_skipped = 0;
291 + if (pathjoin(fbuf, sizeof fbuf, dirname, ".rsyncsums") >= sizeof fbuf)
294 + strlcpy(fbuf, ".rsyncsums", sizeof fbuf);
296 + if (checksum_flist->high - checksum_flist->low < 0 && no_skipped) {
301 + if (!new_entries && counts_match)
304 + if (!(out_fp = fopen(fbuf, "w")))
307 + for (i = checksum_flist->low; i <= checksum_flist->high; i++) {
308 + struct file_struct *file = checksum_flist->sorted[i];
309 + const char *cp = F_SUM(file);
310 + const char *end = cp + checksum_len;
312 + if (!(file->flags & FLAG_SUM_FOUND))
314 + memcpy(&ctime, cp - SIZEOF_TIME_T, SIZEOF_TIME_T);
315 + if (protocol_version >= 30) {
316 + fprintf(out_fp, "%s ",
317 + file->basename + strlen(file->basename) + 1);
319 + if (file->flags & FLAG_SUM_MISSING) {
321 + fprintf(out_fp, "==");
322 + } while (++cp != end);
325 + fprintf(out_fp, "%02x", CVAL(cp, 0));
326 + } while (++cp != end);
328 + if (protocol_version < 30) {
329 + fprintf(out_fp, " %s",
330 + file->basename + strlen(file->basename) + 1);
332 + fprintf(out_fp, " %10.0f %10ld %10ld %s\n",
333 + (double)F_LENGTH(file), (long)file->modtime,
334 + (long)ctime, file->basename);
335 + if (file->modtime > ctime)
336 + ctime = file->modtime;
337 + if (ctime > latest_time)
338 + latest_time = ctime;
343 + set_modtime(fbuf, latest_time, latest_time);
346 int push_pathname(const char *dir, int len)
349 @@ -973,34 +1250,24 @@ static struct file_struct *recv_file_ent
354 - * Create a file_struct for a named file by reading its stat()
355 - * information and performing extensive checks against global
358 - * @return the new file, or NULL if there was an error or this file
359 - * should be excluded.
360 +/* Create a file_struct for a named file by reading its stat() information
361 + * and performing extensive checks against global options.
363 - * @todo There is a small optimization opportunity here to avoid
364 - * stat()ing the file in some circumstances, which has a certain cost.
365 - * We are called immediately after doing readdir(), and so we may
366 - * already know the d_type of the file. We could for example avoid
367 - * statting directories if we're not recursing, but this is not a very
368 - * important case. Some systems may not have d_type.
370 + * Returns a pointer to the new file struct, or NULL if there was an error
371 + * or this file should be excluded. */
372 struct file_struct *make_file(const char *fname, struct file_list *flist,
373 STRUCT_STAT *stp, int flags, int filter_level)
375 static char *lastdir;
376 - static int lastdir_len = -1;
377 + static int lastdir_len = -2;
378 struct file_struct *file;
380 char thisname[MAXPATHLEN];
381 char linkname[MAXPATHLEN];
382 int alloc_len, basename_len, linkname_len;
383 int extra_len = file_extra_cnt * EXTRA_LEN;
384 const char *basename;
389 if (strlcpy(thisname, fname, sizeof thisname)
390 @@ -1077,6 +1344,8 @@ struct file_struct *make_file(const char
391 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
392 if (ignore_perishable)
393 non_perishable_cnt++;
394 + if (S_ISREG(st.st_mode))
399 @@ -1115,9 +1384,16 @@ struct file_struct *make_file(const char
400 memcpy(lastdir, thisname, len);
403 + if (always_checksum && am_sender && flist)
404 + read_checksums(lastdir);
409 + if (always_checksum && am_sender && flist && lastdir_len == -2) {
411 + read_checksums(NULL);
414 basename_len = strlen(basename) + 1; /* count the '\0' */
417 @@ -1193,11 +1469,40 @@ struct file_struct *make_file(const char
421 - if (always_checksum && am_sender && S_ISREG(st.st_mode))
422 - file_checksum(thisname, tmp_sum, st.st_size);
424 F_PATHNAME(file) = pathname;
426 + if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
428 + if (flist && (j = flist_find(checksum_flist, file)) >= 0) {
429 + struct file_struct *fp = checksum_flist->sorted[j];
431 + memcpy(&ctime, F_SUM(fp) - SIZEOF_TIME_T, SIZEOF_TIME_T);
432 + if (F_LENGTH(fp) == st.st_size
433 + && fp->modtime == st.st_mtime && ctime == st.st_ctime) {
434 + if (fp->flags & FLAG_SUM_MISSING) {
435 + fp->flags &= ~FLAG_SUM_MISSING;
436 + file_checksum(thisname, tmp_sum, st.st_size);
437 + memcpy((char*)F_SUM(fp), tmp_sum, MAX_DIGEST_LEN);
439 + checksum_matches++;
440 + memcpy(tmp_sum, F_SUM(fp), MAX_DIGEST_LEN);
442 + fp->flags |= FLAG_SUM_FOUND;
445 + goto compute_checksum;
449 + file_checksum(thisname, tmp_sum, st.st_size);
450 + if (checksum_updating && flist) {
451 + add_checksum(file->dirname, basename, basename_len,
452 + st.st_size, st.st_mtime, st.st_ctime,
453 + tmp_sum, NULL, FLAG_SUM_FOUND);
458 /* This code is only used by the receiver when it is building
459 * a list of files for a delete pass. */
460 if (keep_dirlinks && linkname_len && flist) {
461 @@ -1241,14 +1546,14 @@ void unmake_file(struct file_struct *fil
463 static struct file_struct *send_file_name(int f, struct file_list *flist,
464 char *fname, STRUCT_STAT *stp,
465 - int flags, int filter_flags)
466 + int flags, int filter_level)
468 struct file_struct *file;
469 #if defined SUPPORT_ACLS || defined SUPPORT_XATTRS
473 - file = make_file(fname, flist, stp, flags, filter_flags);
474 + file = make_file(fname, flist, stp, flags, filter_level);
478 @@ -1442,7 +1747,7 @@ static void send_directory(int f, struct
480 int divert_dirs = (flags & FLAG_DIVERT_DIRS) != 0;
481 int start = flist->count;
482 - int filter_flags = f == -2 ? SERVER_FILTERS : ALL_FILTERS;
483 + int filter_level = f == -2 ? SERVER_FILTERS : ALL_FILTERS;
485 assert(flist != NULL);
487 @@ -1471,7 +1776,7 @@ static void send_directory(int f, struct
491 - send_file_name(f, flist, fbuf, NULL, flags, filter_flags);
492 + send_file_name(f, flist, fbuf, NULL, flags, filter_level);
496 @@ -1483,6 +1788,9 @@ static void send_directory(int f, struct
500 + if (checksum_updating && always_checksum && am_sender && f >= 0)
501 + write_checksums(fbuf);
503 if (f >= 0 && recurse && !divert_dirs) {
504 int i, end = flist->count - 1;
505 /* send_if_directory() bumps flist->count, so use "end". */
506 @@ -2206,7 +2514,7 @@ void flist_free(struct file_list *flist)
508 if (!flist->prev || !flist_cnt)
509 pool_destroy(flist->file_pool);
511 + else if (flist->pool_boundary)
512 pool_free_old(flist->file_pool, flist->pool_boundary);
514 if (flist->sorted && flist->sorted != flist->files)
515 @@ -2225,6 +2533,7 @@ static void clean_flist(struct file_list
518 if (flist->count == 0) {
525 @@ -149,6 +149,7 @@ typedef struct
529 + BOOL checksum_updating;
532 BOOL ignore_nonreadable;
533 @@ -197,6 +198,7 @@ static service sDefault =
534 /* syslog_facility; */ LOG_DAEMON,
537 + /* checksum_updating; */ False,
538 /* fake_super; */ False,
539 /* ignore_errors; */ False,
540 /* ignore_nonreadable; */ False,
541 @@ -313,6 +315,7 @@ static struct parm_struct parm_table[] =
542 {"lock file", P_STRING, P_LOCAL, &sDefault.lock_file, NULL,0},
543 {"log file", P_STRING, P_LOCAL, &sDefault.log_file, NULL,0},
544 {"log format", P_STRING, P_LOCAL, &sDefault.log_format, NULL,0},
545 + {"checksum updating", P_BOOL, P_LOCAL, &sDefault.checksum_updating, NULL,0},
546 {"max connections", P_INTEGER,P_LOCAL, &sDefault.max_connections, NULL,0},
547 {"max verbosity", P_INTEGER,P_LOCAL, &sDefault.max_verbosity, NULL,0},
548 {"name", P_STRING, P_LOCAL, &sDefault.name, NULL,0},
549 @@ -418,6 +421,7 @@ FN_LOCAL_BOOL(lp_fake_super, fake_super)
550 FN_LOCAL_BOOL(lp_ignore_errors, ignore_errors)
551 FN_LOCAL_BOOL(lp_ignore_nonreadable, ignore_nonreadable)
552 FN_LOCAL_BOOL(lp_list, list)
553 +FN_LOCAL_BOOL(lp_checksum_updating, checksum_updating)
554 FN_LOCAL_BOOL(lp_read_only, read_only)
555 FN_LOCAL_BOOL(lp_strict_modes, strict_modes)
556 FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
559 @@ -109,6 +109,7 @@ size_t bwlimit_writemax = 0;
560 int ignore_existing = 0;
561 int ignore_non_existing = 0;
562 int need_messages_from_generator = 0;
563 +int checksum_updating = 0;
567 @@ -302,6 +303,7 @@ void usage(enum logcode F)
568 rprintf(F," -q, --quiet suppress non-error messages\n");
569 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
570 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
571 + rprintf(F," --checksum-updating sender updates .rsyncsums files\n");
572 rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
573 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
574 rprintf(F," -r, --recursive recurse into directories\n");
575 @@ -542,6 +544,7 @@ static struct poptOption long_options[]
576 {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
577 {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
578 {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
579 + {"checksum-updating",0, POPT_ARG_NONE, &checksum_updating, 0, 0, 0 },
580 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
581 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
582 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
583 @@ -1896,7 +1899,9 @@ void server_options(char **args,int *arg
584 args[ac++] = basis_dir[i];
588 + } else if (checksum_updating)
589 + args[ac++] = "--checksum-updating";
593 args[ac++] = "--append";
596 @@ -589,6 +589,7 @@ extern int preserve_xattrs;
597 #define EXTRA_LEN (sizeof (union file_extras))
598 #define PTR_EXTRA_LEN ((sizeof (char *) + EXTRA_LEN - 1) / EXTRA_LEN)
599 #define SUM_EXTRA_CNT ((MAX_DIGEST_LEN + EXTRA_LEN - 1) / EXTRA_LEN)
600 +#define TIME_EXTRA_CNT ((SIZEOF_TIME_T + EXTRA_LEN - 1) / EXTRA_LEN)
602 #define REQ_EXTRA(f,ndx) ((union file_extras*)(f) - (ndx))
603 #define OPT_EXTRA(f,bump) ((union file_extras*)(f) - file_extra_cnt - 1 - (bump))
604 @@ -1070,6 +1071,12 @@ isDigit(const char *ptr)
608 +isXDigit(const char *ptr)
610 + return isxdigit(*(unsigned char *)ptr);
614 isPrint(const char *ptr)
616 return isprint(*(unsigned char *)ptr);
619 @@ -307,6 +307,7 @@ to the detailed description below for a
620 -q, --quiet suppress non-error messages
621 --no-motd suppress daemon-mode MOTD (see caveat)
622 -c, --checksum skip based on checksum, not mod-time & size
623 + --checksum-updating sender updates .rsyncsums files
624 -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
625 --no-OPTION turn off an implied OPTION (e.g. --no-D)
626 -r, --recursive recurse into directories
627 @@ -502,9 +503,9 @@ uses a "quick check" that (by default) c
628 of last modification match between the sender and receiver. This option
629 changes this to compare a 128-bit MD4 checksum for each file that has a
630 matching size. Generating the checksums means that both sides will expend
631 -a lot of disk I/O reading all the data in the files in the transfer (and
632 -this is prior to any reading that will be done to transfer changed files),
633 -so this can slow things down significantly.
634 +a lot of disk I/O reading the data in all the files in the transfer, so
635 +this can slow things down significantly (and this is prior to any reading
636 +that will be done to transfer the files that have changed).
638 The sending side generates its checksums while it is doing the file-system
639 scan that builds the list of the available files. The receiver generates
640 @@ -512,12 +513,42 @@ its checksums when it is scanning for ch
641 file that has the same size as the corresponding sender's file: files with
642 either a changed size or a changed checksum are selected for transfer.
644 +Starting with version 3.0.0, the sending side will look for a checksum
645 +summary file and use a pre-generated checksum that it reads out of the file
646 +(as long as it matches the file's size and modified time). This allows a
647 +server to support the --checksum option to clients without having to
648 +recompute the checksums for each client. See the bf(--checksum-updating)
649 +option for a way to have rsync create/update these checksum files.
651 Note that rsync always verifies that each em(transferred) file was
652 correctly reconstructed on the receiving side by checking a whole-file
653 checksum that is generated when as the file is transferred, but that
654 automatic after-the-transfer verification has nothing to do with this
655 option's before-the-transfer "Does this file need to be updated?" check.
657 +dit(bf(--checksum-updating)) This option tells the sending side to create
658 +and/or update per-directory checksum files that are used by the
659 +bf(--checksum) option. The file that is updated is named .rsyncsums. If
660 +pre-transfer checksums are not being computed, this option has no effect.
662 +The checksum files stores the computed checksum, last-known size,
663 +modification time, and name for each file in the current directory. If a
664 +later transfer finds that a file matches its prior size and modification
665 +time, the checksum is assumed to still be correct. Otherwise it is
666 +recomputed and udpated in the file.
668 +To avoid transferring the system's checksum files, you can use an exclude
669 +(e.g. bf(--exclude=.rsyncsums)). To make this easier to type, you can use
670 +a popt alias. For instance, adding the following line in your ~/.popt file
671 +defines a bf(-cc) option that enables checksum updating and excludes the
674 +verb( rsync alias --cc --checksum-updating --exclude=.rsyncsums)
676 +An rsync daemon does not allow the client to control this setting, so see
677 +the "checksum updating" daemon config option for information on how to make
678 +a daemon maintain these checksum files.
680 dit(bf(-a, --archive)) This is equivalent to bf(-rlptgoD). It is a quick
681 way of saying you want recursion and want to preserve almost
682 everything (with -H being a notable omission).
683 --- old/rsyncd.conf.yo
684 +++ new/rsyncd.conf.yo
685 @@ -198,6 +198,20 @@ locking on this file to ensure that the
686 exceeded for the modules sharing the lock file.
687 The default is tt(/var/run/rsyncd.lock).
689 +dit(bf(checksum updating)) This option tells rsync to update/create the
690 +checksum information in the per-directory checksum files when users copy
691 +files using the bf(--checksum) option. Any file that has changed since it
692 +was last checksummed (or is not mentioned) has its data updated in the
695 +Note that this updating will occur even if the module is listed as being
696 +read-only. If you want to hide these files (and you will almost always
697 +want to do), add ".rsyncsums" to the module's exclude setting.
699 +Note also that the client's command-line option, bf(--checksum-updating),
700 +has no effect on a daemon. A daemon will only update/create checksum files
701 +if this config option is true.
703 dit(bf(read only)) The "read only" option determines whether clients
704 will be able to upload files or not. If "read only" is true then any
705 attempted uploads will fail. If "read only" is false then uploads will
706 --- old/support/rsyncsums
707 +++ new/support/rsyncsums
713 +use Cwd qw(abs_path cwd);
717 +our $SUMS_FILE = '.rsyncsums';
719 +our($recurse_opt, $force_reading, $help_opt);
722 +&Getopt::Long::Configure('bundling');
723 +&usage if !&GetOptions(
724 + 'recurse|r' => \$recurse_opt,
725 + 'force|f' => \$force_reading,
726 + 'verbose|v+' => \$verbosity,
727 + 'help|h' => \$help_opt,
730 +my $start_dir = cwd();
733 +@dirs = '.' unless @dirs;
740 +my $md4 = Digest::MD4->new;
741 +my $md5 = Digest::MD5->new;
744 + my $dir = shift @dirs;
746 + if (!chdir($dir)) {
747 + warn "Unable to chdir to $dir: $!\n";
750 + if (!opendir(DP, '.')) {
751 + warn "Unable to opendir $dir: $!\n";
757 + $reldir =~ s#^$start_dir(/|$)# $1 ? '' : '.' #eo;
758 + print "$reldir ... ";
761 + my $sums_mtime = (stat($SUMS_FILE))[9];
766 + my $latest_time = 0;
767 + while (defined(my $fn = readdir(DP))) {
768 + next if $fn =~ /^\.\.?$/ || $fn =~ /^\Q$SUMS_FILE\E$/o || -l $fn;
770 + push(@subdirs, "$dir/$fn");
775 + my($size,$mtime,$ctime) = (stat(_))[7,9,10];
777 + $cache{$fn} = [ $size, $mtime, $ctime ];
780 + $latest_time = $mtime if $mtime > $latest_time;
781 + $latest_time = $ctime if $ctime > $latest_time;
786 + unshift(@dirs, sort @subdirs) if $recurse_opt;
789 + if (defined $sums_mtime) {
790 + print "(removed $SUMS_FILE) " if $verbosity;
791 + unlink($SUMS_FILE);
793 + print "empty\n" if $verbosity;
797 + if (defined($sums_mtime) && $sums_mtime == $latest_time && !$force_reading) {
798 + print "OK\n" if $verbosity;
802 + if (open(FP, '+<', $SUMS_FILE)) {
805 + my($sum4, $sum5, $size, $mtime, $ctime, $fn) = split(' ', $_, 6);
806 + my $ref = $cache{$fn};
807 + if (defined $ref) {
808 + if ($$ref[0] == $size
809 + && $$ref[1] == $mtime && $$ref[2] == $ctime
810 + && $sum4 !~ /=/ && $sum5 !~ /=/) {
815 + $$ref[3] = $$ref[4] = undef;
818 + $cnt = -1; # Force rewrite due to removed line.
822 + open(FP, '>', $SUMS_FILE) or die "Unable to write $dir/$SUMS_FILE: $!\n";
827 + print "updating\n" if $verbosity;
828 + while (my($fn, $ref) = each %cache) {
829 + next if defined $$ref[3] && defined $$ref[4];
830 + if (!open(IN, $fn)) {
831 + print STDERR "Unable to read $fn: $!\n";
832 + delete $cache{$fn};
836 + my($size,$mtime,$ctime) = (stat(IN))[7,9,10];
840 + while (sysread(IN, $_, 64*1024)) {
844 + $sum4 = $md4->hexdigest;
845 + $sum5 = $md5->hexdigest;
846 + print " $sum4 $sum5 $fn\n" if $verbosity > 1;
847 + my($size2,$mtime2,$ctime2) = (stat(IN))[7,9,10];
848 + last if $size == $size2 && $mtime == $mtime2 && $ctime == $ctime2;
857 + $cache{$fn} = [ $size, $mtime, $ctime, $sum4, $sum5 ];
862 + foreach my $fn (sort keys %cache) {
863 + my $ref = $cache{$fn};
864 + my($size, $mtime, $ctime, $sum4, $sum5) = @$ref;
865 + printf FP '%s %s %10d %10d %10d %s' . "\n", $sum4, $sum5, $size, $mtime, $ctime, $fn;
867 + $latest_time = $mtime if $mtime > $latest_time;
868 + $latest_time = $ctime if $ctime > $latest_time;
870 + truncate(FP, tell(FP));
872 + print "OK.\n" if $verbosity;
877 + utime $latest_time, $latest_time, $SUMS_FILE;
883 +Usage: rsyncsums [OPTIONS] [DIRS]
886 + -r, --recurse Update $SUMS_FILE files in subdirectories too.
887 + -f, --force Force the reading of an $SUMS_FILE file that looks to be
888 + up-to-date. (Useful for weeding out old entries.)
889 + -v, --verbose Mention what we're doing. Repeat for more info.
890 + -h, --help Display this help message.