diff options
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; |