]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: reflect changinging SCOLS_FL_TREE after adding to table
authorIgor Gnatenko <i.gnatenko.brain@gmail.com>
Sat, 16 Jan 2016 21:51:52 +0000 (22:51 +0100)
committerIgor Gnatenko <i.gnatenko.brain@gmail.com>
Sun, 17 Jan 2016 08:44:09 +0000 (09:44 +0100)
When scols_column_set_flags() is called we will compare before & after
status of SCOLS_FL_TREE flag and appropriately handle tb->ntreecols.

Reference: https://github.com/karelzak/util-linux/issues/254
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
libsmartcols/src/column.c
libsmartcols/src/smartcolsP.h
libsmartcols/src/table.c

index 269ceea0c8529d7bf2bb4d175d80e8f0f8bc58b0..b31b39063fed0221edc7c1d50adad70a31f96f95 100644 (file)
@@ -157,6 +157,13 @@ int scols_column_set_flags(struct libscols_column *cl, int flags)
        if (!cl)
                return -EINVAL;
 
+       if (cl->table) {
+               if (!(cl->flags & SCOLS_FL_TREE) && (flags & SCOLS_FL_TREE))
+                       cl->table->ntreecols++;
+               else if ((cl->flags & SCOLS_FL_TREE) && !(flags & SCOLS_FL_TREE))
+                       cl->table->ntreecols--;
+       }
+
        cl->flags = flags;
        return 0;
 }
index 163417707e54d59a2dcf33c1c4a3512f3e6fff90..9f63c3ad1eafdbd96c096d6ba6a3433db854483a 100644 (file)
@@ -89,6 +89,8 @@ struct libscols_column {
 
        struct libscols_cell    header;
        struct list_head        cl_columns;
+
+       struct libscols_table   *table;
 };
 
 /*
index cb4cfae0d393bb1193b71f8990cee64519199a84..3360d525bc88c0683420143350ddcb631be8dfa6 100644 (file)
@@ -141,6 +141,7 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl
        DBG(TAB, ul_debugobj(tb, "add column %p", cl));
        list_add_tail(&cl->cl_columns, &tb->tb_columns);
        cl->seqnum = tb->ncols++;
+       cl->table = tb;
        scols_ref_column(cl);
 
        /* TODO:
@@ -173,6 +174,7 @@ int scols_table_remove_column(struct libscols_table *tb,
        DBG(TAB, ul_debugobj(tb, "remove column %p", cl));
        list_del_init(&cl->cl_columns);
        tb->ncols--;
+       cl->table = NULL;
        scols_unref_column(cl);
        return 0;
 }