diff options
author | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
---|---|---|
committer | gramanas <anastasis.gramm2@gmail.com> | 2018-11-17 19:49:52 +0200 |
commit | 21c92f735ff52ff98b50f7f9d8e8ab9c46dad557 (patch) | |
tree | 3b244ec29c3b3ad96fc141461bff4d141a36227a /src/delete.c | |
parent | 8eb4df24eb30353bea82268440396e50ed8b1bbc (diff) | |
download | ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.gz ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.tar.bz2 ck-21c92f735ff52ff98b50f7f9d8e8ab9c46dad557.zip |
Finish restructure and simplify include graph
Diffstat (limited to 'src/delete.c')
-rw-r--r-- | src/delete.c | 56 |
1 files changed, 53 insertions, 3 deletions
diff --git a/src/delete.c b/src/delete.c index ce7017f..00f51f8 100644 --- a/src/delete.c +++ b/src/delete.c @@ -1,8 +1,16 @@ +/* delete.c - the delete action ----------------------------------------*- C -*- + * + * This file is part of ck, the config keeper + * + * ----------------------------------------------------------------------------- + * + * Copyright (C) 2018 Anastasis Grammenos + * GPLv3 (see LICENCE for the full notice) + * + * -------------------------------------------------------------------------- */ #include <libgen.h> -#include "actions.h" #include "dblayer.h" -#include "queries.h" #include "ckerrlog.h" ERRLOG(delete); @@ -132,7 +140,7 @@ static int get_cid_from_pname_and_basename(DB *db, const char *pName, const char return _cid; } -int del_transaction_try(DB *db, const char *pName, const char *cBaseName) { +static int del_transaction_try(DB *db, const char *pName, const char *cBaseName) { __BEGIN_TRANSACTION__ int pid = -1; if (cBaseName) { @@ -174,3 +182,45 @@ int del_transaction_try(DB *db, const char *pName, const char *cBaseName) { __END_TRANSACTION__ return 0; } + +int run_DEL(UserOpt * opt, Conf *conf) { + UNUSED(conf); + DB db; + if (open_DB(&db, opt)) { + 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); + print_suggested_configs(&db, pName); + } + } + error: + close_DB(&db); + if (!rc) { + hLOG("ckdb updated succesfully."); + } else { + sERR("Could not complete delete transaction."); + } + return rc; +} + +void print_DEL_help() { + HELP("ck delete PROGRAM_NAME [CONFIG_BASENAME]"); +} |