]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: don't print empty output on empty table in JSON
authorKarel Zak <kzak@redhat.com>
Mon, 7 Sep 2020 09:52:13 +0000 (11:52 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 7 Sep 2020 09:52:13 +0000 (11:52 +0200)
old version:
 $ findmnt --json --type foo
 $

new version:
 $ findmnt --json --type foo
 {
    "filesystems": [
    ]
 }

Addresses: https://github.com/karelzak/util-linux/issues/1136
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/print-api.c

index 48b954baf33313fe54817494d829179b3f33e5b1..9a9f2df9420a0aec601bfc4b1c663847c1ac2889 100644 (file)
@@ -116,7 +116,10 @@ static int do_print_table(struct libscols_table *tb, int *is_empty)
        }
        if (list_empty(&tb->tb_lines)) {
                DBG(TAB, ul_debugobj(tb, "ignore -- no lines"));
-               if (is_empty)
+               if (scols_table_is_json(tb)) {
+                       fput_table_open(tb);
+                       fput_table_close(tb);
+               } else if (is_empty)
                        *is_empty = 1;
                return 0;
        }