From: Karel Zak Date: Mon, 7 Sep 2020 09:52:13 +0000 (+0200) Subject: libsmartcols: don't print empty output on empty table in JSON X-Git-Tag: v2.37-rc1~495 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f29a2cfbe18ecc165f188b2df572be01a74e1ec5;p=thirdparty%2Futil-linux.git libsmartcols: don't print empty output on empty table in JSON 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 --- diff --git a/libsmartcols/src/print-api.c b/libsmartcols/src/print-api.c index 48b954baf3..9a9f2df942 100644 --- a/libsmartcols/src/print-api.c +++ b/libsmartcols/src/print-api.c @@ -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; }