diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-11-19 19:11:06 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-11-19 19:11:06 +0200 |
commit | 78ee1c72c670a71bfd165448676fc65bff802916 (patch) | |
tree | 893b0f09dfc84f3fd7f1ac218213012f33d5b612 /src/init.c | |
parent | 84bbbb91c9154ca0b1c295eb7d1aa0de59450764 (diff) | |
download | ck-78ee1c72c670a71bfd165448676fc65bff802916.tar.gz ck-78ee1c72c670a71bfd165448676fc65bff802916.tar.bz2 ck-78ee1c72c670a71bfd165448676fc65bff802916.zip |
Add ability to use ck without secret dir
Diffstat (limited to 'src/init.c')
-rw-r--r-- | src/init.c | 45 |
1 files changed, 37 insertions, 8 deletions
@@ -15,15 +15,18 @@ ERRLOG(init); static int init_create_config_file(UserOpt *opt) { char absVCdir[STR_L] = ""; - if (!util_file_exists(list_get_at(opt->args, 0), absVCdir)) { + list_rewind(opt->args); + if (!util_file_exists(list_get(opt->args), absVCdir)) { ERR("Version control directory: %s does not exist.", list_get_at(opt->args, 0)); return 1; } char absSRdir[STR_L] = ""; - if (!util_file_exists(list_get_at(opt->args, 1), absSRdir)) { - ERR("Secret directory: %s does not exist.", list_get_at(opt->args, 1)); - return 1; + if (list_next(opt->args)) { + if (!util_file_exists(list_get_at(opt->args, 1), absSRdir)) { + ERR("Secret directory: %s does not exist.", list_get_at(opt->args, 1)); + return 1; + } } if (!util_file_exists(opt->confDir, NULL)) { @@ -43,10 +46,13 @@ static int init_create_config_file(UserOpt *opt) { strcat(tmp, "\n"); fputs(tmp, f); - strcpy(tmp, "secret_dir = "); - strcat(tmp, absSRdir); - strcat(tmp, "\n"); - fputs(tmp, f); + /* if absSRdir is not equal to "" */ + if (strcmp(absSRdir, "")) { + strcpy(tmp, "secret_dir = "); + strcat(tmp, absSRdir); + strcat(tmp, "\n"); + fputs(tmp, f); + } strcpy(tmp, "home_dir = "); strcat(tmp, getenv("HOME")); @@ -57,6 +63,27 @@ static int init_create_config_file(UserOpt *opt) { return 0; } +static int set_secret_enabled(DB *db, int enabled) { + sqlite3_stmt *stmt; + int rc; + + char sql[STR_M] = ""; + dbh_form_query_set_secret_enabled(sql); + + rc = sqlite3_prepare_v2(db->ptr, sql, -1, &stmt, 0); + if (rc != SQLITE_OK) { + ERR("while preparing set_secret_enabled sql."); + return -2; + } + sqlite3_bind_int(stmt, 1, enabled); + if (sqlite3_step(stmt) != SQLITE_DONE) { + ERR("while excecuting set_secret_enabled sql."); + return -1; + } + sqlite3_finalize(stmt); + return 0; +} + static void init_make_tables(DB *db) { char sql[STR_L] = ""; dbh_form_query_make_tables(sql); @@ -84,6 +111,8 @@ int run_INIT(UserOpt * opt, Conf *conf) { return -1; } init_make_tables(&db); + /* If there are two arguments secret is enabled */ + set_secret_enabled(&db, list_size(opt->args) == 2); sqlite3_close(db.ptr); hLOG("Initialized empty ckdb."); return 0; |