aboutsummaryrefslogtreecommitdiffstats
path: root/src/dblayer.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-10-29 17:20:28 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-10-29 17:20:28 +0200
commit5683c51d17b5eed7d2f070aa4e49cc21b65d82e5 (patch)
treef6eea31de970bf3b5233545b7296a0d81e60836e /src/dblayer.c
parent56fdf6de6ee00f1eb4303065c26811310a7c0728 (diff)
downloadck-5683c51d17b5eed7d2f070aa4e49cc21b65d82e5.tar.gz
ck-5683c51d17b5eed7d2f070aa4e49cc21b65d82e5.tar.bz2
ck-5683c51d17b5eed7d2f070aa4e49cc21b65d82e5.zip
Add list with basename and update readme
Diffstat (limited to 'src/dblayer.c')
-rw-r--r--src/dblayer.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/dblayer.c b/src/dblayer.c
index f517dbe..244db62 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -363,6 +363,16 @@ int add_get_or_insert_program_to_db(DB *db, const char *name) {
return pid;
}
+int add_basename_exists(DB *db, const char *pName, const char *path) {
+ cklist *baseNames = list_make_new();
+ get_program_paths(db, baseNames, pName, 1 /*basename */, 0);
+ char *tmp = strdup(path);
+ int rc = list_exists(baseNames, basename(tmp));
+ free(tmp);
+ list_free(baseNames);
+ return rc;
+}
+
int add_transaction_try(DB *db, const AddOpt * const opt) {
__BEGIN_TRANSACTION__
int pid = add_get_or_insert_program_to_db(db, opt->progName);
@@ -370,6 +380,10 @@ int add_transaction_try(DB *db, const AddOpt * const opt) {
PRINT_ERR("Could not insert program to db.\n");
return 1;
}
+ if (add_basename_exists(db, opt->progName, opt->confPath)) {
+ ERR("Cannot have two configs with the same basename, for the same program.");
+ return 1;
+ }
int cid = add_get_or_insert_config_to_db(db, pid, opt->confPath, opt->secret, opt->prime);
if (db->error == SQL_ERR_SQLITE) {
PRINT_ERR("Could not insert config to db.\n");
@@ -540,7 +554,7 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att
return -1;
}
-int list_get_paths(DB *db, cklist *ckl, int attr) {
+int list_get_paths(DB *db, cklist *ckl, int bName, int attr) {
sqlite3_stmt *stmt;
int rc;
@@ -553,8 +567,15 @@ int list_get_paths(DB *db, cklist *ckl, int attr) {
}
while (sqlite3_step(stmt) == SQLITE_ROW) {
+ char *tmp = strdup((char *)sqlite3_column_text(stmt, 0));
char path[STR_L] = "";
- strcat(path, (char *)sqlite3_column_text(stmt, 0));
+ if (bName) {
+ strcat(path, basename(tmp));
+ }
+ else {
+ strcat(path, tmp);
+ }
+ free(tmp);
if (attr) {
/* secret */
if (sqlite3_column_int(stmt, 1)) {
@@ -596,7 +617,7 @@ int list_get_programs(DB *db, cklist *ckl) {
return 1;
}
-int list_get_path_program_tree(DB *db, cklist *ckl, int attr) {
+int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr) {
sqlite3_stmt *stmt;
int rc;
@@ -638,7 +659,14 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int attr) {
sqlite3_bind_text(stmt2, 1, (char *)sqlite3_column_text(stmt, 0), -1, 0);
while (sqlite3_step(stmt2) == SQLITE_ROW) {
char treePath[STR_L] = "|- ";
- strcat(treePath, (char *)sqlite3_column_text(stmt2, 0));
+ char *tmp = strdup((char *)sqlite3_column_text(stmt2, 0));
+ if (bName) {
+ strcat(treePath, basename(tmp));
+ }
+ else {
+ strcat(treePath, tmp);
+ }
+ free(tmp);
if (attr) {
/* secret */
if (sqlite3_column_int(stmt2, 1)) {