]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
systemctl: rm empty dropin dirs after cancelled edit 2787/head
authorRonny Chevalier <chevalier.ronny@gmail.com>
Wed, 2 Mar 2016 21:06:47 +0000 (22:06 +0100)
committerRonny Chevalier <chevalier.ronny@gmail.com>
Wed, 2 Mar 2016 21:06:47 +0000 (22:06 +0100)
Fixes #2734

src/systemctl/systemctl.c

index 11e26ce737399d32c2a1534317fb3139a21bec02..c741baf58a20bcda5fe0396a67763fcaab1b0ab2 100644 (file)
@@ -6162,9 +6162,19 @@ static int edit(int argc, char *argv[], void *userdata) {
                 r = daemon_reload(argc, argv, userdata);
 
 end:
-        STRV_FOREACH_PAIR(original, tmp, paths)
+        STRV_FOREACH_PAIR(original, tmp, paths) {
                 (void) unlink(*tmp);
 
+                /* Removing empty dropin dirs */
+                if (!arg_full) {
+                        _cleanup_free_ char *dir = dirname_malloc(*original);
+                        /* no need to check if the dir is empty, rmdir
+                         * does nothing if it is not the case.
+                         */
+                        (void) rmdir(dir);
+                }
+        }
+
         return r;
 }