log_action("Would remove", "Removing", "%s directory \"%s\"", sub_path);
if (!arg_dry_run &&
- unlinkat(dirfd(d), de->d_name, AT_REMOVEDIR) < 0 &&
- !IN_SET(errno, ENOENT, ENOTEMPTY))
- r = log_warning_errno(errno, "Failed to remove directory \"%s\", ignoring: %m", sub_path);
+ unlinkat(dirfd(d), de->d_name, AT_REMOVEDIR) < 0) {
+ if (errno == ENOTEMPTY)
+ continue;
+ if (errno != ENOENT)
+ r = log_warning_errno(errno, "Failed to remove directory \"%s\", ignoring: %m", sub_path);
+ }
+
+ deleted = true;
} else {
_cleanup_close_ int fd = -EBADF; /* This file descriptor is defined here so that the
# Cleanup the test directory (fail if not empty).
rmdir /tmp/ageby
+
+# Removing an old child directory should restore the parent directory mtime.
+rm -rf /tmp/ageby-mtime
+mkdir -p /tmp/ageby-mtime/old-child
+touch --date "2020-01-01 00:00:00" /tmp/ageby-mtime/old-child /tmp/ageby-mtime
+before="$(stat -c %Y /tmp/ageby-mtime)"
+
+systemd-tmpfiles --clean - <<-EOF
+d /tmp/ageby-mtime - - - M:1s
+EOF
+
+after="$(stat -c %Y /tmp/ageby-mtime)"
+test "$before" = "$after"
+test ! -e /tmp/ageby-mtime/old-child
+rmdir /tmp/ageby-mtime