From: Bruno Haible Date: Mon, 1 May 2017 11:27:57 +0000 (+0200) Subject: copy-file: Preserve sub-second time stamps. X-Git-Tag: v1.0~6214 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3eee3a1e3c5b8883e0d4934bfc1326ee605cb7c1;p=gnulib.git copy-file: Preserve sub-second time stamps. * lib/copy-file.c: Include stat-time.h, utimens.h instead of . (qcopy_file_preserving): Use 'struct timespec' and utimens() to transport the time stamps from the original file to the destination file. * m4/copy-file.m4 (gl_COPY_FILE): Don't test for utime, utimes. * modules/copy-file (Depends-on): Add stat-time, utimns instead of utime-h. --- diff --git a/ChangeLog b/ChangeLog index d268b9e31c..2712adde26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2017-05-01 Bruno Haible + + copy-file: Preserve sub-second time stamps. + * lib/copy-file.c: Include stat-time.h, utimens.h instead of . + (qcopy_file_preserving): Use 'struct timespec' and utimens() to + transport the time stamps from the original file to the destination + file. + * m4/copy-file.m4 (gl_COPY_FILE): Don't test for utime, utimes. + * modules/copy-file (Depends-on): Add stat-time, utimns instead of + utime-h. + 2017-05-01 Bruno Haible wctype: Fix problems if gets included after . diff --git a/lib/copy-file.c b/lib/copy-file.c index b3f02a759c..462ea1cfd4 100644 --- a/lib/copy-file.c +++ b/lib/copy-file.c @@ -28,14 +28,12 @@ #include #include -#if HAVE_UTIME || HAVE_UTIMES -# include -#endif - #include "error.h" #include "ignore-value.h" #include "safe-read.h" #include "full-write.h" +#include "stat-time.h" +#include "utimens.h" #include "acl.h" #include "binary-io.h" #include "quote.h" @@ -113,23 +111,13 @@ qcopy_file_preserving (const char *src_filename, const char *dest_filename) #endif /* Preserve the access and modification times. */ -#if HAVE_UTIME - { - struct utimbuf ut; - - ut.actime = statbuf.st_atime; - ut.modtime = statbuf.st_mtime; - utime (dest_filename, &ut); - } -#elif HAVE_UTIMES { - struct timeval ut[2]; + struct timespec ts[2]; - ut[0].tv_sec = statbuf.st_atime; ut[0].tv_usec = 0; - ut[1].tv_sec = statbuf.st_mtime; ut[1].tv_usec = 0; - utimes (dest_filename, &ut); + ts[0] = get_stat_atime (&statbuf); + ts[1] = get_stat_mtime (&statbuf); + utimens (dest_filename, ts); } -#endif #if HAVE_CHOWN /* Preserve the owner and group. */ diff --git a/m4/copy-file.m4 b/m4/copy-file.m4 index 4b5db8a9ee..c29f7930a7 100644 --- a/m4/copy-file.m4 +++ b/m4/copy-file.m4 @@ -1,4 +1,4 @@ -# copy-file.m4 serial 4 +# copy-file.m4 serial 5 dnl Copyright (C) 2003, 2009-2017 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -7,5 +7,5 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_COPY_FILE], [ AC_CHECK_HEADERS_ONCE([unistd.h]) - AC_CHECK_FUNCS([chown utime utimes]) + AC_CHECK_FUNCS([chown]) ]) diff --git a/modules/copy-file b/modules/copy-file index 7238f55f6e..e94a22ca3c 100644 --- a/modules/copy-file +++ b/modules/copy-file @@ -17,9 +17,10 @@ ignore-value open quote safe-read +stat-time stdlib unistd -utime-h +utimens xalloc configure.ac: