diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-04-29 19:44:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-05-02 11:15:30 +0200 |
commit | 3b8483c0a3c7e2ba32c2f9b8ba36082bee3e0536 (patch) | |
tree | b21d9bfff07313e73fa40c7c0dc3f02cccbe2b10 | |
parent | b498c53d80faf7ebd0df5888a48793889ee421e4 (diff) |
copy: adjust directory times after writing to the directory
When recursively copying a directory tree, fix up the file times after having
created all contents in it, so that our changes don't end up altering any of
the directory times.
-rw-r--r-- | src/basic/copy.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/src/basic/copy.c b/src/basic/copy.c index c2baef6d22..79b9a0e1a0 100644 --- a/src/basic/copy.c +++ b/src/basic/copy.c @@ -327,22 +327,6 @@ static int fd_copy_directory( r = 0; - if (created) { - struct timespec ut[2] = { - st->st_atim, - st->st_mtim - }; - - if (fchown(fdt, st->st_uid, st->st_gid) < 0) - r = -errno; - - if (fchmod(fdt, st->st_mode & 07777) < 0) - r = -errno; - - (void) futimens(fdt, ut); - (void) copy_xattr(dirfd(d), fdt); - } - FOREACH_DIRENT_ALL(de, d, return -errno) { struct stat buf; int q; @@ -378,6 +362,22 @@ static int fd_copy_directory( r = q; } + if (created) { + struct timespec ut[2] = { + st->st_atim, + st->st_mtim + }; + + if (fchown(fdt, st->st_uid, st->st_gid) < 0) + r = -errno; + + if (fchmod(fdt, st->st_mode & 07777) < 0) + r = -errno; + + (void) copy_xattr(dirfd(d), fdt); + (void) futimens(fdt, ut); + } + return r; } @@ -409,7 +409,6 @@ int copy_tree(const char *from, const char *to, bool merge) { } int copy_directory_fd(int dirfd, const char *to, bool merge) { - struct stat st; assert(dirfd >= 0); |