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/>.
28 #include <alpm_list.h>
36 * @brief Upgrade a specified list of packages.
38 * @param targets a list of packages (as strings) to upgrade
40 * @return 0 on success, 1 on failure
42 int pacman_upgrade(alpm_list_t
*targets
)
44 alpm_list_t
*i
, *data
= NULL
;
48 pm_printf(PM_LOG_ERROR
, _("no targets specified (use -h for help)\n"));
52 /* Check for URL targets and process them
54 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
55 if(strstr(i
->data
, "://")) {
56 char *str
= alpm_fetch_pkgurl(i
->data
);
66 /* Step 1: create a new transaction */
67 if(trans_init(config
->flags
) == -1) {
71 /* add targets to the created transaction */
72 for(i
= targets
; i
; i
= alpm_list_next(i
)) {
73 char *targ
= alpm_list_getdata(i
);
76 if(alpm_pkg_load(targ
, 1, &pkg
) != 0) {
77 pm_fprintf(stderr
, PM_LOG_ERROR
, "'%s': %s\n",
78 targ
, alpm_strerrorlast());
82 if(alpm_add_pkg(pkg
) == -1) {
83 pm_fprintf(stderr
, PM_LOG_ERROR
, "'%s': %s\n",
84 targ
, alpm_strerrorlast());
91 /* Step 2: "compute" the transaction based on targets and flags */
92 /* TODO: No, compute nothing. This is stupid. */
93 if(alpm_trans_prepare(&data
) == -1) {
94 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to prepare transaction (%s)\n"),
97 case PM_ERR_PKG_INVALID_ARCH
:
98 for(i
= data
; i
; i
= alpm_list_next(i
)) {
99 char *pkg
= alpm_list_getdata(i
);
100 printf(_(":: package %s does not have a valid architecture\n"), pkg
);
103 case PM_ERR_UNSATISFIED_DEPS
:
104 for(i
= data
; i
; i
= alpm_list_next(i
)) {
105 pmdepmissing_t
*miss
= alpm_list_getdata(i
);
106 pmdepend_t
*dep
= alpm_miss_get_dep(miss
);
107 char *depstring
= alpm_dep_compute_string(dep
);
109 /* TODO indicate if the error was a virtual package or not:
110 * :: %s: requires %s, provided by %s
112 printf(_(":: %s: requires %s\n"), alpm_miss_get_target(miss
),
117 case PM_ERR_CONFLICTING_DEPS
:
118 for(i
= data
; i
; i
= alpm_list_next(i
)) {
119 pmconflict_t
*conflict
= alpm_list_getdata(i
);
120 const char *package1
= alpm_conflict_get_package1(conflict
);
121 const char *package2
= alpm_conflict_get_package2(conflict
);
122 const char *reason
= alpm_conflict_get_reason(conflict
);
123 /* only print reason if it contains new information */
124 if(strcmp(package1
, reason
) == 0 || strcmp(package2
, reason
) == 0) {
125 printf(_(":: %s and %s are in conflict\n"), package1
, package2
);
127 printf(_(":: %s and %s are in conflict (%s)\n"), package1
, package2
, reason
);
139 /* Step 3: perform the installation */
142 print_packages(alpm_trans_get_add());
147 /* print targets and ask user confirmation */
148 alpm_list_t
*packages
= alpm_trans_get_add();
149 if(packages
== NULL
) { /* we are done */
150 printf(_(" there is nothing to do\n"));
154 display_targets(alpm_trans_get_remove(), 0);
155 display_targets(alpm_trans_get_add(), 1);
157 int confirm
= yesno(_("Proceed with installation?"));
163 if(alpm_trans_commit(&data
) == -1) {
164 pm_fprintf(stderr
, PM_LOG_ERROR
, _("failed to commit transaction (%s)\n"),
165 alpm_strerrorlast());
168 case PM_ERR_FILE_CONFLICTS
:
169 for(i
= data
; i
; i
= alpm_list_next(i
)) {
170 pmfileconflict_t
*conflict
= alpm_list_getdata(i
);
171 switch(alpm_fileconflict_get_type(conflict
)) {
172 case PM_FILECONFLICT_TARGET
:
173 printf(_("%s exists in both '%s' and '%s'\n"),
174 alpm_fileconflict_get_file(conflict
),
175 alpm_fileconflict_get_target(conflict
),
176 alpm_fileconflict_get_ctarget(conflict
));
178 case PM_FILECONFLICT_FILESYSTEM
:
179 printf(_("%s: %s exists in filesystem\n"),
180 alpm_fileconflict_get_target(conflict
),
181 alpm_fileconflict_get_file(conflict
));
186 case PM_ERR_PKG_INVALID
:
187 case PM_ERR_DLT_INVALID
:
188 for(i
= data
; i
; i
= alpm_list_next(i
)) {
189 char *filename
= alpm_list_getdata(i
);
190 printf(_("%s is invalid or corrupted\n"), filename
);
201 if(trans_release() == -1) {
207 /* vim: set ts=2 sw=2 noet: */