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 --- old/clientserver.c
13 +++ new/clientserver.c
14 @@ -37,6 +37,7 @@ extern int sanitize_paths;
15 extern int filesfrom_fd;
16 extern int remote_protocol;
17 extern int protocol_version;
18 +extern int checksum_updating;
19 extern int io_timeout;
21 extern int default_af_hint;
22 @@ -641,6 +642,8 @@ static int rsync_module(int f_in, int f_
23 else if (am_root < 0) /* Treat --fake-super from client as --super. */
26 + checksum_updating = lp_checksum_updating(i);
28 if (filesfrom_fd == 0)
41 @@ -57,6 +58,7 @@ extern int implied_dirs;
42 extern int file_extra_cnt;
43 extern int ignore_perishable;
44 extern int non_perishable_cnt;
45 +extern int checksum_updating;
46 extern int prune_empty_dirs;
47 extern int copy_links;
48 extern int copy_unsafe_links;
49 @@ -79,6 +81,9 @@ extern iconv_t ic_send, ic_recv;
51 #define PTR_SIZE (sizeof (struct file_struct *))
53 +#define FLAG_SUM_MISSING (1<<1) /* F_SUM() data is undefined */
54 +#define FLAG_SUM_KEEP (1<<2) /* keep entry when rewriting */
58 dev_t filesystem_dev; /* used to implement -x */
59 @@ -101,6 +106,10 @@ static char tmp_sum[MAX_DIGEST_LEN];
60 static char empty_sum[MAX_DIGEST_LEN];
61 static int flist_count_offset; /* for --delete --progress */
62 static int dir_count = 0;
63 +static struct file_list *checksum_flist = NULL;
64 +static int checksum_matches = 0;
65 +static int checksum_updates = 0;
66 +static int regular_skipped = 0;
68 static void clean_flist(struct file_list *flist, int strip_root);
69 static void output_flist(struct file_list *flist);
70 @@ -317,6 +326,301 @@ static void flist_done_allocating(struct
71 flist->pool_boundary = ptr;
74 +/* The len count is the length of the basename + 1 for the null. */
75 +static int add_checksum(const char *dirname, const char *basename, int len,
76 + OFF_T file_length, time_t mtime, int32 ctime, int32 inode,
77 + const char *sum, const char *alt_sum, int flags)
79 + struct file_struct *file;
80 + int alloc_len, extra_len;
83 + if (len == 10+1 && *basename == '.' && strcmp(basename, ".rsyncsums") == 0)
85 + if (file_length == 0)
89 + len = strlen(basename) + 1;
91 + /* "2" is for a 32-bit ctime num and an 32-bit inode num. */
92 + extra_len = (file_extra_cnt + (file_length > 0xFFFFFFFFu) + SUM_EXTRA_CNT + 2)
94 +#if EXTRA_ROUNDING > 0
95 + if (extra_len & (EXTRA_ROUNDING * EXTRA_LEN))
96 + extra_len = (extra_len | (EXTRA_ROUNDING * EXTRA_LEN)) + EXTRA_LEN;
98 + alloc_len = FILE_STRUCT_LEN + extra_len + len + checksum_len*2 + 1;
99 + bp = pool_alloc(checksum_flist->file_pool, alloc_len, "add_checksum");
101 + memset(bp, 0, extra_len + FILE_STRUCT_LEN);
103 + file = (struct file_struct *)bp;
104 + bp += FILE_STRUCT_LEN;
106 + memcpy(bp, basename, len);
108 + strlcpy(bp+len, alt_sum, checksum_len*2 + 1);
110 + memset(bp+len, '=', checksum_len*2);
111 + bp[len+checksum_len*2] = '\0';
114 + file->flags = flags;
115 + file->mode = S_IFREG;
116 + file->modtime = mtime;
117 + file->len32 = (uint32)file_length;
118 + if (file_length > 0xFFFFFFFFu) {
119 + file->flags |= FLAG_LENGTH64;
120 + OPT_EXTRA(file, 0)->unum = (uint32)(file_length >> 32);
122 + file->dirname = dirname;
124 + memcpy(bp, sum, checksum_len);
125 + F_CTIME(file) = ctime;
126 + F_INODE(file) = inode;
128 + flist_expand(checksum_flist, 1);
129 + checksum_flist->files[checksum_flist->used++] = file;
131 + checksum_flist->sorted = checksum_flist->files;
136 +static void write_checksums(const char *next_dirname, int whole_dir)
138 + static const char *dirname_save;
139 + char fbuf[MAXPATHLEN];
140 + const char *dirname;
141 + int used, new_entries, counts_match, no_skipped;
145 + dirname = dirname_save;
146 + dirname_save = next_dirname;
151 + used = checksum_flist->used;
152 + new_entries = checksum_updates != 0;
153 + counts_match = used == checksum_matches;
154 + no_skipped = whole_dir && regular_skipped == 0;
156 + clean_flist(checksum_flist, 0);
158 + checksum_flist->used = 0;
159 + checksum_matches = 0;
160 + checksum_updates = 0;
161 + regular_skipped = 0;
167 + if (pathjoin(fbuf, sizeof fbuf, dirname, ".rsyncsums") >= sizeof fbuf)
170 + strlcpy(fbuf, ".rsyncsums", sizeof fbuf);
172 + if (checksum_flist->high - checksum_flist->low < 0 && no_skipped) {
177 + if (!new_entries && (counts_match || !whole_dir))
180 + if (!(out_fp = fopen(fbuf, "w")))
184 + for (i = checksum_flist->low; i <= checksum_flist->high; i++) {
185 + struct file_struct *file = checksum_flist->sorted[i];
186 + const char *cp = F_SUM(file);
187 + const char *end = cp + checksum_len;
188 + const char *alt_sum = file->basename + strlen(file->basename) + 1;
189 + int32 ctime, inode;
190 + if (whole_dir && !(file->flags & FLAG_SUM_KEEP))
192 + ctime = F_CTIME(file);
193 + inode = F_INODE(file);
194 + if (protocol_version >= 30)
195 + fprintf(out_fp, "%s ", alt_sum);
196 + if (file->flags & FLAG_SUM_MISSING) {
199 + fprintf(out_fp, "==");
200 + } while (++cp != end);
203 + fprintf(out_fp, "%02x", CVAL(cp, 0));
204 + } while (++cp != end);
206 + if (protocol_version < 30)
207 + fprintf(out_fp, " %s", alt_sum);
208 + if (*alt_sum == '=')
210 + fprintf(out_fp, " %10.0f %10.0f %10lu %10lu %s\n",
211 + (double)F_LENGTH(file), (double)file->modtime,
212 + (long)ctime, (long)inode, file->basename);
218 +/* The direname value must remain unchanged during the lifespan of the
219 + * created checksum_flist object because we use it directly. */
220 +static void read_checksums(const char *dirname)
222 + char line[MAXPATHLEN+1024], fbuf[MAXPATHLEN], sum[MAX_DIGEST_LEN];
223 + const char *alt_sum = NULL;
226 + int32 ctime, inode;
227 + int len, dlen, i, flags;
231 + if (checksum_updating)
232 + write_checksums(dirname, 0);
234 + if (checksum_flist) {
235 + /* Reset the pool memory and empty the file-list array. */
236 + pool_free_old(checksum_flist->file_pool,
237 + pool_boundary(checksum_flist->file_pool, 0));
238 + checksum_flist->used = 0;
240 + checksum_flist = flist_new(FLIST_TEMP, "read_checksums");
242 + checksum_flist->low = 0;
243 + checksum_flist->high = -1;
244 + checksum_matches = 0;
245 + checksum_updates = 0;
246 + regular_skipped = 0;
251 + dlen = strlcpy(fbuf, dirname, sizeof fbuf);
252 + if (dlen >= (int)sizeof fbuf)
255 + fbuf[dlen++] = '/';
258 + strlcpy(fbuf+dlen, ".rsyncsums", sizeof fbuf - dlen);
259 + if (!(fp = fopen(fbuf, "r")))
262 + while (fgets(line, sizeof line, fp)) {
264 + if (protocol_version >= 30) {
267 + while (*++cp == '=') {}
269 + while (isXDigit(cp)) cp++;
270 + if (cp - alt_sum != MD4_DIGEST_LEN*2 || *cp != ' ')
272 + while (*++cp == ' ') {}
276 + for (i = 0; i < checksum_len*2; i++, cp++) {
282 + memset(sum, 0, checksum_len);
283 + flags = FLAG_SUM_MISSING;
285 + for (i = 0; i < checksum_len*2; i++, cp++) {
287 + if (isXDigit(cp)) {
291 + x = (*cp & 0xF) + 9;
305 + while (*++cp == ' ') {}
307 + if (protocol_version < 30) {
310 + while (*++cp == '=') {}
312 + while (isXDigit(cp)) cp++;
313 + if (cp - alt_sum != MD5_DIGEST_LEN*2 || *cp != ' ')
315 + while (*++cp == ' ') {}
319 + while (isDigit(cp))
320 + file_length = file_length * 10 + *cp++ - '0';
323 + while (*++cp == ' ') {}
326 + while (isDigit(cp))
327 + mtime = mtime * 10 + *cp++ - '0';
330 + while (*++cp == ' ') {}
333 + while (isDigit(cp))
334 + ctime = ctime * 10 + *cp++ - '0';
337 + while (*++cp == ' ') {}
340 + while (isDigit(cp))
341 + inode = inode * 10 + *cp++ - '0';
344 + while (*++cp == ' ') {}
347 + while (len && (cp[len-1] == '\n' || cp[len-1] == '\r'))
351 + cp[len++] = '\0'; /* len now counts the null */
352 + if (strchr(cp, '/') || len > MAXPATHLEN)
355 + strlcpy(fbuf+dlen, cp, sizeof fbuf - dlen);
356 + if (is_excluded(fbuf, 0, ALL_FILTERS)) {
357 + flags |= FLAG_SUM_KEEP;
358 + checksum_matches++;
361 + add_checksum(dirname, cp, len, file_length, mtime, ctime, inode,
362 + sum, alt_sum, flags);
366 + clean_flist(checksum_flist, 0);
369 int push_pathname(const char *dir, int len)
372 @@ -989,7 +1293,7 @@ struct file_struct *make_file(const char
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;
379 char thisname[MAXPATHLEN];
380 char linkname[MAXPATHLEN];
381 @@ -1076,6 +1380,8 @@ struct file_struct *make_file(const char
382 if (is_excluded(thisname, S_ISDIR(st.st_mode) != 0, filter_level)) {
383 if (ignore_perishable)
384 non_perishable_cnt++;
385 + if (S_ISREG(st.st_mode))
390 @@ -1114,9 +1420,16 @@ struct file_struct *make_file(const char
391 memcpy(lastdir, thisname, len);
394 + if (always_checksum && am_sender && flist)
395 + read_checksums(lastdir);
400 + if (always_checksum && am_sender && flist && lastdir_len == -2) {
402 + read_checksums("");
405 basename_len = strlen(basename) + 1; /* count the '\0' */
408 @@ -1192,11 +1505,44 @@ struct file_struct *make_file(const char
412 - if (always_checksum && am_sender && S_ISREG(st.st_mode))
413 - file_checksum(thisname, tmp_sum, st.st_size);
415 F_PATHNAME(file) = pathname;
417 + if (always_checksum && am_sender && S_ISREG(st.st_mode)) {
419 + if (flist && (j = flist_find(checksum_flist, file)) >= 0) {
420 + struct file_struct *fp = checksum_flist->sorted[j];
421 + int32 ctime = F_CTIME(fp);
422 + int32 inode = F_INODE(fp);
423 + if (F_LENGTH(fp) == st.st_size
424 + && fp->modtime == st.st_mtime
425 + && ctime == (int32)st.st_ctime
426 + && inode == (int32)st.st_ino) {
427 + if (fp->flags & FLAG_SUM_MISSING) {
428 + fp->flags &= ~FLAG_SUM_MISSING;
429 + checksum_updates++;
430 + file_checksum(thisname, tmp_sum, st.st_size);
431 + memcpy(F_SUM(fp), tmp_sum, MAX_DIGEST_LEN);
433 + checksum_matches++;
434 + memcpy(tmp_sum, F_SUM(fp), MAX_DIGEST_LEN);
436 + fp->flags |= FLAG_SUM_KEEP;
439 + goto compute_new_checksum;
442 + compute_new_checksum:
443 + file_checksum(thisname, tmp_sum, st.st_size);
444 + if (checksum_updating && flist) {
445 + checksum_updates +=
446 + add_checksum(file->dirname, basename, basename_len,
447 + st.st_size, st.st_mtime, st.st_ctime,
448 + st.st_ino, tmp_sum, NULL, FLAG_SUM_KEEP);
453 /* This code is only used by the receiver when it is building
454 * a list of files for a delete pass. */
455 if (keep_dirlinks && linkname_len && flist) {
456 @@ -1489,6 +1835,9 @@ static void send_directory(int f, struct
460 + if (checksum_updating && always_checksum && am_sender && f >= 0)
461 + write_checksums(NULL, 1);
463 if (f >= 0 && recurse && !divert_dirs) {
464 int i, end = flist->used - 1;
465 /* send_if_directory() bumps flist->used, so use "end". */
466 @@ -1932,7 +2281,11 @@ struct file_list *send_file_list(int f,
467 * file-list to check if this is a 1-file xfer. */
468 send_extra_file_list(f, 1);
474 + if (checksum_updating && always_checksum && flist_eof)
475 + read_checksums(NULL); /* writes any last updates */
479 @@ -2225,7 +2578,7 @@ void flist_free(struct file_list *flist)
481 if (!flist->prev || !flist_cnt)
482 pool_destroy(flist->file_pool);
484 + else if (flist->pool_boundary)
485 pool_free_old(flist->file_pool, flist->pool_boundary);
487 if (flist->sorted && flist->sorted != flist->files)
490 @@ -152,6 +152,7 @@ typedef struct
494 + BOOL checksum_updating;
497 BOOL ignore_nonreadable;
498 @@ -200,6 +201,7 @@ static service sDefault =
499 /* syslog_facility; */ LOG_DAEMON,
502 + /* checksum_updating; */ False,
503 /* fake_super; */ False,
504 /* ignore_errors; */ False,
505 /* ignore_nonreadable; */ False,
506 @@ -316,6 +318,7 @@ static struct parm_struct parm_table[] =
507 {"lock file", P_STRING, P_LOCAL, &sDefault.lock_file, NULL,0},
508 {"log file", P_STRING, P_LOCAL, &sDefault.log_file, NULL,0},
509 {"log format", P_STRING, P_LOCAL, &sDefault.log_format, NULL,0},
510 + {"checksum updating", P_BOOL, P_LOCAL, &sDefault.checksum_updating, NULL,0},
511 {"max connections", P_INTEGER,P_LOCAL, &sDefault.max_connections, NULL,0},
512 {"max verbosity", P_INTEGER,P_LOCAL, &sDefault.max_verbosity, NULL,0},
513 {"name", P_STRING, P_LOCAL, &sDefault.name, NULL,0},
514 @@ -421,6 +424,7 @@ FN_LOCAL_BOOL(lp_fake_super, fake_super)
515 FN_LOCAL_BOOL(lp_ignore_errors, ignore_errors)
516 FN_LOCAL_BOOL(lp_ignore_nonreadable, ignore_nonreadable)
517 FN_LOCAL_BOOL(lp_list, list)
518 +FN_LOCAL_BOOL(lp_checksum_updating, checksum_updating)
519 FN_LOCAL_BOOL(lp_read_only, read_only)
520 FN_LOCAL_BOOL(lp_strict_modes, strict_modes)
521 FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
524 @@ -109,6 +109,7 @@ size_t bwlimit_writemax = 0;
525 int ignore_existing = 0;
526 int ignore_non_existing = 0;
527 int need_messages_from_generator = 0;
528 +int checksum_updating = 0;
529 int max_delete = INT_MIN;
532 @@ -308,6 +309,7 @@ void usage(enum logcode F)
533 rprintf(F," -q, --quiet suppress non-error messages\n");
534 rprintf(F," --no-motd suppress daemon-mode MOTD (see manpage caveat)\n");
535 rprintf(F," -c, --checksum skip based on checksum, not mod-time & size\n");
536 + rprintf(F," --checksum-updating sender updates .rsyncsums files\n");
537 rprintf(F," -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)\n");
538 rprintf(F," --no-OPTION turn off an implied OPTION (e.g. --no-D)\n");
539 rprintf(F," -r, --recursive recurse into directories\n");
540 @@ -547,6 +549,7 @@ static struct poptOption long_options[]
541 {"checksum", 'c', POPT_ARG_VAL, &always_checksum, 1, 0, 0 },
542 {"no-checksum", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
543 {"no-c", 0, POPT_ARG_VAL, &always_checksum, 0, 0, 0 },
544 + {"checksum-updating",0, POPT_ARG_NONE, &checksum_updating, 0, 0, 0 },
545 {"block-size", 'B', POPT_ARG_LONG, &block_size, 0, 0, 0 },
546 {"compare-dest", 0, POPT_ARG_STRING, 0, OPT_COMPARE_DEST, 0, 0 },
547 {"copy-dest", 0, POPT_ARG_STRING, 0, OPT_COPY_DEST, 0, 0 },
548 @@ -1910,7 +1913,9 @@ void server_options(char **args,int *arg
549 args[ac++] = basis_dir[i];
553 + } else if (checksum_updating)
554 + args[ac++] = "--checksum-updating";
558 args[ac++] = "--append";
561 @@ -641,6 +641,10 @@ extern int xattrs_ndx;
562 #define F_SUM(f) ((char*)OPT_EXTRA(f, LEN64_BUMP(f) + HLINK_BUMP(f) \
563 + SUM_EXTRA_CNT - 1))
565 +/* These are only valid on an entry read from a checksum file. */
566 +#define F_CTIME(f) OPT_EXTRA(f, LEN64_BUMP(f) + SUM_EXTRA_CNT)->num
567 +#define F_INODE(f) OPT_EXTRA(f, LEN64_BUMP(f) + SUM_EXTRA_CNT + 1)->num
569 /* Some utility defines: */
570 #define F_IS_ACTIVE(f) (f)->basename[0]
571 #define F_IS_HLINKED(f) ((f)->flags & FLAG_HLINKED)
572 @@ -1077,6 +1081,12 @@ isDigit(const char *ptr)
576 +isXDigit(const char *ptr)
578 + return isxdigit(*(unsigned char *)ptr);
582 isPrint(const char *ptr)
584 return isprint(*(unsigned char *)ptr);
587 @@ -322,6 +322,7 @@ to the detailed description below for a
588 -q, --quiet suppress non-error messages
589 --no-motd suppress daemon-mode MOTD (see caveat)
590 -c, --checksum skip based on checksum, not mod-time & size
591 + --checksum-updating sender updates .rsyncsums files
592 -a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)
593 --no-OPTION turn off an implied OPTION (e.g. --no-D)
594 -r, --recursive recurse into directories
595 @@ -518,9 +519,9 @@ uses a "quick check" that (by default) c
596 of last modification match between the sender and receiver. This option
597 changes this to compare a 128-bit MD4 checksum for each file that has a
598 matching size. Generating the checksums means that both sides will expend
599 -a lot of disk I/O reading all the data in the files in the transfer (and
600 -this is prior to any reading that will be done to transfer changed files),
601 -so this can slow things down significantly.
602 +a lot of disk I/O reading the data in all the files in the transfer, so
603 +this can slow things down significantly (and this is prior to any reading
604 +that will be done to transfer the files that have changed).
606 The sending side generates its checksums while it is doing the file-system
607 scan that builds the list of the available files. The receiver generates
608 @@ -528,12 +529,42 @@ its checksums when it is scanning for ch
609 file that has the same size as the corresponding sender's file: files with
610 either a changed size or a changed checksum are selected for transfer.
612 +Starting with version 3.0.0, the sending side will look for a checksum
613 +summary file and use a pre-generated checksum that it reads out of the file
614 +(as long as it matches the file's size and modified time). This allows a
615 +server to support the --checksum option to clients without having to
616 +recompute the checksums for each client. See the bf(--checksum-updating)
617 +option for a way to have rsync create/update these checksum files.
619 Note that rsync always verifies that each em(transferred) file was
620 correctly reconstructed on the receiving side by checking a whole-file
621 checksum that is generated when as the file is transferred, but that
622 automatic after-the-transfer verification has nothing to do with this
623 option's before-the-transfer "Does this file need to be updated?" check.
625 +dit(bf(--checksum-updating)) This option tells the sending side to create
626 +and/or update per-directory checksum files that are used by the
627 +bf(--checksum) option. The file that is updated is named .rsyncsums. If
628 +pre-transfer checksums are not being computed, this option has no effect.
630 +The checksum files stores the computed checksum, last-known size,
631 +modification time, and name for each file in the current directory. If a
632 +later transfer finds that a file matches its prior size and modification
633 +time, the checksum is assumed to still be correct. Otherwise it is
634 +recomputed and udpated in the file.
636 +To avoid transferring the system's checksum files, you can use an exclude
637 +(e.g. bf(--exclude=.rsyncsums)). To make this easier to type, you can use
638 +a popt alias. For instance, adding the following line in your ~/.popt file
639 +defines a bf(-cc) option that enables checksum updating and excludes the
642 +verb( rsync alias --cc --checksum-updating --exclude=.rsyncsums)
644 +An rsync daemon does not allow the client to control this setting, so see
645 +the "checksum updating" daemon config option for information on how to make
646 +a daemon maintain these checksum files.
648 dit(bf(-a, --archive)) This is equivalent to bf(-rlptgoD). It is a quick
649 way of saying you want recursion and want to preserve almost
650 everything (with -H being a notable omission).
651 --- old/rsyncd.conf.yo
652 +++ new/rsyncd.conf.yo
653 @@ -198,6 +198,20 @@ locking on this file to ensure that the
654 exceeded for the modules sharing the lock file.
655 The default is tt(/var/run/rsyncd.lock).
657 +dit(bf(checksum updating)) This option tells rsync to update/create the
658 +checksum information in the per-directory checksum files when users copy
659 +files using the bf(--checksum) option. Any file that has changed since it
660 +was last checksummed (or is not mentioned) has its data updated in the
663 +Note that this updating will occur even if the module is listed as being
664 +read-only. If you want to hide these files (and you will almost always
665 +want to do), add ".rsyncsums" to the module's exclude setting.
667 +Note also that the client's command-line option, bf(--checksum-updating),
668 +has no effect on a daemon. A daemon will only update/create checksum files
669 +if this config option is true.
671 dit(bf(read only)) The "read only" option determines whether clients
672 will be able to upload files or not. If "read only" is true then any
673 attempted uploads will fail. If "read only" is false then uploads will
674 --- old/support/rsyncsums
675 +++ new/support/rsyncsums
681 +use Cwd qw(abs_path cwd);
685 +our $SUMS_FILE = '.rsyncsums';
687 +our($recurse_opt, $help_opt);
690 +&Getopt::Long::Configure('bundling');
691 +&usage if !&GetOptions(
692 + 'recurse|r' => \$recurse_opt,
693 + 'verbose|v+' => \$verbosity,
694 + 'help|h' => \$help_opt,
697 +my $start_dir = cwd();
700 +@dirs = '.' unless @dirs;
707 +my $md4 = Digest::MD4->new;
708 +my $md5 = Digest::MD5->new;
711 + my $dir = shift @dirs;
713 + if (!chdir($dir)) {
714 + warn "Unable to chdir to $dir: $!\n";
717 + if (!opendir(DP, '.')) {
718 + warn "Unable to opendir $dir: $!\n";
724 + $reldir =~ s#^$start_dir(/|$)# $1 ? '' : '.' #eo;
725 + print "$reldir ... ";
728 + my $sums_mtime = (stat($SUMS_FILE))[9];
732 + while (defined(my $fn = readdir(DP))) {
733 + next if $fn =~ /^\.\.?$/ || $fn =~ /^\Q$SUMS_FILE\E$/o || -l $fn;
735 + push(@subdirs, "$dir/$fn");
740 + my($size,$mtime,$ctime,$inode) = (stat(_))[7,9,10,1];
741 + next if $size == 0;
743 + $cache{$fn} = [ $size, $mtime, $ctime & 0xFFFFFFFF, $inode & 0xFFFFFFFF ];
749 + unshift(@dirs, sort @subdirs) if $recurse_opt;
752 + if (defined $sums_mtime) {
753 + print "(removed $SUMS_FILE) " if $verbosity;
754 + unlink($SUMS_FILE);
756 + print "empty\n" if $verbosity;
760 + if (open(FP, '+<', $SUMS_FILE)) {
763 + my($sum4, $sum5, $size, $mtime, $ctime, $inode, $fn) = split(' ', $_, 7);
764 + my $ref = $cache{$fn};
765 + if (defined $ref) {
766 + if ($$ref[0] == $size
767 + && $$ref[1] == $mtime
768 + && $$ref[2] == $ctime
769 + && $$ref[3] == $inode
770 + && $sum4 !~ /=/ && $sum5 !~ /=/) {
775 + $$ref[4] = $$ref[5] = undef;
778 + $cnt = -1; # Force rewrite due to removed line.
782 + open(FP, '>', $SUMS_FILE) or die "Unable to write $dir/$SUMS_FILE: $!\n";
787 + print "UPDATING\n" if $verbosity;
788 + while (my($fn, $ref) = each %cache) {
789 + next if defined $$ref[3] && defined $$ref[4];
790 + if (!open(IN, $fn)) {
791 + print STDERR "Unable to read $fn: $!\n";
792 + delete $cache{$fn};
796 + my($size,$mtime,$ctime,$inode) = (stat(IN))[7,9,10,1];
804 + while (sysread(IN, $_, 64*1024)) {
808 + $sum4 = $md4->hexdigest;
809 + $sum5 = $md5->hexdigest;
810 + print " $sum4 $sum5" if $verbosity > 2;
811 + print " $fn\n" if $verbosity > 1;
812 + my($size2,$mtime2,$ctime2,$inode2) = (stat(IN))[7,9,10,1];
813 + last if $size == $size2 && $mtime == $mtime2
814 + && $ctime == $ctime2 && $inode == $inode2;
824 + $cache{$fn} = [ $size, $mtime, $ctime, $inode, $sum4, $sum5 ];
828 + foreach my $fn (sort keys %cache) {
829 + my $ref = $cache{$fn};
830 + my($size, $mtime, $ctime, $inode, $sum4, $sum5) = @$ref;
831 + printf FP '%s %s %10d %10d %10d %10d %s' . "\n", $sum4, $sum5, $size, $mtime, $ctime, $inode, $fn;
833 + truncate(FP, tell(FP));
835 + print "ok\n" if $verbosity;
844 +Usage: rsyncsums [OPTIONS] [DIRS]
847 + -r, --recurse Update $SUMS_FILE files in subdirectories too.
848 + -v, --verbose Mention what we're doing. Repeat for more info.
849 + -h, --help Display this help message.