From accc091fe9ebbb602bcf692c577486e62011d5c1 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Mon, 7 Sep 2009 13:45:33 -0700 Subject: [PATCH] Always use lutimes() if it is available. --- compat.c | 6 +++--- generator.c | 4 ++-- options.c | 4 ++-- rsync.h | 4 ++++ util.c | 15 +++++++-------- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/compat.c b/compat.c index 10add121..6655acd4 100644 --- a/compat.c +++ b/compat.c @@ -248,7 +248,7 @@ void setup_protocol(int f_out,int f_in) int compat_flags; if (am_server) { compat_flags = allow_inc_recurse ? CF_INC_RECURSE : 0; -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES compat_flags |= CF_SYMLINK_TIMES; #endif #ifdef ICONV_OPTION @@ -264,7 +264,7 @@ void setup_protocol(int f_out,int f_in) ? strchr(client_info, 'L') != NULL : !!(compat_flags & CF_SYMLINK_TIMES); } -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES else receiver_symlink_times = 1; #endif @@ -281,7 +281,7 @@ void setup_protocol(int f_out,int f_in) exit_cleanup(RERR_SYNTAX); } need_messages_from_generator = 1; -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES } else if (!am_sender) { receiver_symlink_times = 1; #endif diff --git a/generator.c b/generator.c index 5f6afd6f..11a7cb9d 100644 --- a/generator.c +++ b/generator.c @@ -392,7 +392,7 @@ static void do_delete_pass(void) int unchanged_attrs(const char *fname, struct file_struct *file, stat_x *sxp) { -#if !defined HAVE_LUTIMES || !defined HAVE_UTIMES +#ifndef CAN_SET_SYMLINK_TIMES if (S_ISLNK(file->mode)) { ; } else @@ -440,7 +440,7 @@ void itemize(const char *fnamecmp, struct file_struct *file, int ndx, int statre if (statret >= 0) { /* A from-dest-dir statret can == 1! */ int keep_time = !preserve_times ? 0 : S_ISDIR(file->mode) ? preserve_times > 1 : -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES 1; #else !S_ISLNK(file->mode); diff --git a/options.c b/options.c index 53640adc..ee981e37 100644 --- a/options.c +++ b/options.c @@ -596,7 +596,7 @@ static void print_rsync_version(enum logcode f) #ifdef ICONV_OPTION iconv = ""; #endif -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES symtimes = ""; #endif @@ -2358,7 +2358,7 @@ void server_options(char **args, int *argc_p) argstr[x++] = '.'; if (allow_inc_recurse) argstr[x++] = 'i'; -#if defined HAVE_LUTIMES && defined HAVE_UTIMES +#ifdef CAN_SET_SYMLINK_TIMES argstr[x++] = 'L'; #endif #ifdef ICONV_OPTION diff --git a/rsync.h b/rsync.h index 4d4a7642..cf2a2dd7 100644 --- a/rsync.h +++ b/rsync.h @@ -359,6 +359,10 @@ enum delret { #include #endif +#ifdef HAVE_LUTIMES +#define CAN_SET_SYMLINK_TIMES 1 +#endif + #ifdef HAVE_SYS_SELECT_H #include #endif diff --git a/util.c b/util.c index 4d58dc41..d7efd239 100644 --- a/util.c +++ b/util.c @@ -125,7 +125,7 @@ NORETURN void overflow_exit(const char *str) int set_modtime(const char *fname, time_t modtime, mode_t mode) { -#if !defined HAVE_LUTIMES || !defined HAVE_UTIMES +#ifndef CAN_SET_SYMLINK_TIMES if (S_ISLNK(mode)) return 1; #endif @@ -140,20 +140,19 @@ int set_modtime(const char *fname, time_t modtime, mode_t mode) return 0; { -#ifdef HAVE_UTIMES +#if defined HAVE_UTIMES || defined HAVE_LUTIMES struct timeval t[2]; t[0].tv_sec = time(NULL); t[0].tv_usec = 0; t[1].tv_sec = modtime; t[1].tv_usec = 0; # ifdef HAVE_LUTIMES - if (S_ISLNK(mode)) { - if (lutimes(fname, t) < 0) - return errno == ENOSYS ? 1 : -1; - return 0; - } -# endif + if (lutimes(fname, t) < 0) + return S_ISLNK(mode) && errno == ENOSYS ? 1 : -1; + return 0; +# else return utimes(fname, t); +# endif #elif defined HAVE_STRUCT_UTIMBUF struct utimbuf tbuf; tbuf.actime = time(NULL); -- 2.34.1