From 8702ce8bbd4d1435cc81fa8fcd7f5309d3c7b003 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Tue, 18 Sep 2018 19:18:01 +0300 Subject: VC and secret dir are now stored with absolute path --- src/actionhelper.c | 2 +- src/ckutil.c | 6 +++++- src/ckutil.h | 6 ++++-- src/confparser.c | 12 +++++++----- 4 files changed, 17 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/actionhelper.c b/src/actionhelper.c index 7d6aa8a..c4c1f34 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -65,5 +65,5 @@ edit_rc edit_get_config_or_suggestions(cklist *args, char *ret) { UNUSED(args); UNUSED(ret); - return ERC_ERR; + return ERC_ERR; } diff --git a/src/ckutil.c b/src/ckutil.c index 74a6b00..880696b 100644 --- a/src/ckutil.c +++ b/src/ckutil.c @@ -10,6 +10,7 @@ * -------------------------------------------------------------------------- */ #include #include +#include #include #include #include @@ -39,11 +40,14 @@ void util_replace_slash_with_uscore(char *s) { } } -int util_file_exists(const char* path) { +int util_file_exists(const char* path, char *absPath) { struct stat st = {0}; if (stat(path, &st) == -1) { return 0; } + if (absPath != NULL) { + realpath(path, absPath); + } return 1; } diff --git a/src/ckutil.h b/src/ckutil.h index 8f5eda8..56b9cd9 100644 --- a/src/ckutil.h +++ b/src/ckutil.h @@ -65,8 +65,10 @@ extern int str_is_empty(const char *s); /* Returns 1 if path is a directory, else returns 0. */ extern int util_is_dir(const char *path); -/* Returns 1 if file(or dir) exists, else returns 0. */ -extern int util_file_exists(const char *path); +/* Returns 1 if file(or dir) exists, else returns 0. + * Pass a char array in absPath to get the absolute path + * of the file it it exists. Pass NULL if no need. */ +extern int util_file_exists(const char *path, char *absPath); /* Returns 1 if file(or dir) is readable and writable, * else returns 0. */ diff --git a/src/confparser.c b/src/confparser.c index 5754dfa..948623c 100644 --- a/src/confparser.c +++ b/src/confparser.c @@ -139,17 +139,19 @@ void free_conf(Conf *conf) { } int init_create_config_file(UserOpt *opt) { - if (!util_file_exists(list_get_at(opt->args, 0))) { + char absVCdir[STR_L]; + if (!util_file_exists(list_get_at(opt->args, 0), absVCdir)) { printf("Version control directory: %s\ndoes not exist.\n", list_get_at(opt->args, 0)); return 1; } - if (!util_file_exists(list_get_at(opt->args, 1))) { + char absSRdir[STR_L]; + if (!util_file_exists(list_get_at(opt->args, 1), absSRdir)) { printf("Secret directory: %s\ndoes not exist.\n", list_get_at(opt->args, 1)); return 1; } - if (!util_file_exists(opt->confDir)) { + if (!util_file_exists(opt->confDir, NULL)) { util_mkdir(opt->confDir); } @@ -162,12 +164,12 @@ int init_create_config_file(UserOpt *opt) { char tmp[200]; strcpy(tmp, "version_control_dir = "); - strcat(tmp, list_get_at(opt->args, 0)); + strcat(tmp, absVCdir); strcat(tmp, "\n"); fputs(tmp, f); strcpy(tmp, "secret_dir = "); - strcat(tmp, list_get_at(opt->args, 1)); + strcat(tmp, absSRdir); strcat(tmp, "\n"); fputs(tmp, f); -- cgit v1.2.3