diff options
Diffstat (limited to 'src/dblayer.c')
-rw-r--r-- | src/dblayer.c | 60 |
1 files changed, 24 insertions, 36 deletions
diff --git a/src/dblayer.c b/src/dblayer.c index d3fd49e..97a93db 100644 --- a/src/dblayer.c +++ b/src/dblayer.c @@ -496,6 +496,21 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int return -1; } +static void decorate_entry(char *entry, int secret, int primary, const char *path) { + if (primary) { + strcat(entry, " [p]"); + } + + if (secret) { + strcat(entry, " [s]"); + } + /* root */ + if (util_is_link_owned_by_root(path)) { + strcat(entry, " [root]"); + } +} + + int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int attr, const char *home) { int pid = get_program_id(db, pName); /* error */ @@ -542,18 +557,9 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att } } if (attr) { - /* primary */ - if (sqlite3_column_int(stmt, 2)) { - strcat(entry, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt, 1)) { - strcat(entry, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { - strcat(entry, " [root]"); - } + decorate_entry(entry, sqlite3_column_int(stmt, 1), + sqlite3_column_int(stmt, 2), + (char *)sqlite3_column_text(stmt, 0)); } list_add(ckl, entry); free(tmp); @@ -593,18 +599,9 @@ int list_get_paths(DB *db, cklist *ckl, int bName, int attr, const char *home) { } free(tmp); if (attr) { - /* primary */ - if (sqlite3_column_int(stmt, 2)) { - strcat(path, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt, 1)) { - strcat(path, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt, 0))) { - strcat(path, " [root]"); - } + decorate_entry(path, sqlite3_column_int(stmt, 1), + sqlite3_column_int(stmt, 2), + (char *)sqlite3_column_text(stmt, 0)); } list_add(ckl, path); } @@ -690,18 +687,9 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const c } free(tmp); if (attr) { - /* primary */ - if (sqlite3_column_int(stmt2, 2)) { - strcat(treePath, " [p]"); - } - /* secret */ - if (sqlite3_column_int(stmt2, 1)) { - strcat(treePath, " [s]"); - } - /* root */ - if (util_is_link_owned_by_root((char *)sqlite3_column_text(stmt2, 0))) { - strcat(treePath, " [root]"); - } + decorate_entry(treePath, sqlite3_column_int(stmt2, 1), + sqlite3_column_int(stmt2, 2), + (char *)sqlite3_column_text(stmt2, 0)); } list_add(ckl, treePath); } |