]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
copy: also attempt to copy atime/mtime when copying symlinks, device nodes, fifos
authorLennart Poettering <lennart@poettering.net>
Mon, 1 Feb 2021 15:57:46 +0000 (16:57 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Feb 2021 22:24:55 +0000 (23:24 +0100)
src/basic/copy.c

index aa805bb8e25acbf9e5303b37e453251dcd5a9cfc..c2c337c1a1b04d6b3a3f76acf08d4b9b13422acf 100644 (file)
@@ -391,9 +391,10 @@ static int fd_copy_symlink(
                      uid_is_valid(override_uid) ? override_uid : st->st_uid,
                      gid_is_valid(override_gid) ? override_gid : st->st_gid,
                      AT_SYMLINK_NOFOLLOW) < 0)
-                return -errno;
+                r = -errno;
 
-        return 0;
+        (void) utimensat(dt, to, (struct timespec[]) { st->st_atim, st->st_mtim }, AT_SYMLINK_NOFOLLOW);
+        return r;
 }
 
 /* Encapsulates the database we store potential hardlink targets in */
@@ -693,6 +694,8 @@ static int fd_copy_fifo(
         if (fchmodat(dt, to, st->st_mode & 07777, 0) < 0)
                 r = -errno;
 
+        (void) utimensat(dt, to, (struct timespec[]) { st->st_atim, st->st_mtim }, AT_SYMLINK_NOFOLLOW);
+
         (void) memorize_hardlink(hardlink_context, st, dt, to);
         return r;
 }
@@ -739,6 +742,8 @@ static int fd_copy_node(
         if (fchmodat(dt, to, st->st_mode & 07777, 0) < 0)
                 r = -errno;
 
+        (void) utimensat(dt, to, (struct timespec[]) { st->st_atim, st->st_mtim }, AT_SYMLINK_NOFOLLOW);
+
         (void) memorize_hardlink(hardlink_context, st, dt, to);
         return r;
 }