Skip to content

Commit 2624e00

Browse files
author
Wayne Davison
committed
Add --omit-link-times and use CAN_SET_SYMLINK_TIMES less.
1 parent c9bf436 commit 2624e00

File tree

7 files changed

+43
-30
lines changed

7 files changed

+43
-30
lines changed

generator.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,12 +390,9 @@ static void do_delete_pass(void)
390390

391391
int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp)
392392
{
393-
#ifndef CAN_SET_SYMLINK_TIMES
394-
if (S_ISLNK(file->mode)) {
393+
if (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(file->mode)) {
395394
;
396-
} else
397-
#endif
398-
if (preserve_times && cmp_time(sxp->st.st_mtime, file->modtime) != 0)
395+
} else if (preserve_times && cmp_time(sxp->st.st_mtime, file->modtime) != 0)
399396
return 0;
400397

401398
if (preserve_perms) {
@@ -437,12 +434,9 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre
437434
{
438435
if (statret >= 0) { /* A from-dest-dir statret can == 1! */
439436
int keep_time = !preserve_times ? 0
440-
: S_ISDIR(file->mode) ? preserve_times > 1 :
441-
#ifdef CAN_SET_SYMLINK_TIMES
442-
1;
443-
#else
444-
!S_ISLNK(file->mode);
445-
#endif
437+
: S_ISDIR(file->mode) ? preserve_times & PRESERVE_DIR_TIMES
438+
: S_ISLNK(file->mode) ? preserve_times & PRESERVE_LINK_TIMES
439+
: 1;
446440

447441
if (S_ISREG(file->mode) && F_LENGTH(file) != sxp->st.st_size)
448442
iflags |= ITEM_REPORT_SIZE;
@@ -2056,7 +2050,7 @@ void generate_files(int f_out, const char *local_name)
20562050
}
20572051
solo_file = local_name;
20582052
dir_tweaking = !(list_only || solo_file || dry_run);
2059-
need_retouch_dir_times = preserve_times > 1;
2053+
need_retouch_dir_times = preserve_times & PRESERVE_DIR_TIMES;
20602054
loopchk_limit = allowed_lull ? allowed_lull * 5 : 200;
20612055
symlink_timeset_failed_flags = ITEM_REPORT_TIME
20622056
| (protocol_version >= 30 || !am_server ? ITEM_REPORT_TIMEFAIL : 0);

options.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ static int do_stats = 0;
293293
static int do_progress = 0;
294294
static int daemon_opt; /* sets am_daemon after option error-reporting */
295295
static int omit_dir_times = 0;
296+
static int omit_link_times = 0;
296297
static int F_option_cnt = 0;
297298
static int modify_window_set;
298299
static int itemize_changes = 0;
@@ -699,6 +700,7 @@ void usage(enum logcode F)
699700
rprintf(F," -D same as --devices --specials\n");
700701
rprintf(F," -t, --times preserve modification times\n");
701702
rprintf(F," -O, --omit-dir-times omit directories from --times\n");
703+
rprintf(F," -J, --omit-link-times omit symlinks from --times\n");
702704
rprintf(F," --super receiver attempts super-user activities\n");
703705
#ifdef SUPPORT_XATTRS
704706
rprintf(F," --fake-super store/recover privileged attrs using xattrs\n");
@@ -843,12 +845,15 @@ static struct poptOption long_options[] = {
843845
{"xattrs", 'X', POPT_ARG_NONE, 0, 'X', 0, 0 },
844846
{"no-xattrs", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
845847
{"no-X", 0, POPT_ARG_VAL, &preserve_xattrs, 0, 0, 0 },
846-
{"times", 't', POPT_ARG_VAL, &preserve_times, 2, 0, 0 },
848+
{"times", 't', POPT_ARG_VAL, &preserve_times, 1, 0, 0 },
847849
{"no-times", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
848850
{"no-t", 0, POPT_ARG_VAL, &preserve_times, 0, 0, 0 },
849851
{"omit-dir-times", 'O', POPT_ARG_VAL, &omit_dir_times, 1, 0, 0 },
850852
{"no-omit-dir-times",0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
851853
{"no-O", 0, POPT_ARG_VAL, &omit_dir_times, 0, 0, 0 },
854+
{"omit-link-times", 'J', POPT_ARG_VAL, &omit_link_times, 1, 0, 0 },
855+
{"no-omit-link-times",0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 },
856+
{"no-J", 0, POPT_ARG_VAL, &omit_link_times, 0, 0, 0 },
852857
{"modify-window", 0, POPT_ARG_INT, &modify_window, OPT_MODIFY_WINDOW, 0, 0 },
853858
{"super", 0, POPT_ARG_VAL, &am_root, 2, 0, 0 },
854859
{"no-super", 0, POPT_ARG_VAL, &am_root, 0, 0, 0 },
@@ -1452,7 +1457,7 @@ int parse_arguments(int *argc_p, const char ***argv_p)
14521457
preserve_links = 1;
14531458
#endif
14541459
preserve_perms = 1;
1455-
preserve_times = 2;
1460+
preserve_times = 1;
14561461
preserve_gid = 1;
14571462
preserve_uid = 1;
14581463
preserve_devices = 1;
@@ -2072,13 +2077,19 @@ int parse_arguments(int *argc_p, const char ***argv_p)
20722077
parse_filter_str(&filter_list, backup_dir_buf, rule_template(0), 0);
20732078
}
20742079

2080+
if (preserve_times) {
2081+
preserve_times = PRESERVE_FILE_TIMES;
2082+
if (!omit_dir_times)
2083+
preserve_times |= PRESERVE_DIR_TIMES;
2084+
#ifdef CAN_SET_SYMLINK_TIMES
2085+
if (!omit_link_times)
2086+
preserve_times |= PRESERVE_LINK_TIMES;
2087+
#endif
2088+
}
2089+
20752090
if (make_backups && !backup_dir) {
20762091
omit_dir_times = 0; /* Implied, so avoid -O to sender. */
2077-
if (preserve_times > 1)
2078-
preserve_times = 1;
2079-
} else if (omit_dir_times) {
2080-
if (preserve_times > 1)
2081-
preserve_times = 1;
2092+
preserve_times &= ~PRESERVE_DIR_TIMES;
20822093
}
20832094

20842095
if (stdout_format) {
@@ -2315,6 +2326,8 @@ void server_options(char **args, int *argc_p)
23152326
argstr[x++] = 'm';
23162327
if (omit_dir_times)
23172328
argstr[x++] = 'O';
2329+
if (omit_link_times)
2330+
argstr[x++] = 'J';
23182331
} else {
23192332
if (copy_links)
23202333
argstr[x++] = 'L';

rsync.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,13 @@ int set_file_attrs(const char *fname, struct file_struct *file, stat_x *sxp,
489489
set_xattr(fname, file, fnamecmp, sxp);
490490
#endif
491491

492-
if (!preserve_times || (S_ISDIR(sxp->st.st_mode) && preserve_times == 1))
492+
if (!preserve_times
493+
|| (!(preserve_times & PRESERVE_DIR_TIMES) && S_ISDIR(sxp->st.st_mode))
494+
|| (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(sxp->st.st_mode)))
493495
flags |= ATTRS_SKIP_MTIME;
494496
if (!(flags & ATTRS_SKIP_MTIME)
495497
&& cmp_time(sxp->st.st_mtime, file->modtime) != 0) {
496-
int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), sxp->st.st_mode);
498+
int ret = set_modtime(fname, file->modtime, F_MOD_NSEC(file), file->mode);
497499
if (ret < 0) {
498500
rsyserr(FERROR_XFER, errno, "failed to set times on %s",
499501
full_fname(fname));

rsync.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,10 @@ extern int errno;
11171117
#define IS_SPECIAL(mode) (S_ISSOCK(mode) || S_ISFIFO(mode))
11181118
#define IS_DEVICE(mode) (S_ISCHR(mode) || S_ISBLK(mode))
11191119

1120+
#define PRESERVE_FILE_TIMES (1<<0)
1121+
#define PRESERVE_DIR_TIMES (1<<1)
1122+
#define PRESERVE_LINK_TIMES (1<<2)
1123+
11201124
/* Initial mask on permissions given to temporary files. Mask off setuid
11211125
bits and group access because of potential race-condition security
11221126
holes, and mask other access because mode 707 is bizarre */

rsync.yo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ to the detailed description below for a complete description. verb(
356356
-D same as --devices --specials
357357
-t, --times preserve modification times
358358
-O, --omit-dir-times omit directories from --times
359+
-J, --omit-link-times omit symlinks from --times
359360
--super receiver attempts super-user activities
360361
--fake-super store/recover privileged attrs using xattrs
361362
-S, --sparse handle sparse files efficiently
@@ -1114,6 +1115,9 @@ it is preserving modification times (see bf(--times)). If NFS is sharing
11141115
the directories on the receiving side, it is a good idea to use bf(-O).
11151116
This option is inferred if you use bf(--backup) without bf(--backup-dir).
11161117

1118+
dit(bf(-J, --omit-link-times)) This tells rsync to omit symlinks when
1119+
it is preserving modification times (see bf(--times)).
1120+
11171121
dit(bf(--super)) This tells the receiving side to attempt super-user
11181122
activities even if the receiving rsync wasn't run by the super-user. These
11191123
activities include: preserving users via the bf(--owner) option, preserving

t_stub.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ int modify_window = 0;
2525
int module_id = -1;
2626
int relative_paths = 0;
2727
int module_dirlen = 0;
28+
int preserve_times = 0;
2829
int preserve_xattrs = 0;
2930
char number_separator = ',';
3031
char *partial_dir;

util.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ extern int dry_run;
2929
extern int module_id;
3030
extern int modify_window;
3131
extern int relative_paths;
32+
extern int preserve_times;
3233
extern int preserve_xattrs;
3334
extern char *module_dir;
3435
extern unsigned int module_dirlen;
@@ -124,10 +125,8 @@ NORETURN void overflow_exit(const char *str)
124125

125126
int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t mode)
126127
{
127-
#ifndef CAN_SET_SYMLINK_TIMES
128-
if (S_ISLNK(mode))
128+
if (!(preserve_times & PRESERVE_LINK_TIMES) && S_ISLNK(mode))
129129
return 1;
130-
#endif
131130

132131
if (DEBUG_GTE(TIME, 1)) {
133132
rprintf(FINFO, "set modtime of %s to (%ld) %s",
@@ -145,19 +144,15 @@ int set_modtime(const char *fname, time_t modtime, uint32 mod_nsec, mode_t mode)
145144
t[0].tv_nsec = UTIME_NOW;
146145
t[1].tv_sec = modtime;
147146
t[1].tv_nsec = mod_nsec;
148-
if (utimensat(AT_FDCWD, fname, t, AT_SYMLINK_NOFOLLOW) < 0)
149-
return S_ISLNK(mode) && errno == ENOSYS ? 1 : -1;
150-
return 0;
147+
return utimensat(AT_FDCWD, fname, t, AT_SYMLINK_NOFOLLOW);
151148
#elif defined HAVE_UTIMES || defined HAVE_LUTIMES
152149
struct timeval t[2];
153150
t[0].tv_sec = time(NULL);
154151
t[0].tv_usec = 0;
155152
t[1].tv_sec = modtime;
156153
t[1].tv_usec = mod_nsec / 1000;
157154
# ifdef HAVE_LUTIMES
158-
if (lutimes(fname, t) < 0)
159-
return S_ISLNK(mode) && errno == ENOSYS ? 1 : -1;
160-
return 0;
155+
return lutimes(fname, t);
161156
# else
162157
return utimes(fname, t);
163158
# endif

0 commit comments

Comments
 (0)