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: 1a0541d44c
This commit is contained in:
dongshengyuan
2026-07-18 15:48:34 +08:00
parent 50eaa51ce1
commit e7e68ec449
2 changed files with 39 additions and 0 deletions
+10
View File
@@ -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();
+29
View File
@@ -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" <<EOF
[Partition]
Type=root
Format=ext4
MountPoint=/
EOF
systemd-repart --pretty=yes \
--definitions "$defs" \
--dry-run=yes \
--seed="$seed" \
--generate-fstab="$root/etc/fstab" \
-
test ! -e "$root/etc/fstab"
}
testcase_encrypted_volume_empty_name() {
local defs imgs