2005-03-14 20:51:43 -05:00
|
|
|
/*
|
2007-12-02 15:14:14 -05:00
|
|
|
* upgrade.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2015-01-21 01:31:20 -05:00
|
|
|
* Copyright (c) 2006-2015 Pacman Development Team <pacman-dev@archlinux.org>
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2005-03-14 20:51:43 -05:00
|
|
|
* 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
|
2007-12-10 23:55:22 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2005-03-14 20:51:43 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <alpm.h>
|
2007-01-19 04:28:44 -05:00
|
|
|
#include <alpm_list.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
2007-04-25 02:21:12 -04:00
|
|
|
#include "pacman.h"
|
2005-10-28 08:20:40 -04:00
|
|
|
#include "conf.h"
|
2006-05-14 22:19:57 -04:00
|
|
|
#include "util.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-04-25 04:08:49 -04:00
|
|
|
/**
|
|
|
|
* @brief Upgrade a specified list of packages.
|
|
|
|
*
|
|
|
|
* @param targets a list of packages (as strings) to upgrade
|
|
|
|
*
|
|
|
|
* @return 0 on success, 1 on failure
|
|
|
|
*/
|
2007-04-25 02:27:16 -04:00
|
|
|
int pacman_upgrade(alpm_list_t *targets)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2014-03-11 22:29:21 -04:00
|
|
|
int retval = 0, *file_is_remote;
|
|
|
|
alpm_list_t *i;
|
|
|
|
unsigned int n, num_targets;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(targets == NULL) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2014-03-11 22:29:21 -04:00
|
|
|
num_targets = alpm_list_count(targets);
|
2011-12-22 05:19:18 -05:00
|
|
|
|
2014-03-11 22:29:21 -04:00
|
|
|
/* Check for URL targets and process them */
|
|
|
|
file_is_remote = malloc(num_targets * sizeof(int));
|
|
|
|
if(file_is_remote == NULL) {
|
|
|
|
pm_printf(ALPM_LOG_ERROR, _("memory exhausted\n"));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = targets, n = 0; i; i = alpm_list_next(i), n++) {
|
2005-03-14 20:51:43 -05:00
|
|
|
if(strstr(i->data, "://")) {
|
2011-06-07 14:15:43 -04:00
|
|
|
char *str = alpm_fetch_pkgurl(config->handle, i->data);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(str == NULL) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
|
2011-06-07 17:06:16 -04:00
|
|
|
(char *)i->data, alpm_strerror(alpm_errno(config->handle)));
|
2011-12-12 11:50:27 -05:00
|
|
|
retval = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
|
|
|
free(i->data);
|
|
|
|
i->data = str;
|
2014-03-11 22:29:21 -04:00
|
|
|
file_is_remote[n] = 1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2011-12-22 05:19:18 -05:00
|
|
|
} else {
|
2014-03-11 22:29:21 -04:00
|
|
|
file_is_remote[n] = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-12 11:50:27 -05:00
|
|
|
if(retval) {
|
2014-03-11 22:29:22 -04:00
|
|
|
goto fail_free;
|
2011-12-12 11:50:27 -05:00
|
|
|
}
|
|
|
|
|
2007-04-25 04:08:49 -04:00
|
|
|
/* Step 1: create a new transaction */
|
2011-06-08 00:08:06 -04:00
|
|
|
if(trans_init(config->flags, 1) == -1) {
|
2014-03-11 22:29:22 -04:00
|
|
|
retval = 1;
|
|
|
|
goto fail_free;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-09-19 22:09:15 -04:00
|
|
|
printf(_("loading packages...\n"));
|
2007-04-25 04:08:49 -04:00
|
|
|
/* add targets to the created transaction */
|
2014-03-11 22:29:21 -04:00
|
|
|
for(i = targets, n = 0; i; i = alpm_list_next(i), n++) {
|
2011-10-06 01:55:47 -04:00
|
|
|
const char *targ = i->data;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg;
|
2011-12-22 05:19:18 -05:00
|
|
|
alpm_siglevel_t level;
|
|
|
|
|
2014-03-11 22:29:21 -04:00
|
|
|
if(file_is_remote[n]) {
|
2011-12-22 05:19:18 -05:00
|
|
|
level = alpm_option_get_remote_file_siglevel(config->handle);
|
|
|
|
} else {
|
|
|
|
level = alpm_option_get_local_file_siglevel(config->handle);
|
|
|
|
}
|
2010-10-17 05:16:27 -04:00
|
|
|
|
2011-06-27 17:29:49 -04:00
|
|
|
if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
|
2011-06-07 17:06:16 -04:00
|
|
|
targ, alpm_strerror(alpm_errno(config->handle)));
|
2011-12-12 11:50:27 -05:00
|
|
|
retval = 1;
|
|
|
|
continue;
|
2010-10-17 05:16:27 -04:00
|
|
|
}
|
2011-06-09 17:00:55 -04:00
|
|
|
if(alpm_add_pkg(config->handle, pkg) == -1) {
|
2011-10-21 11:44:19 -04:00
|
|
|
pm_printf(ALPM_LOG_ERROR, "'%s': %s\n",
|
2011-06-07 17:06:16 -04:00
|
|
|
targ, alpm_strerror(alpm_errno(config->handle)));
|
2010-10-17 05:16:27 -04:00
|
|
|
alpm_pkg_free(pkg);
|
2011-12-12 11:50:27 -05:00
|
|
|
retval = 1;
|
|
|
|
continue;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2011-07-29 16:35:59 -04:00
|
|
|
config->explicit_adds = alpm_list_add(config->explicit_adds, pkg);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-12-12 11:50:27 -05:00
|
|
|
if(retval) {
|
2014-03-11 22:29:22 -04:00
|
|
|
goto fail_release;
|
2011-12-12 11:50:27 -05:00
|
|
|
}
|
|
|
|
|
2014-03-11 22:29:22 -04:00
|
|
|
free(file_is_remote);
|
|
|
|
|
2011-07-22 13:12:18 -04:00
|
|
|
/* now that targets are resolved, we can hand it all off to the sync code */
|
|
|
|
return sync_prepare_execute();
|
2014-03-11 22:29:22 -04:00
|
|
|
|
|
|
|
fail_release:
|
|
|
|
trans_release();
|
|
|
|
fail_free:
|
|
|
|
free(file_is_remote);
|
|
|
|
|
|
|
|
return retval;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
/* vim: set noet: */
|