libalpm
Arch Linux Package Manager Library
|
00001 /* 00002 * database.c 00003 * 00004 * Copyright (c) 2006-2011 Pacman Development Team <pacman-dev@archlinux.org> 00005 * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include <stdio.h> 00022 00023 #include <alpm.h> 00024 #include <alpm_list.h> 00025 00026 /* pacman */ 00027 #include "pacman.h" 00028 #include "conf.h" 00029 #include "util.h" 00030 00031 /** 00032 * @brief Modify the 'local' package database. 00033 * 00034 * @param targets a list of packages (as strings) to modify 00035 * 00036 * @return 0 on success, 1 on failure 00037 */ 00038 int pacman_database(alpm_list_t *targets) 00039 { 00040 alpm_list_t *i; 00041 alpm_db_t *db_local; 00042 int retval = 0; 00043 alpm_pkgreason_t reason; 00044 00045 if(targets == NULL) { 00046 pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); 00047 return 1; 00048 } 00049 00050 if(config->flags & ALPM_TRANS_FLAG_ALLDEPS) { /* --asdeps */ 00051 reason = ALPM_PKG_REASON_DEPEND; 00052 } else if(config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT) { /* --asexplicit */ 00053 reason = ALPM_PKG_REASON_EXPLICIT; 00054 } else { 00055 pm_printf(ALPM_LOG_ERROR, _("no install reason specified (use -h for help)\n")); 00056 return 1; 00057 } 00058 00059 /* Lock database */ 00060 if(trans_init(0, 0) == -1) { 00061 return 1; 00062 } 00063 00064 db_local = alpm_option_get_localdb(config->handle); 00065 for(i = targets; i; i = alpm_list_next(i)) { 00066 char *pkgname = i->data; 00067 alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname); 00068 if(!pkg || alpm_db_set_pkgreason(config->handle, pkg, reason)) { 00069 pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"), 00070 pkgname, alpm_strerror(alpm_errno(config->handle))); 00071 retval = 1; 00072 } else { 00073 if(reason == ALPM_PKG_REASON_DEPEND) { 00074 printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname); 00075 } else { 00076 printf(_("%s: install reason has been set to 'explicitly installed'\n"), pkgname); 00077 } 00078 } 00079 } 00080 00081 /* Unlock database */ 00082 if(trans_release() == -1) { 00083 return 1; 00084 } 00085 return retval; 00086 } 00087 00088 /* vim: set ts=2 sw=2 noet: */