aboutsummaryrefslogtreecommitdiffstats
path: root/src/init.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-11-16 14:43:19 +0200
committergramanas <anastasis.gramm2@gmail.com>2018-11-16 14:43:19 +0200
commit54ae271dfc5f8405233ed320b2e9bd821ee8210f (patch)
tree9b27941b0e5cc0aa5ba805e1bcb9f8d7ff965592 /src/init.c
parent97e14c73be6684259e235a92cc575ea39a04fc7e (diff)
downloadck-54ae271dfc5f8405233ed320b2e9bd821ee8210f.tar.gz
ck-54ae271dfc5f8405233ed320b2e9bd821ee8210f.tar.bz2
ck-54ae271dfc5f8405233ed320b2e9bd821ee8210f.zip
Code restructure/simplification, restore regression test
Diffstat (limited to 'src/init.c')
-rw-r--r--src/init.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/init.c b/src/init.c
new file mode 100644
index 0000000..e38a6f5
--- /dev/null
+++ b/src/init.c
@@ -0,0 +1,62 @@
+#include "actions.h"
+#include "dblayer.h"
+#include "queries.h"
+#include "ckerrlog.h"
+
+ERRLOG(init);
+
+int init_create_config_file(UserOpt *opt) {
+ char absVCdir[STR_L] = "";
+ if (!util_file_exists(list_get_at(opt->args, 0), 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 (!util_file_exists(opt->confDir, NULL)) {
+ util_mkdir(opt->confDir);
+ }
+
+ char confName[STR_L] = "";
+ make_config_name(confName, opt->confDir);
+ FILE *f;
+ if ((f = fopen(confName, "w")) == NULL) {
+ return 1;
+ }
+
+ char tmp[STR_L] = "";
+ strcpy(tmp, "version_control_dir = ");
+ strcat(tmp, absVCdir);
+ strcat(tmp, "\n");
+ fputs(tmp, f);
+
+ strcpy(tmp, "secret_dir = ");
+ strcat(tmp, absSRdir);
+ strcat(tmp, "\n");
+ fputs(tmp, f);
+
+ strcpy(tmp, "home_dir = ");
+ strcat(tmp, getenv("HOME"));
+ strcat(tmp, "\n");
+ fputs(tmp, f);
+
+ fclose(f);
+ return 0;
+}
+
+void init_make_tables(DB *db) {
+ char sql[STR_L] = "";
+ dbh_form_query_make_tables(sql);
+
+ int rc = sqlite3_exec(db->ptr, sql, 0, 0, 0);
+ if (rc != SQLITE_OK ) {
+ PRINT_ERR("Could not create empty db.");
+ db->error = SQL_ERR_SQLITE;
+ return;
+ }
+}