Rename public functions with grp in their name
[pacman-ng.git] / src / pacman / database.c
blobb7490cea472c899626ec6516050824e8510ded45
1 /*
2 * database.c
4 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org>
5 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include <stdio.h>
25 #include <alpm.h>
26 #include <alpm_list.h>
28 /* pacman */
29 #include "pacman.h"
30 #include "conf.h"
31 #include "util.h"
33 /**
34 * @brief Modify the 'local' package database.
36 * @param targets a list of packages (as strings) to modify
38 * @return 0 on success, 1 on failure
40 int pacman_database(alpm_list_t *targets)
42 alpm_list_t *i;
43 alpm_db_t *db_local;
44 int retval = 0;
45 alpm_pkgreason_t reason;
47 if(targets == NULL) {
48 pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
49 return 1;
52 if(config->flags & PM_TRANS_FLAG_ALLDEPS) { /* --asdeps */
53 reason = PM_PKG_REASON_DEPEND;
54 } else if(config->flags & PM_TRANS_FLAG_ALLEXPLICIT) { /* --asexplicit */
55 reason = PM_PKG_REASON_EXPLICIT;
56 } else {
57 pm_printf(PM_LOG_ERROR, _("no install reason specified (use -h for help)\n"));
58 return 1;
61 /* Lock database */
62 if(trans_init(0) == -1) {
63 return 1;
66 db_local = alpm_option_get_localdb(config->handle);
67 for(i = targets; i; i = alpm_list_next(i)) {
68 char *pkgname = i->data;
69 if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) {
70 pm_printf(PM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
71 pkgname, alpm_strerror(alpm_errno(config->handle)));
72 retval = 1;
73 } else {
74 if(reason == PM_PKG_REASON_DEPEND) {
75 printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname);
76 } else {
77 printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname);
82 /* Unlock database */
83 if(trans_release() == -1) {
84 return 1;
86 return retval;
89 /* vim: set ts=2 sw=2 noet: */