libalpm
Arch Linux Package Manager Library
|
00001 /* 00002 * upgrade.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 <stdlib.h> 00022 #include <stdio.h> 00023 #include <string.h> 00024 00025 #include <alpm.h> 00026 #include <alpm_list.h> 00027 00028 /* pacman */ 00029 #include "pacman.h" 00030 #include "conf.h" 00031 #include "util.h" 00032 00033 /** 00034 * @brief Upgrade a specified list of packages. 00035 * 00036 * @param targets a list of packages (as strings) to upgrade 00037 * 00038 * @return 0 on success, 1 on failure 00039 */ 00040 int pacman_upgrade(alpm_list_t *targets) 00041 { 00042 int retval = 0; 00043 alpm_list_t *i; 00044 alpm_siglevel_t level = alpm_option_get_default_siglevel(config->handle); 00045 00046 if(targets == NULL) { 00047 pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n")); 00048 return 1; 00049 } 00050 00051 /* Check for URL targets and process them 00052 */ 00053 for(i = targets; i; i = alpm_list_next(i)) { 00054 if(strstr(i->data, "://")) { 00055 char *str = alpm_fetch_pkgurl(config->handle, i->data); 00056 if(str == NULL) { 00057 pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", 00058 (char *)i->data, alpm_strerror(alpm_errno(config->handle))); 00059 retval = 1; 00060 } else { 00061 free(i->data); 00062 i->data = str; 00063 } 00064 } 00065 } 00066 00067 if(retval) { 00068 return retval; 00069 } 00070 00071 /* Step 1: create a new transaction */ 00072 if(trans_init(config->flags, 1) == -1) { 00073 return 1; 00074 } 00075 00076 printf(_("loading packages...\n")); 00077 /* add targets to the created transaction */ 00078 for(i = targets; i; i = alpm_list_next(i)) { 00079 const char *targ = i->data; 00080 alpm_pkg_t *pkg; 00081 00082 if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) { 00083 pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", 00084 targ, alpm_strerror(alpm_errno(config->handle))); 00085 retval = 1; 00086 continue; 00087 } 00088 if(alpm_add_pkg(config->handle, pkg) == -1) { 00089 pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", 00090 targ, alpm_strerror(alpm_errno(config->handle))); 00091 alpm_pkg_free(pkg); 00092 retval = 1; 00093 continue; 00094 } 00095 config->explicit_adds = alpm_list_add(config->explicit_adds, pkg); 00096 } 00097 00098 if(retval) { 00099 trans_release(); 00100 return retval; 00101 } 00102 00103 /* now that targets are resolved, we can hand it all off to the sync code */ 00104 return sync_prepare_execute(); 00105 } 00106 00107 /* vim: set ts=2 sw=2 noet: */