From 401820e28b74e09bffdeaa25fcf6de518487a433 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Sat, 27 Oct 2018 00:49:06 +0300 Subject: restore --- src/actions.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/actions.c') 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; +} -- cgit v1.2.3