]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: honour --dry-run when removing directories
authorLennart Poettering <lennart@poettering.net>
Tue, 18 Jun 2024 07:54:33 +0000 (09:54 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Jun 2024 08:15:24 +0000 (10:15 +0200)
src/tmpfiles/tmpfiles.c

index 1805cfb8a177c835da0e89a291b1f0d74f0a0770..3b3489ee62205cc0bb76e5954e8627186dd2de27 100644 (file)
@@ -3024,10 +3024,16 @@ static int remove_recursive(
                 return r;
 
         if (remove_instance) {
-                log_debug("Removing directory \"%s\".", instance);
-                r = RET_NERRNO(rmdir(instance));
-                if (r < 0 && !IN_SET(r, -ENOENT, -ENOTEMPTY))
-                        return log_error_errno(r, "Failed to remove %s: %m", instance);
+                log_action("Would remove", "Removing", "%s directory \"%s\".", instance);
+                if (!arg_dry_run) {
+                        r = RET_NERRNO(rmdir(instance));
+                        if (r < 0) {
+                                bool fatal = !IN_SET(r, -ENOENT, -ENOTEMPTY);
+                                log_full_errno(fatal ? LOG_ERR : LOG_DEBUG, r, "Failed to remove %s: %m", instance);
+                                if (fatal)
+                                        return r;
+                        }
+                }
         }
         return 0;
 }