aboutsummaryrefslogtreecommitdiffstats
path: root/src/actions.c
diff options
context:
space:
mode:
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;
+}