]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tmpfiles: always remove/clean-up before creating
authorLennart Poettering <lennart@poettering.net>
Fri, 26 Oct 2018 19:19:36 +0000 (21:19 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Nov 2018 08:52:16 +0000 (09:52 +0100)
Let's always clean the platform before we build something new.

Fixes: #9508
src/tmpfiles/tmpfiles.c

index af8c12e06ea1a4603ab79987b90b1f559f692dbe..ce9146c1d1f8f61fb60b39d4222e24eba3c84551 100644 (file)
@@ -3162,11 +3162,11 @@ static int link_parent(ItemArray *a) {
 }
 
 int main(int argc, char *argv[]) {
-        int r, k, r_process = 0;
-        ItemArray *a;
-        Iterator iterator;
         _cleanup_strv_free_ char **config_dirs = NULL;
+        int r, k, r_process = 0, phase;
         bool invalid_config = false;
+        Iterator iterator;
+        ItemArray *a;
 
         r = parse_argv(argc, argv);
         if (r <= 0)
@@ -3242,20 +3242,34 @@ int main(int argc, char *argv[]) {
                         goto finish;
         }
 
-        /* The non-globbing ones usually create things, hence we apply
-         * them first */
-        ORDERED_HASHMAP_FOREACH(a, items, iterator) {
-                k = process_item_array(a, arg_operation);
-                if (k < 0 && r_process == 0)
-                        r_process = k;
-        }
+        /* If multiple operations are requested, let's first run the remove/clean operations, and only then the create
+         * operations. i.e. that we first clean out the platform we then build on. */
+        for (phase = 0; phase < 2; phase++) {
+                OperationMask op;
 
-        /* The globbing ones usually alter things, hence we apply them
-         * second. */
-        ORDERED_HASHMAP_FOREACH(a, globs, iterator) {
-                k = process_item_array(a, arg_operation);
-                if (k < 0 && r_process == 0)
-                        r_process = k;
+                if (phase == 0)
+                        op = arg_operation & (OPERATION_REMOVE|OPERATION_CLEAN);
+                else if (phase == 1)
+                        op = arg_operation & OPERATION_CREATE;
+                else
+                        assert_not_reached("unexpected phase");
+
+                if (op == 0) /* Nothing requested in this phase */
+                        continue;
+
+                /* The non-globbing ones usually create things, hence we apply them first */
+                ORDERED_HASHMAP_FOREACH(a, items, iterator) {
+                        k = process_item_array(a, op);
+                        if (k < 0 && r_process == 0)
+                                r_process = k;
+                }
+
+                /* The globbing ones usually alter things, hence we apply them second. */
+                ORDERED_HASHMAP_FOREACH(a, globs, iterator) {
+                        k = process_item_array(a, op);
+                        if (k < 0 && r_process == 0)
+                                r_process = k;
+                }
         }
 
 finish: