summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-29 19:44:59 +0200
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:58 +0200
commit2ed028df72f5995acfbeca89db3f056d0e83cac1 (patch)
tree0fec57e23a36cec8d26b4969caee8719c9617033 /src
parent3124bef9cf7c0f7be0584d41e249dc7d6f0ad4b4 (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.
Diffstat (limited to 'src')
-rw-r--r--src/basic/copy.c33
1 files changed, 16 insertions, 17 deletions
diff --git a/src/basic/copy.c b/src/basic/copy.c
index 24e03a705..24d109f48 100644
--- a/src/basic/copy.c
+++ b/src/basic/copy.c
@@ -289,22 +289,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;
@@ -340,6 +324,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;
}
@@ -371,7 +371,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);