aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/add.c2
-rw-r--r--src/ckutil.c10
-rw-r--r--src/clparser.c2
-rw-r--r--src/clparser.h1
-rw-r--r--src/export.c48
-rw-r--r--src/restore.c2
6 files changed, 58 insertions, 7 deletions
diff --git a/src/add.c b/src/add.c
index 79227d1..c38db24 100644
--- a/src/add.c
+++ b/src/add.c
@@ -246,7 +246,7 @@ static AddOpt add_make_options(cklist *args, DB *db) {
addOpt.err = ADD_ERR_WRONG_CONFIG;
return addOpt;
}
- if (!util_is_file_link(addOpt.confPath)) {
+ if (util_is_file_link(addOpt.confPath)) {
addOpt.err = ADD_ERR_LINK_CONFIG;
return addOpt;
}
diff --git a/src/ckutil.c b/src/ckutil.c
index bc86c02..9eed9a5 100644
--- a/src/ckutil.c
+++ b/src/ckutil.c
@@ -34,7 +34,7 @@ int util_is_dir(const char *path) {
}
int util_file_exists(const char* path, char *absPath) {
- if (!path || !absPath) {
+ if (!path) {
return 0;
}
struct stat st = {0};
@@ -61,12 +61,12 @@ int util_is_file_link(const char *path) {
if (!path) {
return 0;
}
+ if (!util_file_exists(path, NULL)) {
+ return 0;
+ }
struct stat buf;
lstat(path, &buf);
- if (S_ISLNK(buf.st_mode)) {
- return 0;
- }
- return 1;
+ return S_ISLNK(buf.st_mode);
}
void util_mkdir(const char *name) {
diff --git a/src/clparser.c b/src/clparser.c
index 5b0852b..3a2a9a6 100644
--- a/src/clparser.c
+++ b/src/clparser.c
@@ -25,6 +25,7 @@ const char* const strLIST[] = {"5", "list", "ls", "l", "-l", "-ls"};
const char* const strSEARCH[] = {"4", "search", "grep", "s", "-s"};
const char* const strHELP[] = {"5", "help", "h", "-?", "-h", "--help"};
const char* const strRESTORE[] = {"3", "restore","r", "-r"};
+const char* const strEXPORT[] = {"3", "export", "ex", "--export"};
const char* const strConfDir[] = {"2", "--config", "-c"};
const char* const strVerbose1[] = {"2", "--verbose", "-v"};
const char* const strVersion[] = {"2", "version", "--version"};
@@ -276,6 +277,7 @@ static void print_parser_help() {
ckhelp("List\t%s", get_possible_action_strings(names, CKA_LIST));
ckhelp("Search\t%s", get_possible_action_strings(names, CKA_SEARCH));
ckhelp("Restore\t%s", get_possible_action_strings(names, CKA_RESTORE));
+ ckhelp("Export\t%s", get_possible_action_strings(names, CKA_EXPORT));
ckhelp("Help\t%s", get_possible_action_strings(names, CKA_HELP));
report_help();
}
diff --git a/src/clparser.h b/src/clparser.h
index afb6260..6e4cbea 100644
--- a/src/clparser.h
+++ b/src/clparser.h
@@ -29,6 +29,7 @@
X(LIST, 1, 6) \
X(SEARCH, 1, 1) \
X(RESTORE, 1, 2) \
+ X(EXPORT, 0, 0) \
X(HELP, 1, 1)
enum ParseErrors {
diff --git a/src/export.c b/src/export.c
new file mode 100644
index 0000000..b9f6aa3
--- /dev/null
+++ b/src/export.c
@@ -0,0 +1,48 @@
+/* export.c - the export action ---------------------------------------*- C -*-
+ *
+ * This file is part of ck, the config keeper
+ *
+ * -----------------------------------------------------------------------------
+ *
+ * Copyright (C) 2018 Anastasis Grammenos
+ * GPLv3 (see LICENCE for the full notice)
+ *
+ * -------------------------------------------------------------------------- */
+#include <libgen.h>
+
+#include "dblayer.h"
+#include "ckerrlog.h"
+
+ERRLOG(export);
+
+int run_EXPORT(UserOpt *opt, Conf *conf) {
+ if (system("which tar > /dev/null 2>&1") != 0) {
+ ERR("No tar avaliable. Please make sure you have tar installed.");
+ return -1;
+ }
+
+ char cmd[STR_L] = "tar -zcvf ck.tar.gz";
+ if(conf->scrt_dir) {
+ strcat(cmd, " -C ");
+ strcat(cmd, conf->scrt_dir);
+ strcat(cmd, " ../");
+ strcat(cmd, basename(conf->scrt_dir));
+ }
+ strcat(cmd, " -C ");
+ strcat(cmd, conf->vc_dir);
+ strcat(cmd, " ../");
+ strcat(cmd, basename(conf->vc_dir));
+ strcat(cmd, " -C ");
+ strcat(cmd, opt->confDir);
+ strcat(cmd, " ckrc -C ");
+ strcat(cmd, opt->confDir);
+ strcat(cmd, " ckdb");
+
+ hLOG("Running: %s", cmd);
+ strcat(cmd, " > /dev/null 2>&1");
+ return system(cmd);
+}
+
+void print_EXPORT_help() {
+ HELP("ck export");
+}
diff --git a/src/restore.c b/src/restore.c
index 3aff790..a18f906 100644
--- a/src/restore.c
+++ b/src/restore.c
@@ -23,7 +23,7 @@ static int restore_make_links(cklist *from, cklist *to) {
&& list_size(from) == list_size(to)) {
do {
if (util_file_exists(list_get(to), NULL)
- || !util_is_file_link(list_get(to))) {
+ || util_is_file_link(list_get(to))) {
ERR("File %s already exists.", list_get(to));
sERR("No links were created.");
return -1;