From 401820e28b74e09bffdeaa25fcf6de518487a433 Mon Sep 17 00:00:00 2001 From: Anastasis Grammenos Date: Sat, 27 Oct 2018 00:49:06 +0300 Subject: restore --- src/actionhelper.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/actionhelper.c') diff --git a/src/actionhelper.c b/src/actionhelper.c index ad259a2..0269470 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -260,6 +260,36 @@ ListOpt list_make_options(cklist *args) { return listOpt; } +int restore_make_links(cklist *from, cklist *to) { + list_rewind(from); + list_rewind(to); + if (list_size(from) > 0 + && list_size(to) > 0 + && list_size(from) == list_size(to)) { + while (1) { + HELP("%s %d %d", list_get(to), util_file_exists(list_get(to), NULL), !util_is_file_link(list_get(to))); + if (util_file_exists(list_get(to), NULL) + || !util_is_file_link(list_get(to))) { + sERR("File %s already exists. Terminating.", list_get(to)); + return -1; + } + if (util_symlink_file(list_get(from), list_get(to))) { + sERR("Failed: %s -> %s", list_get(from), list_get(to)); + return -1; + } + LOG("Linking: %s -> %s", list_get(from), list_get(to)); + HELP("Linking: %s -> %s", list_get(from), list_get(to)); + if (!list_next(from)) { + break; + } + if (!list_next(to)) { + break; + } + } + } + return 0; +} + /*****************/ /* PRINT RESULTS */ /*****************/ @@ -317,6 +347,14 @@ void print_HELP_result(int err) { } } +void print_RESTORE_result(int err) { + if (!err) { + HELP("restore OK"); + return; + } + sERR("restore NOT OK"); +} + void print_INIT_help() { ckhelp("Initialize the database and create the file that holds"); ckhelp("the paths where configurations will be stored."); @@ -406,6 +444,11 @@ void print_HELP_help() { report_help(); } +void print_RESTORE_help() { + ckhelp("Restore help"); + report_help(); +} + void print_conf_help(void) { ckhelp("Set a different ck configuration directory.\n"); ckhelp("This has to be passed before any action or action argument"); -- cgit v1.2.3