diff options
Diffstat (limited to 'src/actionhelper.c')
-rw-r--r-- | src/actionhelper.c | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/src/actionhelper.c b/src/actionhelper.c index 0269470..6428ab0 100644 --- a/src/actionhelper.c +++ b/src/actionhelper.c @@ -266,19 +266,25 @@ int restore_make_links(cklist *from, cklist *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))); + do { if (util_file_exists(list_get(to), NULL) || !util_is_file_link(list_get(to))) { - sERR("File %s already exists. Terminating.", list_get(to)); + ERR("File %s already exists.", list_get(to)); + sERR("No links were created."); return -1; } + } while (list_next(to)); + list_rewind(to); + while (1) { if (util_symlink_file(list_get(from), list_get(to))) { - sERR("Failed: %s -> %s", list_get(from), list_get(to)); + ERR("FATAL could not link %s -> %s", list_get(from), list_get(to)); + sERR("Process stopping."); + return -1; + } + hLOG("Linking: %s -> %s", list_get(from), list_get(to)); + if (util_own_grp_copy(list_get(to), list_get(from))) { 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; } @@ -348,11 +354,9 @@ void print_HELP_result(int err) { } void print_RESTORE_result(int err) { - if (!err) { - HELP("restore OK"); - return; + if (err == -1) { + sERR("Restore failed.") } - sERR("restore NOT OK"); } void print_INIT_help() { @@ -445,7 +449,25 @@ void print_HELP_help() { } void print_RESTORE_help() { - ckhelp("Restore help"); + ckhelp("Restore links.\n"); + ckhelp("Given a working ck instance (ckdb + ckrc + directories in ckrc with configs)"); + ckhelp("restore shall recreate the links from the config directories in ckrc"); + ckhelp("back to their corresponding position when added in ck.\n"); + ckhelp("It is useful for copying your configs to a new linux installation"); + ckhelp("or restoring deleted links.\n"); + ckhelp("It can either restore a specific program or all of them:"); + ckhelp(" `-p progName`: restores progName."); + ckhelp(" `all`: restores everything.\n"); + ckhelp("Note:\nIf ck tracks configs that are owned by root, simply running"); + ckhelp("`ck restore ...` will fail due to permissions. To remedy this, ck will alter the"); + ckhelp("owner and group of a link to match the one in the ckrc directories."); + ckhelp("Thus, running `sudo ck -c /home/myuser/.ck restore ..` will restore"); + ckhelp("the root user's links as it should and the user links will have"); + ckhelp("the user as the owner instead of the root.\n"); + ckhelp("ck checks that the configs exist and that the location for the link"); + ckhelp("is avaliable before making any links. However, in the even that symlink"); + ckhelp("fails for some other reason, the process will stop as is. Make sure you"); + ckhelp("take care of the already created links, if that's the case."); report_help(); } |