aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
authorAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-10-27 00:49:06 +0300
committerAnastasis Grammenos <anastasis.gramm2@gmail.com>2018-10-27 00:49:06 +0300
commit401820e28b74e09bffdeaa25fcf6de518487a433 (patch)
treee0a6b4d0fafb4718a3eacee983e4694996f1f570 /src/actions.c
parent2e1a9e0832b53c0f03a71ba76fdd76612517d03c (diff)
downloadck-401820e28b74e09bffdeaa25fcf6de518487a433.tar.gz
ck-401820e28b74e09bffdeaa25fcf6de518487a433.tar.bz2
ck-401820e28b74e09bffdeaa25fcf6de518487a433.zip
restore
Diffstat (limited to 'src/actions.c')
-rw-r--r--src/actions.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/actions.c b/src/actions.c
index 48a4066..5220864 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -300,3 +300,66 @@ int run_HELP(UserOpt *opt, Conf *conf) {
}
return 1;
}
+
+int run_RESTORE(UserOpt *opt, Conf *conf) {
+ UNUSED(conf);
+ DB db = open_DB(opt);
+ if (db.ptr == NULL) {
+ if (db.error == SQL_ERR_NO_TABLES) {
+ ERR("The database file is currupted. Run ck init anew.");
+ }
+ return 1;
+ }
+ cklist *from = list_make_new();
+ cklist *to = list_make_new();
+ int err_flag = 0;
+ if (strcmp(list_get(opt->args), "-p") == 0) {
+ if (list_next(opt->args)) {
+ if (program_exists(&db, list_get(opt->args))) {
+ if (restore_configs_exists(&db, conf, list_get(opt->args), from, to)) {
+ HELP("Making links for %s", list_get(opt->args));
+ }
+ else {
+ err_flag = 1;
+ }
+ }
+ else {
+ ERR("Program %s does not exist", list_get(opt->args));
+ err_flag = 1;
+ }
+ }
+ else {
+ sERR("-p needs a program name");
+ err_flag = 1;
+ }
+ }
+ else if (strcmp(list_get(opt->args), "all") == 0) {
+ if (!list_next(opt->args)) {
+ if (restore_all_exist(&db, conf, from, to)) {
+ HELP("Make all links");
+ }
+ else {
+ err_flag = 1;
+ }
+ }
+ else {
+ sERR("Wrong argument");
+ err_flag = 1;
+ }
+ }
+ else {
+ sERR("Wrong argument");
+ err_flag = 1;
+ }
+ close_DB(&db);
+ if (!err_flag) {
+ HELP("LINKS");
+ int rc = restore_make_links(from, to);
+ list_free(from);
+ list_free(to);
+ return rc;
+ }
+ list_free(from);
+ list_free(to);
+ return 1;
+}