Skip to content
Snippets Groups Projects
Commit 6852289c authored by Eelco Dolstra's avatar Eelco Dolstra
Browse files

Use lutimes() if available to canonicalise the timestamp of symlinks

Also use utimes() instead of utime() if lutimes() is not available.
parent 1832ab71
No related branches found
No related tags found
No related merge requests found
...@@ -115,6 +115,11 @@ AC_CHECK_HEADERS([sys/mount.h], [], [], ...@@ -115,6 +115,11 @@ AC_CHECK_HEADERS([sys/mount.h], [], [],
]) ])
# Check for lutimes, optionally used for changing the mtime of
# symlinks.
AC_CHECK_FUNCS([lutimes])
# Check for <locale>. # Check for <locale>.
AC_LANG_PUSH(C++) AC_LANG_PUSH(C++)
AC_CHECK_HEADERS([locale]) AC_CHECK_HEADERS([locale])
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <utime.h> #include <utime.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -444,7 +445,7 @@ void canonicalisePathMetaData(const Path & path, bool recurse) ...@@ -444,7 +445,7 @@ void canonicalisePathMetaData(const Path & path, bool recurse)
throw SysError(format("changing owner of `%1%' to %2%") throw SysError(format("changing owner of `%1%' to %2%")
% path % geteuid()); % path % geteuid());
} }
if (!S_ISLNK(st.st_mode)) { if (!S_ISLNK(st.st_mode)) {
/* Mask out all type related bits. */ /* Mask out all type related bits. */
...@@ -458,14 +459,20 @@ void canonicalisePathMetaData(const Path & path, bool recurse) ...@@ -458,14 +459,20 @@ void canonicalisePathMetaData(const Path & path, bool recurse)
throw SysError(format("changing mode of `%1%' to %2$o") % path % mode); throw SysError(format("changing mode of `%1%' to %2$o") % path % mode);
} }
if (st.st_mtime != mtimeStore) { }
struct utimbuf utimbuf;
utimbuf.actime = st.st_atime; if (st.st_mtime != mtimeStore) {
utimbuf.modtime = mtimeStore; struct timeval times[2];
if (utime(path.c_str(), &utimbuf) == -1) times[0].tv_sec = st.st_atime;
throw SysError(format("changing modification time of `%1%'") % path); times[0].tv_usec = 0;
} times[1].tv_sec = mtimeStore;
times[1].tv_usec = 0;
#if HAVE_LUTIMES
if (lutimes(path.c_str(), times) == -1)
#else
if (!S_ISLNK(st.st_mode) && utimes(path.c_str(), times) == -1)
#endif
throw SysError(format("changing modification time of `%1%'") % path);
} }
if (recurse && S_ISDIR(st.st_mode)) { if (recurse && S_ISDIR(st.st_mode)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment