aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2018-04-29 21:36:52 +0300
committergramanas <anastasis.gramm2@gmail.com>2018-04-29 21:36:52 +0300
commit93eae1c206796d76e930c0c4860e4ead9c8fca14 (patch)
tree239940d27be834bcd16b28d6fcd03db4a00f3072 /src/engine.c
parent25ccc84ac00a7b3975dfdb0cc415522ca7793f0f (diff)
downloadck-93eae1c206796d76e930c0c4860e4ead9c8fca14.tar.gz
ck-93eae1c206796d76e930c0c4860e4ead9c8fca14.tar.bz2
ck-93eae1c206796d76e930c0c4860e4ead9c8fca14.zip
linkin park
Diffstat (limited to 'src/engine.c')
-rw-r--r--src/engine.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/engine.c b/src/engine.c
new file mode 100644
index 0000000..3505fd0
--- /dev/null
+++ b/src/engine.c
@@ -0,0 +1,62 @@
+/* engine.c - manages the linking and copying of configs ---------------*- C -*-
+ *
+ * This file is part of ck, the config keeper
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2018 Anastasis Grammenos
+ * GPLv3 (see LICENCE for the full notice)
+ *
+ * -----------------------------------------------------------------------------
+ *
+ *
+ *
+ * -------------------------------------------------------------------------- */
+#include "engine.h"
+
+char engine_err[STR_M] = "";
+
+int engine_err_message(char *err) {
+ if (!str_is_empty(engine_err)) {
+ if (err) {
+ strcpy(err, engine_err);
+ }
+ return 1;
+ }
+ return 0;
+}
+
+int copy_config(char *path);
+
+
+void link_config(const AddOpt *opt, const char* newPath) {
+ printf("Linking %s -> %s\n", opt->confPath, newPath);
+ if (util_symlink_file(newPath, opt->confPath) != 0) {
+ strcpy(engine_err, "Could not link file.");
+ }
+}
+
+void move_config(const AddOpt *opt, const Conf *conf, char *ret) {
+ char newName[STR_M];
+ str_make_new_config_name(newName, opt->confPath, opt->progName);
+ char newPath[STR_L];
+ str_join_dirname_with_basename(newPath, opt->secret ? conf->SCRT_dir : conf->VC_dir, newName);
+ printf("Moving %s -> %s\n", opt->confPath, newPath);
+ strcpy(ret, newPath);
+ if (util_move_file(opt->confPath, newPath) != 0) {
+ strcpy(engine_err, "Could not move file.");
+ }
+}
+
+void engine_add_make_link(const AddOpt *opt,
+ const Conf *conf) {
+ char newPath[STR_L];
+ move_config(opt, conf, newPath);
+ if (engine_err_message(NULL)) {
+ return;
+ }
+ link_config(opt, newPath);
+ if (engine_err_message(NULL)) {
+ return;
+ }
+}