]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: don't wipe the disk image if we just created it fresh
authorLennart Poettering <lennart@poettering.net>
Thu, 28 Sep 2023 16:08:48 +0000 (18:08 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Oct 2023 17:02:53 +0000 (19:02 +0200)
Let's avoid some unnecessary work if we the image is freshly created
anyway.

src/partition/repart.c

index 1dd05b3bde6a1486dd41f7a0dac2bc2fb0d87965..9f9acdff1edafb01e7358965cccc3a562ae47ad8 100644 (file)
@@ -3356,6 +3356,9 @@ static int context_wipe_and_discard(Context *context) {
 
         assert(context);
 
+        if (arg_empty == EMPTY_CREATE) /* If we just created the image, no need to wipe */
+                return 0;
+
         /* Wipe and discard the contents of all partitions we are about to create. We skip the discarding if
          * we were supposed to start from scratch anyway, as in that case we just discard the whole block
          * device in one go early on. */
@@ -5420,7 +5423,8 @@ static int context_write_partition_table(Context *context) {
 
         log_info("Applying changes.");
 
-        if (context->from_scratch) {
+        if (context->from_scratch && arg_empty != EMPTY_CREATE) {
+                /* Erase everything if we operate from scratch, except if the image was just created anyway, and thus is definitely empty. */
                 r = context_wipe_range(context, 0, context->total);
                 if (r < 0)
                         return r;