From: dongshengyuan <545258830@qq.com> Date: Thu, 16 Jul 2026 06:32:14 +0000 (+0800) Subject: repart: skip generated files during dry runs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7e68ec449b2f47a5cfccc77c701483783c51c96;p=thirdparty%2Fsystemd.git repart: skip generated files during dry runs Skip generated fstab and crypttab output when --dry-run=yes is used, after confirming there is eligible content to generate. Reproducer: systemd-repart --dry-run=yes --generate-fstab=/tmp/root/etc/fstab - Before: the command exited successfully and still wrote the requested fstab file. Follow-up: 1a0541d44c78ced78a566051ec8f63417370aeaa --- diff --git a/src/repart/repart.c b/src/repart/repart.c index bd8df612633..e07370805b9 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -9493,6 +9493,11 @@ static int context_fstab(Context *context) { return 0; } + if (arg_dry_run) { + log_notice("Running in dry run mode, not generating %s", arg_generate_fstab); + return 0; + } + path = path_join(arg_copy_source, arg_generate_fstab); if (!path) return log_oom(); @@ -9625,6 +9630,11 @@ static int context_crypttab(Context *context, bool late) { return 0; } + if (arg_dry_run) { + log_notice("Running in dry run mode, not generating %s", arg_generate_crypttab); + return 0; + } + path = path_join(arg_copy_source, arg_generate_crypttab); if (!path) return log_oom(); diff --git a/test/units/TEST-58-REPART.sh b/test/units/TEST-58-REPART.sh index d5fe4897eac..dbc5017d286 100755 --- a/test/units/TEST-58-REPART.sh +++ b/test/units/TEST-58-REPART.sh @@ -2873,6 +2873,35 @@ EOF losetup -d "$loop" } +testcase_generate_fstab_dry_run() { + local defs root + + defs="$(mktemp --directory "/tmp/test-repart.defs.XXXXXXXXXX")" + root="$(mktemp --directory "/var/test-repart.root.XXXXXXXXXX")" + # shellcheck disable=SC2064 + trap "rm -rf '$defs' '$root'" RETURN + chmod 0755 "$defs" + + echo "*** testcase for skipping generated fstab in dry-run mode ***" + + mkdir -p "$root/etc" + tee "$defs/root.conf" <