]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: skip generated files during dry runs
authordongshengyuan <545258830@qq.com>
Thu, 16 Jul 2026 06:32:14 +0000 (14:32 +0800)
committerdongshengyuan <545258830@qq.com>
Sat, 18 Jul 2026 07:48:34 +0000 (15:48 +0800)
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

src/repart/repart.c
test/units/TEST-58-REPART.sh

index bd8df61263354e11dc9b879918101b264100219e..e07370805b97d7e79f352212715cbbc4a4fa4335 100644 (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();
index d5fe4897eac7622dfdaee91f05c93945a71dc6eb..dbc5017d28698fca66b8ebf98d5355cebf5f68b0 100755 (executable)
@@ -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