From: Lennart Poettering Date: Thu, 28 Sep 2023 16:08:48 +0000 (+0200) Subject: repart: don't wipe the disk image if we just created it fresh X-Git-Tag: v255-rc1~319^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=19c58989f7f0f84577f0fc63cdccdb01fa97673f;p=thirdparty%2Fsystemd.git repart: don't wipe the disk image if we just created it fresh Let's avoid some unnecessary work if we the image is freshly created anyway. --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 1dd05b3bde6..9f9acdff1ed 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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;