aboutsummaryrefslogtreecommitdiffstats
path: root/src/dblayer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dblayer.c')
-rw-r--r--src/dblayer.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/dblayer.c b/src/dblayer.c
index 08b1e4c..f263b86 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -331,8 +331,12 @@ int program_has_primary_config(DB *db, const int pid, char *ret, int *sec) {
return 0;
}
-int add_get_or_insert_config_to_db(DB *db, const int pid, const char *path, const int secret, const int prime) {
- int cid = get_config_id(db, path);
+int add_get_or_insert_config_to_db(DB *db, const int pid, const char *path, const int secret, const int prime, const char *home) {
+ char tpath[STR_L];
+ if (!swap_home_with_tilde(tpath, path, home)) {
+ strcpy(tpath, path);
+ }
+ int cid = get_config_id(db, tpath);
if (cid == -2) {
db->error = SQL_ERR_SQLITE;
return -1;
@@ -343,7 +347,7 @@ int add_get_or_insert_config_to_db(DB *db, const int pid, const char *path, cons
db->error = SQL_ERR_PRIMARY_REDEFINITION;
return -1;
}
- return insert_to_config_table(db, path, secret, prime);
+ return insert_to_config_table(db, tpath, secret, prime);
}
/* If it exist it means the user has inserted the same path twice */
@@ -365,7 +369,7 @@ int add_get_or_insert_program_to_db(DB *db, const char *name) {
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);
+ get_program_paths(db, baseNames, pName, 1 /*basename */, 0, NULL);
char *tmp = strdup(path);
int rc = list_exists(baseNames, basename(tmp));
free(tmp);
@@ -373,7 +377,7 @@ int add_basename_exists(DB *db, const char *pName, const char *path) {
return rc;
}
-int add_transaction_try(DB *db, const AddOpt * const opt) {
+int add_transaction_try(DB *db, const AddOpt * const opt, const char *home) {
__BEGIN_TRANSACTION__
int pid = add_get_or_insert_program_to_db(db, opt->progName);
if (db->error == SQL_ERR_SQLITE) {
@@ -384,7 +388,7 @@ int add_transaction_try(DB *db, const AddOpt * const opt) {
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);
+ int cid = add_get_or_insert_config_to_db(db, pid, opt->confPath, opt->secret, opt->prime, home);
if (db->error == SQL_ERR_SQLITE) {
PRINT_ERR("Could not insert config to db.\n");
return 1;
@@ -473,11 +477,13 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int
}
}
free(tmp);
+ break;
}
else {
+ /* Since we are here, it means there is only 1 config for the selected program */
+ flag = 0;
str_make_ck_config_name(confName, (char *)sqlite3_column_text(stmt, 0), pName);
strcpy(ret, confName);
- flag = 0;
if (sec) {
*sec = sqlite3_column_int(stmt, 1);
}
@@ -490,7 +496,7 @@ int edit_get_config(DB *db, const char *pName, char *ret, const char *cName, int
return -1;
}
-int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int attr) {
+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 */
if (pid == -2) {
@@ -527,7 +533,13 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att
strcat(entry, basename(tmp));
}
else {
- strcat(entry, tmp);
+ char tpath[STR_L] = "";
+ if (swap_tilde_with_home(tpath, tmp, home)) {
+ strcat(entry, tpath);
+ }
+ else {
+ strcat(entry, tmp);
+ }
}
if (attr) {
/* primary */
@@ -552,7 +564,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 bName, int attr) {
+int list_get_paths(DB *db, cklist *ckl, int bName, int attr, const char *home) {
sqlite3_stmt *stmt;
int rc;
@@ -571,7 +583,13 @@ int list_get_paths(DB *db, cklist *ckl, int bName, int attr) {
strcat(path, basename(tmp));
}
else {
- strcat(path, tmp);
+ char tpath[STR_L] = "";
+ if (swap_tilde_with_home(tpath, tmp, home)) {
+ strcat(path, tpath);
+ }
+ else {
+ strcat(path, tmp);
+ }
}
free(tmp);
if (attr) {
@@ -615,7 +633,7 @@ int list_get_programs(DB *db, cklist *ckl) {
return 1;
}
-int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr) {
+int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr, const char *home) {
sqlite3_stmt *stmt;
int rc;
@@ -662,7 +680,13 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr) {
strcat(treePath, basename(tmp));
}
else {
- strcat(treePath, tmp);
+ char tpath[STR_L] = "";
+ if (swap_tilde_with_home(tpath, tmp, home)) {
+ strcat(treePath, tpath);
+ }
+ else {
+ strcat(treePath, tmp);
+ }
}
free(tmp);
if (attr) {