]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
repart: Remove unnecessary newlines from JSON output
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 3 Aug 2022 13:39:12 +0000 (15:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 3 Aug 2022 16:44:10 +0000 (18:44 +0200)
Before

```
➜  systemd git:(dissect-have-blkid) SYSTEMD_LOG_LEVEL=err build/systemd-repart --definitions definitions/ --dry-run=yes --empty=create --size=100M --json=pretty abc
[
        {
                "type" : "root-x86-64",
                "label" : "root-x86-64",
                "uuid" : "2f7c902c-6b2a-4b47-a44b-dca765f38cd2",
                "file" : "root.conf",
                "node" : "abc1",
                "offset" : 1048576,
                "old_size" : 0,
                "raw_size" : 103788544,
                "old_padding" : 0,
                "raw_padding" : 0,
                "activity" : "create"
        }
]

➜  systemd git:(dissect-have-blkid)
```

After:

```
➜  systemd git:(repart-newlines) SYSTEMD_LOG_LEVEL=err build/systemd-repart --definitions definitions/ --dry-run=yes --empty=create --size=100M --json=pretty abc
[
        {
                "type" : "root-x86-64",
                "label" : "root-x86-64",
                "uuid" : "2f7c902c-6b2a-4b47-a44b-dca765f38cd2",
                "file" : "root.conf",
                "node" : "abc1",
                "offset" : 1048576,
                "old_size" : 0,
                "raw_size" : 103788544,
                "old_padding" : 0,
                "raw_padding" : 0,
                "activity" : "create"
        }
]
➜  systemd git:(repart-newlines)
```

src/partition/repart.c

index 893431da2a9c1a9a7af7debb7e74b6ed0a0fbcae..f377908a338f2d12dc2ced5798a2a5a8f0b1be81 100644 (file)
@@ -3460,11 +3460,12 @@ static int context_write_partition_table(
 
                 (void) context_dump_partitions(context, node);
 
-                putc('\n', stdout);
-
-                if (arg_json_format_flags & JSON_FORMAT_OFF)
+                if (arg_json_format_flags & JSON_FORMAT_OFF) {
+                        putc('\n', stdout);
                         (void) context_dump_partition_bar(context, node);
-                putc('\n', stdout);
+                        putc('\n', stdout);
+                }
+
                 fflush(stdout);
         }