Skip to content

Commit b774dbc

Browse files
committed
Improve --omit-dir-times & --omit-link-times
The code now better handles skipping time setting on dirs and/or links when --atimes and/or --crtimes is specified without --times.
1 parent 296352e commit b774dbc

File tree

8 files changed

+43
-53
lines changed

8 files changed

+43
-53
lines changed

NEWS.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
newer for your copy, rsync now sends `--no-W` to the remote rsync in such a
1313
scenario (just in case the remote rsync is a version with this bug).
1414

15-
- Fix a bug with `--mkpath` if a single-file copy specifies an existing
15+
- Fixed a bug with `--mkpath` if a single-file copy specifies an existing
1616
destination dir with a non-existing destination filename.
1717

18-
- Fix `--update -vv` to output "is uptodate" instead of "is newer" messages
18+
- Fixed `--update -vv` to output "is uptodate" instead of "is newer" messages
1919
for files that are being skipped due to an identical modify time. (This
2020
was a new output quirk in 3.2.3.)
2121

@@ -51,7 +51,7 @@
5151
- Reduced memory usage for an incremental transfer that has a bunch of small
5252
diretories.
5353

54-
- Added support for `--atimes` on macOS and fix using using it without -t.
54+
- Added support for `--atimes` on macOS and fixed using using it without -t.
5555

5656
- Rsync can now update the xattrs on a read-only file when your user can
5757
temporarily add user-write permission to the file. (It always worked for a
@@ -120,7 +120,7 @@
120120
- Restored the ability to use `--bwlimit=0` to specify no bandwidth limit. (It
121121
was accidentally broken in 3.2.2.)
122122

123-
- Fix a bug when combining `--delete-missing-args` with `--no-implied-dirs` &
123+
- Fixed a bug when combining `--delete-missing-args` with `--no-implied-dirs` &
124124
`-R` where rsync might create the destination path of a missing arg. The
125125
code also avoids some superfluous warnings for nested paths of removed args.
126126

generator.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ extern int preserve_specials;
4444
extern int preserve_hard_links;
4545
extern int preserve_executability;
4646
extern int preserve_perms;
47-
extern int preserve_times;
47+
extern int preserve_mtimes;
48+
extern int omit_dir_times;
49+
extern int omit_link_times;
4850
extern int delete_mode;
4951
extern int delete_before;
5052
extern int delete_during;
@@ -460,7 +462,7 @@ int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp)
460462
{
461463
if (S_ISLNK(file->mode)) {
462464
#ifdef CAN_SET_SYMLINK_TIMES
463-
if (preserve_times & PRESERVE_LINK_TIMES && any_time_differs(sxp, file, fname))
465+
if (preserve_mtimes && !omit_link_times && any_time_differs(sxp, file, fname))
464466
return 0;
465467
#endif
466468
#ifdef CAN_CHMOD_SYMLINK
@@ -480,7 +482,7 @@ int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp)
480482
return 0;
481483
#endif
482484
} else {
483-
if (preserve_times && any_time_differs(sxp, file, fname))
485+
if (preserve_mtimes && any_time_differs(sxp, file, fname))
484486
return 0;
485487
if (perms_differ(file, sxp))
486488
return 0;
@@ -504,9 +506,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
504506
const char *xname)
505507
{
506508
if (statret >= 0) { /* A from-dest-dir statret can == 1! */
507-
int keep_time = !preserve_times ? 0
508-
: S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES
509-
: S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES
509+
int keep_time = !preserve_mtimes ? 0
510+
: S_ISDIR(file->mode) ? !omit_dir_times
511+
: S_ISLNK(file->mode) ? !omit_link_times
510512
: 1;
511513

512514
if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
@@ -1411,7 +1413,7 @@ static void recv_generator(char *fname, struct file_struct *file, int ndx,
14111413
} else
14121414
added_perms = 0;
14131415
if (is_dir < 0) {
1414-
if (!(preserve_times & PRESERVE_DIR_TIMES))
1416+
if (!preserve_mtimes || omit_dir_times)
14151417
goto cleanup;
14161418
/* In inc_recurse mode we want to make sure any missing
14171419
* directories get created while we're still processing
@@ -2238,7 +2240,7 @@ void generate_files(int f_out, const char *local_name)
22382240
}
22392241
solo_file = local_name;
22402242
dir_tweaking = !(list_only || solo_file || dry_run);
2241-
need_retouch_dir_times = preserve_times & PRESERVE_DIR_TIMES;
2243+
need_retouch_dir_times = preserve_mtimes && !omit_dir_times;
22422244
loopchk_limit = allowed_lull ? allowed_lull * 5 : 200;
22432245
symlink_timeset_failed_flags = ITEM_REPORT_TIME
22442246
| (protocol_version >= 30 || !am_server ? ITEM_REPORT_TIMEFAIL : 0);

log.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extern int module_id;
3434
extern int allow_8bit_chars;
3535
extern int protocol_version;
3636
extern int always_checksum;
37-
extern int preserve_times;
37+
extern int preserve_mtimes;
3838
extern int msgs2stderr;
3939
extern int xfersum_type;
4040
extern int checksum_type;
@@ -706,15 +706,15 @@ static void log_formatted(enum logcode code, const char *format, const char *op,
706706
c[1] = 'L';
707707
c[3] = '.';
708708
c[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
709-
: !preserve_times || !receiver_symlink_times
709+
: !preserve_mtimes || !receiver_symlink_times
710710
|| (iflags & ITEM_REPORT_TIMEFAIL) ? 'T' : 't';
711711
} else {
712712
c[1] = S_ISDIR(file->mode) ? 'd'
713713
: IS_SPECIAL(file->mode) ? 'S'
714714
: IS_DEVICE(file->mode) ? 'D' : 'f';
715715
c[3] = !(iflags & ITEM_REPORT_SIZE) ? '.' : 's';
716716
c[4] = !(iflags & ITEM_REPORT_TIME) ? '.'
717-
: !preserve_times ? 'T' : 't';
717+
: !preserve_mtimes ? 'T' : 't';
718718
}
719719
c[2] = !(iflags & ITEM_REPORT_CHANGE) ? '.' : 'c';
720720
c[5] = !(iflags & ITEM_REPORT_PERMS) ? '.' : 'p';

options.c

+11-23
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ int preserve_devices = 0;
5858
int preserve_specials = 0;
5959
int preserve_uid = 0;
6060
int preserve_gid = 0;
61-
int preserve_times = 0;
61+
int preserve_mtimes = 0;
6262
int preserve_atimes = 0;
6363
int preserve_crtimes = 0;
64+
int omit_dir_times = 0;
65+
int omit_link_times = 0;
6466
int update_only = 0;
6567
int open_noatime = 0;
6668
int cvs_exclude = 0;
@@ -308,8 +310,6 @@ static int verbose = 0;
308310
static int do_stats = 0;
309311
static int do_progress = 0;
310312
static int daemon_opt; /* sets am_daemon after option error-reporting */
311-
static int omit_dir_times = 0;
312-
static int omit_link_times = 0;
313313
static int F_option_cnt = 0;
314314
static int modify_window_set;
315315
static int itemize_changes = 0;
@@ -622,9 +622,9 @@ static struct poptOption long_options[] = {
622622
{"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
623623
{"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
624624
{"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
625-
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
626-
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
627-
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
625+
{"times", 't', POPT_ARG_VAL, &preserve_mtimes, 1, 0, 0 },
626+
{"no-times", 0, POPT_ARG_VAL, &preserve_mtimes, 0, 0, 0 },
627+
{"no-t", 0, POPT_ARG_VAL, &preserve_mtimes, 0, 0, 0 },
628628
{"atimes", 'U', POPT_ARG_NONE, 0, 'U', 0, 0 },
629629
{"no-atimes", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
630630
{"no-U", 0, POPT_ARG_VAL, &preserve_atimes, 0, 0, 0 },
@@ -1518,7 +1518,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
15181518
preserve_links = 1;
15191519
#endif
15201520
preserve_perms = 1;
1521-
preserve_times = 1;
1521+
preserve_mtimes = 1;
15221522
preserve_gid = 1;
15231523
preserve_uid = 1;
15241524
preserve_devices = 1;
@@ -2257,20 +2257,8 @@ int parse_arguments(int *argc_p, const char ***argv_p)
22572257
parse_filter_str(&filter_list, backup_dir_buf, rule_template(0), 0);
22582258
}
22592259

2260-
if (preserve_times) {
2261-
preserve_times = PRESERVE_FILE_TIMES;
2262-
if (!omit_dir_times)
2263-
preserve_times |= PRESERVE_DIR_TIMES;
2264-
#ifdef CAN_SET_SYMLINK_TIMES
2265-
if (!omit_link_times)
2266-
preserve_times |= PRESERVE_LINK_TIMES;
2267-
#endif
2268-
}
2269-
2270-
if (make_backups && !backup_dir) {
2271-
omit_dir_times = 0; /* Implied, so avoid -O to sender. */
2272-
preserve_times &= ~PRESERVE_DIR_TIMES;
2273-
}
2260+
if (make_backups && !backup_dir)
2261+
omit_dir_times = -1; /* Implied, so avoid -O to sender. */
22742262

22752263
if (stdout_format) {
22762264
if (am_server && log_format_has(stdout_format, 'I'))
@@ -2498,7 +2486,7 @@ void server_options(char **args, int *argc_p)
24982486
argstr[x++] = 'K';
24992487
if (prune_empty_dirs)
25002488
argstr[x++] = 'm';
2501-
if (omit_dir_times)
2489+
if (omit_dir_times > 0)
25022490
argstr[x++] = 'O';
25032491
if (omit_link_times)
25042492
argstr[x++] = 'J';
@@ -2531,7 +2519,7 @@ void server_options(char **args, int *argc_p)
25312519
argstr[x++] = 'g';
25322520
if (preserve_devices) /* ignore preserve_specials here */
25332521
argstr[x++] = 'D';
2534-
if (preserve_times)
2522+
if (preserve_mtimes)
25352523
argstr[x++] = 't';
25362524
if (preserve_atimes) {
25372525
argstr[x++] = 'U';

rsync.c

+9-7
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ extern int preserve_acls;
3232
extern int preserve_xattrs;
3333
extern int preserve_perms;
3434
extern int preserve_executability;
35-
extern int preserve_times;
35+
extern int preserve_mtimes;
36+
extern int omit_dir_times;
37+
extern int omit_link_times;
3638
extern int am_root;
3739
extern int am_server;
3840
extern int am_daemon;
@@ -575,18 +577,18 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
575577
set_xattr(fname, file, fnamecmp, sxp);
576578
#endif
577579

578-
if (!preserve_times)
579-
flags |= ATTRS_SKIP_MTIME | (atimes_ndx ? 0 : ATTRS_SKIP_ATIME) | (crtimes_ndx ? 0 : ATTRS_SKIP_CRTIME);
580-
else if ((!(preserve_times & PRESERVE_DIR_TIMES) && S_ISDIR(sxp->st.st_mode))
581-
|| (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(sxp->st.st_mode)))
580+
if ((omit_dir_times && S_ISDIR(sxp->st.st_mode))
581+
|| (omit_link_times && S_ISLNK(sxp->st.st_mode)))
582582
flags |= ATTRS_SKIP_MTIME | ATTRS_SKIP_ATIME | ATTRS_SKIP_CRTIME;
583-
else if (sxp != &sx2)
584-
memcpy(&sx2.st, &sxp->st, sizeof (sx2.st));
583+
if (!preserve_mtimes)
584+
flags |= ATTRS_SKIP_MTIME;
585585
if (!atimes_ndx || S_ISDIR(sxp->st.st_mode))
586586
flags |= ATTRS_SKIP_ATIME;
587587
/* Don't set the creation date on the root folder of an HFS+ volume. */
588588
if (sxp->st.st_ino == 2 && S_ISDIR(sxp->st.st_mode))
589589
flags |= ATTRS_SKIP_CRTIME;
590+
if (sxp != &sx2 && !(flags & (ATTRS_SKIP_MTIME | ATTRS_SKIP_ATIME)))
591+
memcpy(&sx2.st, &sxp->st, sizeof sx2.st);
590592
if (!(flags & ATTRS_SKIP_MTIME) && !same_mtime(file, &sxp->st, flags & ATTRS_ACCURATE_TIME)) {
591593
sx2.st.st_mtime = file->modtime;
592594
#ifdef ST_MTIME_NSEC

rsync.h

-4
Original file line numberDiff line numberDiff line change
@@ -1327,10 +1327,6 @@ extern int errno;
13271327
#define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
13281328
#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
13291329

1330-
#define PRESERVE_FILE_TIMES (1<<0)
1331-
#define PRESERVE_DIR_TIMES (1<<1)
1332-
#define PRESERVE_LINK_TIMES (1<<2)
1333-
13341330
/* Initial mask on permissions given to temporary files. Mask off setuid
13351331
bits and group access because of potential race-condition security
13361332
holes, and mask other access because mode 707 is bizarre */

t_stub.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ int protect_args = 0;
2929
int module_id = -1;
3030
int relative_paths = 0;
3131
int module_dirlen = 0;
32-
int preserve_times = 0;
32+
int preserve_mtimes = 0;
3333
int preserve_xattrs = 0;
3434
int preserve_perms = 0;
3535
int preserve_executability = 0;
36+
int omit_link_times = 0;
3637
int open_noatime = 0;
3738
size_t max_alloc = 0; /* max_alloc is needed when combined with util2.o */
3839
char *partial_dir;

util1.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ extern int do_fsync;
3131
extern int protect_args;
3232
extern int modify_window;
3333
extern int relative_paths;
34-
extern int preserve_times;
34+
extern int preserve_mtimes;
3535
extern int preserve_xattrs;
36+
extern int omit_link_times;
3637
extern int preallocate_files;
3738
extern char *module_dir;
3839
extern unsigned int module_dirlen;
@@ -159,8 +160,8 @@ int set_times(const char *fname, STRUCT_STAT *stp)
159160

160161
#include "case_N.h"
161162
switch_step++;
162-
if (preserve_times & PRESERVE_LINK_TIMES) {
163-
preserve_times &= ~PRESERVE_LINK_TIMES;
163+
if (!omit_link_times) {
164+
omit_link_times = 1;
164165
if (S_ISLNK(stp->st_mode))
165166
return 1;
166167
}

0 commit comments

Comments
 (0)