From ac9dde072c56b9dbc3fe515dc3702c2c992f492f Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Wed, 20 May 2009 21:46:23 +0200 Subject: Introduce -D, --database The request of FS#12950 is implemented. On the backend side, I introduced a new function, alpm_db_set_pkgreason(), to modify the install reason of a package in the local database. On the front-end side, I introduced a new main operation, -D/--database, which has two options, --asdeps and --asexplicit. I documented this in pacman manual. I've created two pactests to test -D: database001.py and database002.py. Signed-off-by: Nagy Gabor Signed-off-by: Dan McGee --- src/pacman/database.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/pacman/database.c (limited to 'src/pacman/database.c') diff --git a/src/pacman/database.c b/src/pacman/database.c new file mode 100644 index 00000000..9e335fe1 --- /dev/null +++ b/src/pacman/database.c @@ -0,0 +1,90 @@ +/* + * database.c + * + * Copyright (c) 2006-2010 Pacman Development Team + * Copyright (c) 2002-2006 by Judd Vinet + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "config.h" + +#include +#include + +#include +#include + +/* pacman */ +#include "pacman.h" +#include "conf.h" +#include "util.h" + +extern pmdb_t *db_local; + +/** + * @brief Modify the 'local' package database. + * + * @param targets a list of packages (as strings) to modify + * + * @return 0 on success, 1 on failure + */ +int pacman_database(alpm_list_t *targets) +{ + alpm_list_t *i; + int retval = 0; + pmpkgreason_t reason; + + if(targets == NULL) { + pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n")); + return(1); + } + + if(config->flags & PM_TRANS_FLAG_ALLDEPS) { /* --asdeps */ + reason = PM_PKG_REASON_DEPEND; + } else if(config->flags & PM_TRANS_FLAG_ALLEXPLICIT) { /* --asexplicit */ + reason = PM_PKG_REASON_EXPLICIT; + } else { + pm_printf(PM_LOG_ERROR, _("no install reason specified (use -h for help)\n")); + return(1); + } + + /* Lock database */ + if(trans_init(0) == -1) { + return(1); + } + + for(i = targets; i; i = alpm_list_next(i)) { + char *pkgname = i->data; + if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) { + pm_printf(PM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"), + pkgname, alpm_strerrorlast()); + retval = 1; + } else { + if(reason == PM_PKG_REASON_DEPEND) { + printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname); + } else { + printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname); + } + } + } + + /* Unlock database */ + if(trans_release() == -1) { + return(1); + } + return(retval); +} + +/* vim: set ts=2 sw=2 noet: */ -- cgit v1.2.3-24-g4f1b