From 6a43f7bfdfdb693e877943490abd5839a630ad9d Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 13 Nov 2018 13:22:53 +0200 Subject: Fixed homedir with restore and updated delete --- src/actions.c | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'src/actions.c') diff --git a/src/actions.c b/src/actions.c index 990b371..5a3befe 100644 --- a/src/actions.c +++ b/src/actions.c @@ -74,27 +74,38 @@ int run_ADD(UserOpt * opt, Conf *conf) { int run_DEL(UserOpt * opt, Conf *conf) { UNUSED(conf); DB 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; + } - DelOpt delOpt = del_make_options(opt->args); - switch(delOpt.err) { - case DEL_NO_ERR: - 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; + int rc = -1; + /* Since we are here, args have to be 1 or 2 */ + char *pName = list_get(opt->args); + if (!program_exists(&db, pName)) { + ERR("Program %s doesn't exist in the database.", pName); + goto error; + } + + /* If there is no next argument */ + if (!list_next(opt->args)) { + rc = del_transaction_try(&db, pName, NULL); + } + /* If there are more arguments */ + else { + char *cName = list_get(opt->args); + rc = del_transaction_try(&db, pName, cName); + if (rc) { + HELP("Program %s doesn't have a config named %s", pName, cName); + edit_print_suggested_configs(&db, pName); } - int rc = del_transaction_try(&db, delOpt.arg, delOpt.isConf); - close_DB(&db); - return rc; - case DEL_ERR_WRONG_ARGS: - ERR("Wrong delete arguments."); - break; - case DEL_ERR_WRONG_PATH: - ERR("Path %s doesnt exist.", delOpt.arg); } - return -1; + error: + close_DB(&db); + return rc; } int run_EDIT(UserOpt *opt, Conf *conf) { @@ -309,7 +320,6 @@ int run_HELP(UserOpt *opt, Conf *conf) { } 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) { -- cgit v1.2.3