diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 9de612c1d6..5c520ac068 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -808,9 +808,14 @@ static int dir_cleanup( 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 diff --git a/test/units/TEST-22-TMPFILES.12.sh b/test/units/TEST-22-TMPFILES.12.sh index 44bb949825..1aa4faa0d3 100755 --- a/test/units/TEST-22-TMPFILES.12.sh +++ b/test/units/TEST-22-TMPFILES.12.sh @@ -204,3 +204,18 @@ test ! -d /tmp/ageby/d3 # 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