aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-10 22:47:03 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-10 22:47:03 +0200
commit2638802ccd0d0776ebf1867181d4e3950a147074 (patch)
treecc535cc46c41d5dd347a7630f316cf1c84d00045 /src
parent6d77eb748a6b15b9f473ab86371bfa474898cef1 (diff)
downloadck-2638802ccd0d0776ebf1867181d4e3950a147074.tar.gz
ck-2638802ccd0d0776ebf1867181d4e3950a147074.tar.bz2
ck-2638802ccd0d0776ebf1867181d4e3950a147074.zip
Home dir
Diffstat (limited to 'src')
-rw-r--r--src/actionhelper.c5
-rw-r--r--src/ckutil.c19
-rw-r--r--src/ckutil.h3
-rw-r--r--src/confparser.h5
-rw-r--r--src/dblayer.c28
5 files changed, 35 insertions, 25 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c
index d1891c9..1d2a518 100644
--- a/src/actionhelper.c
+++ b/src/actionhelper.c
@@ -191,6 +191,11 @@ int init_create_config_file(UserOpt *opt) {
strcat(tmp, "\n");
fputs(tmp, f);
+ strcpy(tmp, "home_dir = ");
+ strcat(tmp, getenv("HOME"));
+ strcat(tmp, "\n");
+ fputs(tmp, f);
+
fclose(f);
return 0;
}
diff --git a/src/ckutil.c b/src/ckutil.c
index 5f8da98..0895677 100644
--- a/src/ckutil.c
+++ b/src/ckutil.c
@@ -143,17 +143,12 @@ int str_is_empty(const char *s) {
return 1;
}
-int swap_tilde_and_home(char *ret, const char *s) {
- if (!ret || !s) {
- return -1;
- }
- char *home = getenv("HOME");
- if (!home) {
+int swap_tilde_with_home(char *ret, const char *s, const char *home) {
+ if (!ret || !s || !home) {
return -1;
}
ulong i;
ulong homelen = strlen(home);
-
if (s[0] == '~') {
strcpy(ret, home);
for (i = 1; i < strlen(s); i++) {
@@ -162,6 +157,16 @@ int swap_tilde_and_home(char *ret, const char *s) {
return 0;
}
+ return -1;
+}
+
+int swap_home_with_tilde(char *ret, const char *s, const char *home) {
+ if (!ret || !s || !home) {
+ return -1;
+ }
+ ulong i;
+ ulong homelen = strlen(home);
+
for (i = 0; i < strlen(home); i++) {
if (s[i] != home[i]) {
return -1;
diff --git a/src/ckutil.h b/src/ckutil.h
index 72216ef..b9d94db 100644
--- a/src/ckutil.h
+++ b/src/ckutil.h
@@ -59,7 +59,8 @@ extern void str_join_dirname_with_basename(char *ret, const char *path,
* else returns 0. */
extern int str_is_empty(const char *s);
-extern int swap_tilde_and_home(char *ret, const char *s);
+extern int swap_tilde_with_home(char *ret, const char *s, const char *home);
+extern int swap_home_with_tilde(char *ret, const char *s, const char *home);
/*********************/
/* utility functions */
diff --git a/src/confparser.h b/src/confparser.h
index d7af842..3e772fc 100644
--- a/src/confparser.h
+++ b/src/confparser.h
@@ -18,9 +18,10 @@
#include "actionparser.h"
-#define CONFIG_VARIABLES_TABLE \
+#define CONFIG_VARIABLES_TABLE \
X(vc_dir, " version_control_dir = %s ", "Version Control directory") \
- X(scrt_dir, " secret_dir = %s " , "Secret directory")
+ X(scrt_dir, " secret_dir = %s " , "Secret directory") \
+ X(home_dir, " home_dir = %s " , "Home directory")
enum ConfingVariables {
CV_NO_VAL_OR_COMMENT,
diff --git a/src/dblayer.c b/src/dblayer.c
index 244db62..08b1e4c 100644
--- a/src/dblayer.c
+++ b/src/dblayer.c
@@ -420,9 +420,7 @@ int edit_get_prime_config_from_program(DB *db, char *pName, char *ret, int *secr
if (program_has_primary_config(db, pid, path, secret) == 1) {
if (!str_is_empty(path)) {
if (ret) {
- char confName[STR_M];
- str_make_ck_config_name(confName, path, pName);
- strcpy(ret, confName);
+ str_make_ck_config_name(ret, path, pName);
}
return 0;
}
@@ -532,14 +530,14 @@ int get_program_paths(DB *db, cklist *ckl, const char* pName, int bname, int att
strcat(entry, tmp);
}
if (attr) {
- /* secret */
- if (sqlite3_column_int(stmt, 1)) {
- strcat(entry, " [s]");
- }
/* 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]");
@@ -577,14 +575,14 @@ int list_get_paths(DB *db, cklist *ckl, int bName, int attr) {
}
free(tmp);
if (attr) {
- /* secret */
- if (sqlite3_column_int(stmt, 1)) {
- strcat(path, " [s]");
- }
/* 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]");
@@ -668,14 +666,14 @@ int list_get_path_program_tree(DB *db, cklist *ckl, int bName, int attr) {
}
free(tmp);
if (attr) {
- /* secret */
- if (sqlite3_column_int(stmt2, 1)) {
- strcat(treePath, " [s]");
- }
/* 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]");