2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* sync.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2014-01-01 05:24:48 -05:00
|
|
|
* Copyright (c) 2006-2014 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>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.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
|
|
|
*/
|
|
|
|
|
2008-06-01 22:47:31 -04:00
|
|
|
#include <sys/types.h> /* off_t */
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-02-19 13:12:34 -05:00
|
|
|
#include <stdint.h> /* intmax_t */
|
2007-04-29 12:47:02 -04:00
|
|
|
#include <unistd.h>
|
2010-12-17 13:48:09 -05:00
|
|
|
#include <limits.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "sync.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "package.h"
|
|
|
|
#include "db.h"
|
|
|
|
#include "deps.h"
|
2006-01-15 10:55:16 -05:00
|
|
|
#include "conflict.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "trans.h"
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
#include "add.h"
|
2006-10-15 15:31:03 -04:00
|
|
|
#include "util.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "handle.h"
|
2005-12-26 01:40:29 -05:00
|
|
|
#include "alpm.h"
|
2008-01-22 22:36:11 -05:00
|
|
|
#include "dload.h"
|
2007-10-19 13:17:53 -04:00
|
|
|
#include "delta.h"
|
2009-07-15 13:14:01 -04:00
|
|
|
#include "remove.h"
|
2010-11-16 00:57:39 -05:00
|
|
|
#include "diskspace.h"
|
2008-12-07 12:58:24 -05:00
|
|
|
#include "signing.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2008-01-27 19:44:23 -05:00
|
|
|
/** Check for new version of pkg in sync repos
|
|
|
|
* (only the first occurrence is considered in sync)
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_sync)
|
2008-01-27 19:44:23 -05:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = NULL;
|
2008-01-27 19:44:23 -05:00
|
|
|
|
2011-06-14 11:01:08 -04:00
|
|
|
ASSERT(pkg != NULL, return NULL);
|
|
|
|
pkg->handle->pm_errno = 0;
|
|
|
|
|
2008-01-27 19:44:23 -05:00
|
|
|
for(i = dbs_sync; !spkg && i; i = i->next) {
|
2013-03-09 18:28:28 -05:00
|
|
|
alpm_db_t *db = i->data;
|
|
|
|
if(!(db->usage & ALPM_DB_USAGE_SEARCH)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
spkg = _alpm_db_get_pkgfromcache(db, pkg->name);
|
2008-01-27 19:44:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if(spkg == NULL) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(pkg->handle, ALPM_LOG_DEBUG, "'%s' not found in sync db => no upgrade\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
pkg->name);
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2008-01-27 19:44:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compare versions and see if spkg is an upgrade */
|
2009-04-13 09:08:38 -04:00
|
|
|
if(_alpm_pkg_compare_versions(spkg, pkg) > 0) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(pkg->handle, ALPM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
pkg->name, pkg->version, spkg->version);
|
2011-03-20 20:45:57 -04:00
|
|
|
return spkg;
|
2008-01-27 19:44:23 -05:00
|
|
|
}
|
2009-04-13 09:08:38 -04:00
|
|
|
/* spkg is not an upgrade */
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2008-01-27 19:44:23 -05:00
|
|
|
}
|
|
|
|
|
2011-08-18 00:39:41 -04:00
|
|
|
static int check_literal(alpm_handle_t *handle, alpm_pkg_t *lpkg,
|
|
|
|
alpm_pkg_t *spkg, int enable_downgrade)
|
|
|
|
{
|
|
|
|
/* 1. literal was found in sdb */
|
|
|
|
int cmp = _alpm_pkg_compare_versions(spkg, lpkg);
|
|
|
|
if(cmp > 0) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
|
|
|
|
lpkg->name, lpkg->version, spkg->version);
|
|
|
|
/* check IgnorePkg/IgnoreGroup */
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(handle, spkg)
|
|
|
|
|| alpm_pkg_should_ignore(handle, lpkg)) {
|
2011-08-18 00:39:41 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"),
|
|
|
|
lpkg->name, lpkg->version, spkg->version);
|
|
|
|
} else {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
|
|
|
spkg->name, spkg->version);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else if(cmp < 0) {
|
|
|
|
if(enable_downgrade) {
|
|
|
|
/* check IgnorePkg/IgnoreGroup */
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(handle, spkg)
|
|
|
|
|| alpm_pkg_should_ignore(handle, lpkg)) {
|
2011-08-18 00:39:41 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"),
|
|
|
|
lpkg->name, lpkg->version, spkg->version);
|
|
|
|
} else {
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
|
|
|
|
lpkg->name, lpkg->version, spkg->version);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alpm_db_t *sdb = alpm_pkg_get_db(spkg);
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
|
|
|
|
lpkg->name, lpkg->version, sdb->treename, spkg->version);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-08-18 00:52:28 -04:00
|
|
|
static alpm_list_t *check_replacers(alpm_handle_t *handle, alpm_pkg_t *lpkg,
|
|
|
|
alpm_db_t *sdb)
|
|
|
|
{
|
|
|
|
/* 2. search for replacers in sdb */
|
|
|
|
alpm_list_t *replacers = NULL;
|
|
|
|
alpm_list_t *k;
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
2012-08-05 06:05:42 -04:00
|
|
|
"searching for replacements for %s in %s\n",
|
|
|
|
lpkg->name, sdb->treename);
|
2011-08-18 00:52:28 -04:00
|
|
|
for(k = _alpm_db_get_pkgcache(sdb); k; k = k->next) {
|
|
|
|
int found = 0;
|
|
|
|
alpm_pkg_t *spkg = k->data;
|
|
|
|
alpm_list_t *l;
|
|
|
|
for(l = alpm_pkg_get_replaces(spkg); l; l = l->next) {
|
|
|
|
alpm_depend_t *replace = l->data;
|
2011-08-18 01:23:06 -04:00
|
|
|
/* we only want to consider literal matches at this point. */
|
|
|
|
if(_alpm_depcmp_literal(lpkg, replace)) {
|
2011-08-18 00:52:28 -04:00
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_replace_t question = {
|
|
|
|
.type = ALPM_QUESTION_REPLACE_PKG,
|
|
|
|
.replace = 0,
|
|
|
|
.oldpkg = lpkg,
|
|
|
|
.newpkg = spkg,
|
|
|
|
.newdb = sdb
|
|
|
|
};
|
2011-08-18 00:52:28 -04:00
|
|
|
alpm_pkg_t *tpkg;
|
|
|
|
/* check IgnorePkg/IgnoreGroup */
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(handle, spkg)
|
|
|
|
|| alpm_pkg_should_ignore(handle, lpkg)) {
|
2011-08-18 00:52:28 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING,
|
|
|
|
_("ignoring package replacement (%s-%s => %s-%s)\n"),
|
|
|
|
lpkg->name, lpkg->version, spkg->name, spkg->version);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(handle, &question);
|
|
|
|
if(!question.replace) {
|
2011-08-18 00:52:28 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If spkg is already in the target list, we append lpkg to spkg's
|
|
|
|
* removes list */
|
2012-08-12 06:48:53 -04:00
|
|
|
tpkg = alpm_pkg_find(handle->trans->add, spkg->name);
|
2011-08-18 00:52:28 -04:00
|
|
|
if(tpkg) {
|
|
|
|
/* sanity check, multiple repos can contain spkg->name */
|
|
|
|
if(tpkg->origin_data.db != sdb) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("cannot replace %s by %s\n"),
|
|
|
|
lpkg->name, spkg->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "appending %s to the removes list of %s\n",
|
|
|
|
lpkg->name, tpkg->name);
|
|
|
|
tpkg->removes = alpm_list_add(tpkg->removes, lpkg);
|
|
|
|
/* check the to-be-replaced package's reason field */
|
|
|
|
if(alpm_pkg_get_reason(lpkg) == ALPM_PKG_REASON_EXPLICIT) {
|
|
|
|
tpkg->reason = ALPM_PKG_REASON_EXPLICIT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* add spkg to the target list */
|
|
|
|
/* copy over reason */
|
|
|
|
spkg->reason = alpm_pkg_get_reason(lpkg);
|
|
|
|
spkg->removes = alpm_list_add(NULL, lpkg);
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"adding package %s-%s to the transaction targets\n",
|
|
|
|
spkg->name, spkg->version);
|
|
|
|
replacers = alpm_list_add(replacers, spkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return replacers;
|
|
|
|
}
|
|
|
|
|
2011-04-17 03:45:52 -04:00
|
|
|
/** Search for packages to upgrade and add them to the transaction. */
|
2011-06-28 00:04:00 -04:00
|
|
|
int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
|
2006-12-29 12:04:58 -05:00
|
|
|
{
|
2011-08-09 00:54:46 -04:00
|
|
|
alpm_list_t *i, *j;
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return -1);
|
2009-07-16 08:55:45 -04:00
|
|
|
trans = handle->trans;
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(trans != NULL, RET_ERR(handle, ALPM_ERR_TRANS_NULL, -1));
|
|
|
|
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(handle, ALPM_ERR_TRANS_NOT_INITIALIZED, -1));
|
2009-07-16 08:55:45 -04:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking for package upgrades\n");
|
2011-08-09 00:54:46 -04:00
|
|
|
for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *lpkg = i->data;
|
2007-08-24 18:10:40 -04:00
|
|
|
|
2013-11-25 11:16:47 -05:00
|
|
|
if(alpm_pkg_find(trans->remove, lpkg->name)) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is marked for removal -- skipping\n", lpkg->name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(trans->add, lpkg->name)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is already in the target list -- skipping\n", lpkg->name);
|
2007-08-24 18:10:40 -04:00
|
|
|
continue;
|
|
|
|
}
|
2006-12-29 12:04:58 -05:00
|
|
|
|
2013-03-04 03:48:10 -05:00
|
|
|
/* Search for replacers then literal (if no replacer) in each sync database. */
|
2011-08-09 00:54:46 -04:00
|
|
|
for(j = handle->dbs_sync; j; j = j->next) {
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *sdb = j->data;
|
2013-03-09 18:28:28 -05:00
|
|
|
alpm_list_t *replacers;
|
|
|
|
|
|
|
|
if(!(sdb->usage & ALPM_DB_USAGE_UPGRADE)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-04-13 09:08:38 -04:00
|
|
|
/* Check sdb */
|
2013-03-09 18:28:28 -05:00
|
|
|
replacers = check_replacers(handle, lpkg, sdb);
|
2013-03-04 03:48:10 -05:00
|
|
|
if(replacers) {
|
|
|
|
trans->add = alpm_list_join(trans->add, replacers);
|
2011-04-20 20:00:59 -04:00
|
|
|
/* jump to next local package */
|
|
|
|
break;
|
|
|
|
} else {
|
2013-03-04 03:48:10 -05:00
|
|
|
alpm_pkg_t *spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
|
|
|
|
if(spkg) {
|
2013-03-07 08:56:13 -05:00
|
|
|
if(check_literal(handle, lpkg, spkg, enable_downgrade)) {
|
2013-03-04 03:48:10 -05:00
|
|
|
trans->add = alpm_list_add(trans->add, spkg);
|
|
|
|
}
|
|
|
|
/* jump to next local package */
|
|
|
|
break;
|
2009-04-13 09:08:38 -04:00
|
|
|
}
|
2008-01-27 19:44:23 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2006-12-29 12:04:58 -05:00
|
|
|
}
|
2007-08-24 18:10:40 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2010-10-16 18:59:53 -04:00
|
|
|
/** Find group members across a list of databases.
|
|
|
|
* If a member exists in several databases, only the first database is used.
|
|
|
|
* IgnorePkg is also handled.
|
2011-06-28 00:11:43 -04:00
|
|
|
* @param dbs the list of alpm_db_t *
|
2011-09-22 17:29:03 -04:00
|
|
|
* @param name the name of the group
|
2011-06-28 09:26:39 -04:00
|
|
|
* @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free)
|
2010-10-16 18:59:53 -04:00
|
|
|
*/
|
2011-06-29 01:46:49 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
|
2010-10-16 18:59:53 -04:00
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL;
|
|
|
|
|
|
|
|
for(i = dbs; i; i = i->next) {
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db = i->data;
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_group_t *grp = alpm_db_get_group(db, name);
|
2010-10-16 18:59:53 -04:00
|
|
|
|
|
|
|
if(!grp)
|
|
|
|
continue;
|
|
|
|
|
2011-06-16 12:55:26 -04:00
|
|
|
for(j = grp->packages; j; j = j->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = j->data;
|
2010-10-16 18:59:53 -04:00
|
|
|
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(ignorelist, pkg->name)) {
|
2010-10-16 18:59:53 -04:00
|
|
|
continue;
|
|
|
|
}
|
2013-10-15 22:23:11 -04:00
|
|
|
if(alpm_pkg_should_ignore(db->handle, pkg)) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_install_ignorepkg_t question = {
|
|
|
|
.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
|
|
|
|
.install = 0,
|
|
|
|
.pkg = pkg
|
|
|
|
};
|
2010-10-16 18:59:53 -04:00
|
|
|
ignorelist = alpm_list_add(ignorelist, pkg);
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(db->handle, &question);
|
|
|
|
if(!question.install)
|
2010-10-16 18:59:53 -04:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-12 06:48:53 -04:00
|
|
|
if(!alpm_pkg_find(pkgs, pkg->name)) {
|
2010-10-16 18:59:53 -04:00
|
|
|
pkgs = alpm_list_add(pkgs, pkg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alpm_list_free(ignorelist);
|
2011-03-20 20:45:57 -04:00
|
|
|
return pkgs;
|
2010-10-16 18:59:53 -04:00
|
|
|
}
|
|
|
|
|
2008-02-16 11:47:22 -05:00
|
|
|
/** Compute the size of the files that will be downloaded to install a
|
|
|
|
* package.
|
|
|
|
* @param newpkg the new package to upgrade to
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static int compute_download_size(alpm_pkg_t *newpkg)
|
2008-02-16 11:47:22 -05:00
|
|
|
{
|
2011-09-07 16:01:43 -04:00
|
|
|
const char *fname;
|
|
|
|
char *fpath, *fnamepart = NULL;
|
2008-06-01 22:47:31 -04:00
|
|
|
off_t size = 0;
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_handle_t *handle = newpkg->handle;
|
2011-10-18 10:46:47 -04:00
|
|
|
int ret = 0;
|
2008-02-16 11:47:22 -05:00
|
|
|
|
2012-04-01 01:37:19 -04:00
|
|
|
if(newpkg->origin != ALPM_PKG_FROM_SYNCDB) {
|
2010-05-05 18:07:37 -04:00
|
|
|
newpkg->infolevel |= INFRQ_DSIZE;
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
newpkg->download_size = 0;
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
}
|
|
|
|
|
2011-09-02 23:07:06 -04:00
|
|
|
ASSERT(newpkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
2011-09-07 16:01:43 -04:00
|
|
|
fname = newpkg->filename;
|
|
|
|
fpath = _alpm_filecache_find(handle, fname);
|
2008-04-26 14:03:53 -04:00
|
|
|
|
2011-09-07 16:01:43 -04:00
|
|
|
/* downloaded file exists, so there's nothing to grab */
|
2008-02-16 11:47:22 -05:00
|
|
|
if(fpath) {
|
|
|
|
size = 0;
|
2011-09-07 16:01:43 -04:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
|
|
|
CALLOC(fnamepart, strlen(fname) + 6, sizeof(char), return -1);
|
|
|
|
sprintf(fnamepart, "%s.part", fname);
|
|
|
|
fpath = _alpm_filecache_find(handle, fnamepart);
|
|
|
|
if(fpath) {
|
|
|
|
struct stat st;
|
|
|
|
if(stat(fpath, &st) == 0) {
|
|
|
|
/* subtract the size of the .part file */
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using (package - .part) size\n");
|
|
|
|
size = newpkg->size - st.st_size;
|
|
|
|
size = size < 0 ? 0 : size;
|
|
|
|
}
|
2011-10-18 10:46:47 -04:00
|
|
|
|
|
|
|
/* tell the caller that we have a partial */
|
|
|
|
ret = 1;
|
2012-01-11 16:39:52 -05:00
|
|
|
} else if(handle->deltaratio > 0.0) {
|
2008-06-01 22:47:31 -04:00
|
|
|
off_t dltsize;
|
2008-02-16 11:47:22 -05:00
|
|
|
|
2011-09-02 23:07:06 -04:00
|
|
|
dltsize = _alpm_shortest_delta_path(handle, newpkg->deltas,
|
|
|
|
newpkg->filename, &newpkg->delta_path);
|
2008-02-16 11:47:22 -05:00
|
|
|
|
2012-01-11 16:39:52 -05:00
|
|
|
if(newpkg->delta_path && (dltsize < newpkg->size * handle->deltaratio)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using delta size\n");
|
2008-02-16 11:47:22 -05:00
|
|
|
size = dltsize;
|
|
|
|
} else {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "using package size\n");
|
2011-09-02 20:26:07 -04:00
|
|
|
size = newpkg->size;
|
2008-02-16 11:47:22 -05:00
|
|
|
alpm_list_free(newpkg->delta_path);
|
|
|
|
newpkg->delta_path = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2011-09-02 20:26:07 -04:00
|
|
|
size = newpkg->size;
|
2008-02-16 11:47:22 -05:00
|
|
|
}
|
|
|
|
|
2011-09-07 16:01:43 -04:00
|
|
|
finish:
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
(intmax_t)size, newpkg->name);
|
2008-02-16 11:47:22 -05:00
|
|
|
|
2010-05-05 18:07:37 -04:00
|
|
|
newpkg->infolevel |= INFRQ_DSIZE;
|
2008-02-16 11:47:22 -05:00
|
|
|
newpkg->download_size = size;
|
2011-09-07 16:01:43 -04:00
|
|
|
|
|
|
|
FREE(fpath);
|
|
|
|
FREE(fnamepart);
|
|
|
|
|
2011-10-18 10:46:47 -04:00
|
|
|
return ret;
|
2008-02-16 11:47:22 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-07 17:06:16 -04:00
|
|
|
alpm_list_t *i, *j;
|
2007-01-19 04:28:44 -05:00
|
|
|
alpm_list_t *deps = NULL;
|
2009-01-26 07:48:39 -05:00
|
|
|
alpm_list_t *unresolvable = NULL;
|
2014-01-13 23:01:44 -05:00
|
|
|
int from_sync = 0;
|
2006-03-04 05:16:36 -05:00
|
|
|
int ret = 0;
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2005-04-08 15:37:23 -04:00
|
|
|
|
2006-01-07 13:25:28 -05:00
|
|
|
if(data) {
|
|
|
|
*data = NULL;
|
|
|
|
}
|
2005-04-06 17:01:40 -04:00
|
|
|
|
2011-11-15 10:12:18 -05:00
|
|
|
for(i = trans->add; i; i = i->next) {
|
|
|
|
alpm_pkg_t *spkg = i->data;
|
2014-01-13 23:01:44 -05:00
|
|
|
if (spkg->origin == ALPM_PKG_FROM_SYNCDB){
|
|
|
|
from_sync = 1;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-15 10:12:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure all sync database are valid if we will be using them */
|
2011-06-08 00:08:06 -04:00
|
|
|
for(i = handle->dbs_sync; i; i = i->next) {
|
|
|
|
const alpm_db_t *db = i->data;
|
2011-08-17 22:06:04 -04:00
|
|
|
if(db->status & DB_STATUS_INVALID) {
|
2011-06-08 00:08:06 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_DB_INVALID, -1);
|
|
|
|
}
|
2011-11-15 10:12:18 -05:00
|
|
|
/* missing databases are not allowed if we have sync targets */
|
|
|
|
if(from_sync && db->status & DB_STATUS_MISSING) {
|
2011-08-17 22:06:04 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_DB_NOT_FOUND, -1);
|
|
|
|
}
|
2011-06-08 00:08:06 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
2011-11-15 10:12:18 -05:00
|
|
|
alpm_list_t *resolved = NULL;
|
|
|
|
alpm_list_t *remove = NULL;
|
|
|
|
alpm_list_t *localpkgs;
|
2009-03-07 13:44:34 -05:00
|
|
|
|
2009-01-26 07:48:39 -05:00
|
|
|
/* Build up list by repeatedly resolving each transaction package */
|
2005-04-13 15:59:04 -04:00
|
|
|
/* Resolve targets dependencies */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_RESOLVEDEPS_START;
|
|
|
|
EVENT(handle, &event);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "resolving target's dependencies\n");
|
2007-08-12 16:26:54 -04:00
|
|
|
|
2009-09-12 14:50:03 -04:00
|
|
|
/* build remove list for resolvedeps */
|
2009-07-15 13:14:01 -04:00
|
|
|
for(i = trans->add; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
2009-03-07 13:44:34 -05:00
|
|
|
for(j = spkg->removes; j; j = j->next) {
|
2008-01-27 06:24:50 -05:00
|
|
|
remove = alpm_list_add(remove, j->data);
|
2007-08-12 16:26:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-21 10:02:03 -04:00
|
|
|
/* Compute the fake local database for resolvedeps (partial fix for the
|
|
|
|
* phonon/qt issue) */
|
2011-11-15 10:12:18 -05:00
|
|
|
localpkgs = alpm_list_diff(_alpm_db_get_pkgcache(handle->db_local),
|
2011-03-21 10:02:03 -04:00
|
|
|
trans->add, _alpm_pkg_cmp);
|
2010-05-16 20:33:28 -04:00
|
|
|
|
2011-02-25 08:51:58 -05:00
|
|
|
/* Resolve packages in the transaction one at a time, in addition
|
2009-01-26 07:48:39 -05:00
|
|
|
building up a list of packages which could not be resolved. */
|
2009-07-15 13:14:01 -04:00
|
|
|
for(i = trans->add; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = i->data;
|
2011-06-07 15:05:42 -04:00
|
|
|
if(_alpm_resolvedeps(handle, localpkgs, pkg, trans->add,
|
2009-03-08 16:56:13 -04:00
|
|
|
&resolved, remove, data) == -1) {
|
2009-01-26 07:48:39 -05:00
|
|
|
unresolvable = alpm_list_add(unresolvable, pkg);
|
|
|
|
}
|
2009-03-07 13:44:34 -05:00
|
|
|
/* Else, [resolved] now additionally contains [pkg] and all of its
|
2009-01-26 07:48:39 -05:00
|
|
|
dependencies not already on the list */
|
|
|
|
}
|
2010-05-16 20:33:28 -04:00
|
|
|
alpm_list_free(localpkgs);
|
2011-11-15 10:12:18 -05:00
|
|
|
alpm_list_free(remove);
|
2009-01-26 07:48:39 -05:00
|
|
|
|
2009-02-22 05:25:31 -05:00
|
|
|
/* If there were unresolvable top-level packages, prompt the user to
|
|
|
|
see if they'd like to ignore them rather than failing the sync */
|
2009-01-26 07:48:39 -05:00
|
|
|
if(unresolvable != NULL) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_remove_pkgs_t question = {
|
|
|
|
.type = ALPM_QUESTION_REMOVE_PKGS,
|
|
|
|
.skip = 0,
|
|
|
|
.packages = unresolvable
|
|
|
|
};
|
|
|
|
QUESTION(handle, &question);
|
|
|
|
if(question.skip) {
|
2009-02-22 05:25:31 -05:00
|
|
|
/* User wants to remove the unresolvable packages from the
|
2009-03-07 10:25:29 -05:00
|
|
|
transaction. The packages will be removed from the actual
|
|
|
|
transaction when the transaction packages are replaced with a
|
2009-02-22 05:25:31 -05:00
|
|
|
dependency-reordered list below */
|
2011-11-15 10:12:18 -05:00
|
|
|
handle->pm_errno = 0;
|
2009-03-07 10:25:29 -05:00
|
|
|
if(data) {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(*data,
|
|
|
|
(alpm_list_fn_free)alpm_depmissing_free);
|
2009-03-07 10:25:29 -05:00
|
|
|
alpm_list_free(*data);
|
|
|
|
*data = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-15 10:12:18 -05:00
|
|
|
/* pm_errno was set by resolvedeps, callback may have overwrote it */
|
2014-01-06 11:52:24 -05:00
|
|
|
handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
|
2009-03-07 13:44:34 -05:00
|
|
|
alpm_list_free(resolved);
|
2014-02-06 20:49:07 -05:00
|
|
|
alpm_list_free(unresolvable);
|
2009-02-22 05:25:31 -05:00
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2005-04-02 18:21:10 -05:00
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2009-03-07 13:44:34 -05:00
|
|
|
/* Set DEPEND reason for pulled packages */
|
|
|
|
for(i = resolved; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = i->data;
|
2012-08-12 06:48:53 -04:00
|
|
|
if(!alpm_pkg_find(trans->add, pkg->name)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
pkg->reason = ALPM_PKG_REASON_DEPEND;
|
2005-04-08 15:37:23 -04:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2011-09-28 02:53:43 -04:00
|
|
|
/* Unresolvable packages will be removed from the target list; set these
|
|
|
|
* aside in the transaction as a list we won't operate on. If we free them
|
|
|
|
* before the end of the transaction, we may kill pointers the frontend
|
|
|
|
* holds to package objects. */
|
|
|
|
trans->unresolvable = unresolvable;
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
alpm_list_free(trans->add);
|
2013-10-17 23:38:58 -04:00
|
|
|
trans->add = resolved;
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_RESOLVEDEPS_DONE;
|
|
|
|
EVENT(handle, &event);
|
2006-03-04 05:16:36 -05:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NOCONFLICTS)) {
|
2006-03-04 05:16:36 -05:00
|
|
|
/* check for inter-conflicts and whatnot */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_INTERCONFLICTS_START;
|
|
|
|
EVENT(handle, &event);
|
2006-03-04 05:16:36 -05:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for conflicts\n");
|
2005-04-17 16:09:06 -04:00
|
|
|
|
2007-08-12 18:17:32 -04:00
|
|
|
/* 1. check for conflicts in the target list */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "check targets vs targets\n");
|
2011-06-07 14:53:53 -04:00
|
|
|
deps = _alpm_innerconflicts(handle, trans->add);
|
2007-08-12 18:17:32 -04:00
|
|
|
|
|
|
|
for(i = deps; i; i = i->next) {
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *conflict = i->data;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *rsync, *sync, *sync1, *sync2;
|
2007-08-12 18:17:32 -04:00
|
|
|
|
|
|
|
/* have we already removed one of the conflicting targets? */
|
2012-08-12 06:48:53 -04:00
|
|
|
sync1 = alpm_pkg_find(trans->add, conflict->package1);
|
|
|
|
sync2 = alpm_pkg_find(trans->add, conflict->package2);
|
2007-08-12 18:17:32 -04:00
|
|
|
if(!sync1 || !sync2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "conflicting packages in the sync list: '%s' <-> '%s'\n",
|
2007-08-12 18:17:32 -04:00
|
|
|
conflict->package1, conflict->package2);
|
|
|
|
|
|
|
|
/* if sync1 provides sync2, we remove sync2 from the targets, and vice versa */
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *dep1 = _alpm_splitdep(conflict->package1);
|
|
|
|
alpm_depend_t *dep2 = _alpm_splitdep(conflict->package2);
|
2010-10-12 15:47:40 -04:00
|
|
|
if(_alpm_depcmp(sync1, dep2)) {
|
2007-08-12 18:17:32 -04:00
|
|
|
rsync = sync2;
|
|
|
|
sync = sync1;
|
2010-10-12 15:47:40 -04:00
|
|
|
} else if(_alpm_depcmp(sync2, dep1)) {
|
2007-08-12 18:17:32 -04:00
|
|
|
rsync = sync1;
|
|
|
|
sync = sync2;
|
|
|
|
} else {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_CONFLICTING_DEPS;
|
2007-08-12 18:17:32 -04:00
|
|
|
ret = -1;
|
2008-01-25 15:52:35 -05:00
|
|
|
if(data) {
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *newconflict = _alpm_conflict_dup(conflict);
|
2008-01-25 15:52:35 -05:00
|
|
|
if(newconflict) {
|
|
|
|
*data = alpm_list_add(*data, newconflict);
|
|
|
|
}
|
|
|
|
}
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
|
2008-01-25 15:52:35 -05:00
|
|
|
alpm_list_free(deps);
|
Cleanup usages of alpm_list_find and alpm_list_remove.
* remove obsolete and unused *_cmp helper functions like deppkg_cmp and
_alpm_grp_cmp
* new alpm_list_remove_str function, used 6 times in handle.c
* remove _alpm_prov_cmp / _alpm_db_whatprovides and replace them by
a more general alpm_find_pkg_satisfiers with a cleaner implementation.
before: alpm_db_whatprovides(db, targ)
after: alpm_find_pkg_satisfiers(alpm_db_getpkgcache(db), targ)
* remove satisfycmp and replace alpm_list_find + satisfycmp usage by
_alpm_find_dep_satisfiers.
before : alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)
after : _alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)
* remove _alpm_pkgname_pkg_cmp, which was used with alpm_list_remove, and
use _alpm_pkg_find + alpm_list_remove with _alpm_pkg_cmp instead.
This commit actually get rids of all complicated and asymmetric _cmp
functions. I first thought these functions were worth it, be caused it
allowed us to reuse list_find and list_remove. But this was at the detriment
of the clarity and also the ease of use of these functions, dangerous
because of their asymmetricity.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-10 12:47:42 -04:00
|
|
|
_alpm_dep_free(dep1);
|
|
|
|
_alpm_dep_free(dep2);
|
2007-08-12 18:17:32 -04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
Cleanup usages of alpm_list_find and alpm_list_remove.
* remove obsolete and unused *_cmp helper functions like deppkg_cmp and
_alpm_grp_cmp
* new alpm_list_remove_str function, used 6 times in handle.c
* remove _alpm_prov_cmp / _alpm_db_whatprovides and replace them by
a more general alpm_find_pkg_satisfiers with a cleaner implementation.
before: alpm_db_whatprovides(db, targ)
after: alpm_find_pkg_satisfiers(alpm_db_getpkgcache(db), targ)
* remove satisfycmp and replace alpm_list_find + satisfycmp usage by
_alpm_find_dep_satisfiers.
before : alpm_list_find(_alpm_db_get_pkgcache(db), dep, satisfycmp)
after : _alpm_find_dep_satisfiers(_alpm_db_get_pkgcache(db), dep)
* remove _alpm_pkgname_pkg_cmp, which was used with alpm_list_remove, and
use _alpm_pkg_find + alpm_list_remove with _alpm_pkg_cmp instead.
This commit actually get rids of all complicated and asymmetric _cmp
functions. I first thought these functions were worth it, be caused it
allowed us to reuse list_find and list_remove. But this was at the detriment
of the clarity and also the ease of use of these functions, dangerous
because of their asymmetricity.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2008-05-10 12:47:42 -04:00
|
|
|
_alpm_dep_free(dep1);
|
|
|
|
_alpm_dep_free(dep2);
|
2007-08-12 18:17:32 -04:00
|
|
|
|
2008-03-10 10:38:08 -04:00
|
|
|
/* Prints warning */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING,
|
2008-03-10 10:38:08 -04:00
|
|
|
_("removing '%s' from target list because it conflicts with '%s'\n"),
|
2009-03-07 13:44:34 -05:00
|
|
|
rsync->name, sync->name);
|
2009-07-15 13:14:01 -04:00
|
|
|
trans->add = alpm_list_remove(trans->add, rsync, _alpm_pkg_cmp, NULL);
|
2011-09-28 02:53:43 -04:00
|
|
|
/* rsync is not a transaction target anymore */
|
|
|
|
trans->unresolvable = alpm_list_add(trans->unresolvable, rsync);
|
2007-08-12 18:17:32 -04:00
|
|
|
}
|
|
|
|
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
|
2007-08-12 18:17:32 -04:00
|
|
|
alpm_list_free(deps);
|
|
|
|
deps = NULL;
|
|
|
|
|
|
|
|
/* 2. we check for target vs db conflicts (and resolve)*/
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "check targets vs db and db vs targets\n");
|
2011-06-07 17:06:16 -04:00
|
|
|
deps = _alpm_outerconflicts(handle->db_local, trans->add);
|
2007-08-12 18:17:32 -04:00
|
|
|
|
|
|
|
for(i = deps; i; i = i->next) {
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_conflict_t question = {
|
|
|
|
.type = ALPM_QUESTION_CONFLICT_PKG,
|
|
|
|
.remove = 0,
|
|
|
|
.conflict = i->data
|
|
|
|
};
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *conflict = i->data;
|
2013-02-13 18:54:28 -05:00
|
|
|
int found = 0;
|
2007-08-12 18:17:32 -04:00
|
|
|
|
|
|
|
/* if conflict->package2 (the local package) is not elected for removal,
|
|
|
|
we ask the user */
|
2014-03-03 18:29:08 -05:00
|
|
|
if(alpm_pkg_find(trans->remove, conflict->package2)) {
|
|
|
|
found = 1;
|
|
|
|
}
|
2009-07-15 13:14:01 -04:00
|
|
|
for(j = trans->add; j && !found; j = j->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = j->data;
|
2012-08-12 06:48:53 -04:00
|
|
|
if(alpm_pkg_find(spkg->removes, conflict->package2)) {
|
2008-01-27 06:24:50 -05:00
|
|
|
found = 1;
|
2006-01-17 16:18:33 -05:00
|
|
|
}
|
2007-08-12 18:17:32 -04:00
|
|
|
}
|
|
|
|
if(found) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "package '%s' conflicts with '%s'\n",
|
2007-08-12 18:17:32 -04:00
|
|
|
conflict->package1, conflict->package2);
|
|
|
|
|
2014-06-15 13:42:40 -04:00
|
|
|
QUESTION(handle, &question);
|
|
|
|
if(question.remove) {
|
2008-01-27 06:24:50 -05:00
|
|
|
/* append to the removes list */
|
2013-02-13 18:54:28 -05:00
|
|
|
alpm_pkg_t *sync = alpm_pkg_find(trans->add, conflict->package1);
|
|
|
|
alpm_pkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, conflict->package2);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "electing '%s' for removal\n", conflict->package2);
|
2008-01-27 06:24:50 -05:00
|
|
|
sync->removes = alpm_list_add(sync->removes, local);
|
2007-08-12 18:17:32 -04:00
|
|
|
} else { /* abort */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_CONFLICTING_DEPS;
|
2008-01-25 15:52:35 -05:00
|
|
|
ret = -1;
|
Fix several memleaks, mostly related to errors handling.
* The frontend calls alpm_trans_prepare(&data), and in case of errors,
receive the missing dependencies / conflicts / etc in the data pointer.
It apparently needs to free this structure totally with :
alpm_list_free_inner(data, free)
alpm_list_free(data)
So I added alpm_list_free_inner(data, free) in
pacman/{sync.c,remove.c,add,c}
* in _alpm_sync_prepare, the deps and asked lists were not freed in case
of errors (unresolvable conflicts).
Besides the code for handling this case was duplicated.
* in _alpm_remove_commit, free was used instead of alpm_list_free for
newfiles.
* newline fix in pacman/sync.c
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-21 13:51:46 -05:00
|
|
|
if(data) {
|
2011-06-28 00:33:55 -04:00
|
|
|
alpm_conflict_t *newconflict = _alpm_conflict_dup(conflict);
|
2008-01-25 15:52:35 -05:00
|
|
|
if(newconflict) {
|
|
|
|
*data = alpm_list_add(*data, newconflict);
|
Fix several memleaks, mostly related to errors handling.
* The frontend calls alpm_trans_prepare(&data), and in case of errors,
receive the missing dependencies / conflicts / etc in the data pointer.
It apparently needs to free this structure totally with :
alpm_list_free_inner(data, free)
alpm_list_free(data)
So I added alpm_list_free_inner(data, free) in
pacman/{sync.c,remove.c,add,c}
* in _alpm_sync_prepare, the deps and asked lists were not freed in case
of errors (unresolvable conflicts).
Besides the code for handling this case was duplicated.
* in _alpm_remove_commit, free was used instead of alpm_list_free for
newfiles.
* newline fix in pacman/sync.c
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
2007-11-21 13:51:46 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
|
2008-01-11 01:01:58 -05:00
|
|
|
alpm_list_free(deps);
|
2006-03-04 05:16:36 -05:00
|
|
|
goto cleanup;
|
2005-04-17 16:09:06 -04:00
|
|
|
}
|
2005-04-06 17:01:40 -04:00
|
|
|
}
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_INTERCONFLICTS_DONE;
|
|
|
|
EVENT(handle, &event);
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(deps, (alpm_list_fn_free)alpm_conflict_free);
|
2007-08-12 18:17:32 -04:00
|
|
|
alpm_list_free(deps);
|
2006-03-04 05:16:36 -05:00
|
|
|
}
|
2005-04-13 15:59:04 -04:00
|
|
|
|
2009-09-12 14:50:03 -04:00
|
|
|
/* Build trans->remove list */
|
|
|
|
for(i = trans->add; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
2009-09-12 14:50:03 -04:00
|
|
|
for(j = spkg->removes; j; j = j->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *rpkg = j->data;
|
2012-08-12 06:48:53 -04:00
|
|
|
if(!alpm_pkg_find(trans->remove, rpkg->name)) {
|
2011-08-19 12:06:55 -04:00
|
|
|
alpm_pkg_t *copy;
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "adding '%s' to remove list\n", rpkg->name);
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_pkg_dup(rpkg, ©) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
trans->remove = alpm_list_add(trans->remove, copy);
|
2011-03-21 09:59:59 -04:00
|
|
|
}
|
2006-01-05 15:53:41 -05:00
|
|
|
}
|
2009-09-12 14:50:03 -04:00
|
|
|
}
|
2007-08-12 16:26:54 -04:00
|
|
|
|
2011-07-01 12:01:39 -04:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_NODEPS)) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking dependencies\n");
|
2011-06-07 15:05:42 -04:00
|
|
|
deps = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
|
|
|
|
trans->remove, trans->add, 1);
|
2007-08-12 16:26:54 -04:00
|
|
|
if(deps) {
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
|
2007-08-12 16:26:54 -04:00
|
|
|
ret = -1;
|
2007-12-22 10:57:43 -05:00
|
|
|
if(data) {
|
|
|
|
*data = deps;
|
|
|
|
} else {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(deps,
|
|
|
|
(alpm_list_fn_free)alpm_depmissing_free);
|
2007-08-12 18:17:32 -04:00
|
|
|
alpm_list_free(deps);
|
2007-12-22 10:57:43 -05:00
|
|
|
}
|
2007-08-12 16:26:54 -04:00
|
|
|
goto cleanup;
|
2006-01-05 15:53:41 -05:00
|
|
|
}
|
|
|
|
}
|
2009-07-15 13:14:01 -04:00
|
|
|
for(i = trans->add; i; i = i->next) {
|
2008-02-16 11:47:22 -05:00
|
|
|
/* update download size field */
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
2011-10-18 10:46:47 -04:00
|
|
|
if(compute_download_size(spkg) < 0) {
|
2008-04-26 14:03:53 -04:00
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-02-16 11:47:22 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-03-04 05:16:36 -05:00
|
|
|
cleanup:
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-10-19 13:17:54 -04:00
|
|
|
/** Returns the size of the files that will be downloaded to install a
|
|
|
|
* package.
|
|
|
|
* @param newpkg the new package to upgrade to
|
|
|
|
* @return the size of the download
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
off_t SYMEXPORT alpm_pkg_download_size(alpm_pkg_t *newpkg)
|
2007-10-19 13:17:54 -04:00
|
|
|
{
|
2010-05-05 18:07:37 -04:00
|
|
|
if(!(newpkg->infolevel & INFRQ_DSIZE)) {
|
|
|
|
compute_download_size(newpkg);
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return newpkg->download_size;
|
2007-10-19 13:17:54 -04:00
|
|
|
}
|
|
|
|
|
2009-04-11 15:13:03 -04:00
|
|
|
static int endswith(const char *filename, const char *extension)
|
2009-02-19 13:12:34 -05:00
|
|
|
{
|
2009-04-11 15:13:03 -04:00
|
|
|
const char *s = filename + strlen(filename) - strlen(extension);
|
2011-03-20 20:45:57 -04:00
|
|
|
return strcmp(s, extension) == 0;
|
2009-02-19 13:12:34 -05:00
|
|
|
}
|
|
|
|
|
2007-10-19 13:17:53 -04:00
|
|
|
/** Applies delta files to create an upgraded package file.
|
|
|
|
*
|
|
|
|
* All intermediate files are deleted, leaving only the starting and
|
|
|
|
* ending package files.
|
|
|
|
*
|
2011-06-07 14:15:43 -04:00
|
|
|
* @param handle the context handle
|
2007-10-19 13:17:53 -04:00
|
|
|
*
|
|
|
|
* @return 0 if all delta files were able to be applied, 1 otherwise.
|
|
|
|
*/
|
2011-06-28 00:04:00 -04:00
|
|
|
static int apply_deltas(alpm_handle_t *handle)
|
2007-10-19 13:17:53 -04:00
|
|
|
{
|
2008-02-27 10:09:49 -05:00
|
|
|
alpm_list_t *i;
|
2014-02-22 20:41:40 -05:00
|
|
|
size_t deltas_found = 0;
|
|
|
|
int ret = 0;
|
2011-06-07 14:15:43 -04:00
|
|
|
const char *cachedir = _alpm_filecache_setup(handle);
|
2011-06-28 09:27:16 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_delta_patch_t event;
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2009-07-15 13:14:01 -04:00
|
|
|
for(i = trans->add; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
2008-02-27 10:09:49 -05:00
|
|
|
alpm_list_t *delta_path = spkg->delta_path;
|
|
|
|
alpm_list_t *dlts = NULL;
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2008-02-27 10:09:49 -05:00
|
|
|
if(!delta_path) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2011-09-01 17:00:48 -04:00
|
|
|
if(!deltas_found) {
|
|
|
|
/* only show this if we actually have deltas to apply, and it is before
|
|
|
|
* the very first one */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_PATCHES_START;
|
|
|
|
EVENT(handle, &event);
|
2011-09-01 17:00:48 -04:00
|
|
|
deltas_found = 1;
|
|
|
|
}
|
|
|
|
|
2008-02-27 10:09:49 -05:00
|
|
|
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
2011-06-28 00:38:38 -04:00
|
|
|
alpm_delta_t *d = dlts->data;
|
2008-02-27 10:09:49 -05:00
|
|
|
char *delta, *from, *to;
|
|
|
|
char command[PATH_MAX];
|
2009-10-11 15:02:20 -04:00
|
|
|
size_t len = 0;
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2011-06-07 14:15:43 -04:00
|
|
|
delta = _alpm_filecache_find(handle, d->delta);
|
2008-02-27 10:09:49 -05:00
|
|
|
/* the initial package might be in a different cachedir */
|
|
|
|
if(dlts == delta_path) {
|
2011-06-07 14:15:43 -04:00
|
|
|
from = _alpm_filecache_find(handle, d->from);
|
2007-10-19 13:17:53 -04:00
|
|
|
} else {
|
2008-02-27 10:09:49 -05:00
|
|
|
/* len = cachedir len + from len + '/' + null */
|
|
|
|
len = strlen(cachedir) + strlen(d->from) + 2;
|
2011-09-30 12:46:44 -04:00
|
|
|
MALLOC(from, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
|
2008-02-27 10:09:49 -05:00
|
|
|
snprintf(from, len, "%s/%s", cachedir, d->from);
|
2007-10-19 13:17:53 -04:00
|
|
|
}
|
2008-02-27 10:09:49 -05:00
|
|
|
len = strlen(cachedir) + strlen(d->to) + 2;
|
2012-11-24 13:15:04 -05:00
|
|
|
MALLOC(to, len, free(from); RET_ERR(handle, ALPM_ERR_MEMORY, 1));
|
2008-02-27 10:09:49 -05:00
|
|
|
snprintf(to, len, "%s/%s", cachedir, d->to);
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2008-02-27 10:09:49 -05:00
|
|
|
/* build the patch command */
|
2009-02-19 13:12:34 -05:00
|
|
|
if(endswith(to, ".gz")) {
|
2009-05-21 18:24:26 -04:00
|
|
|
/* special handling for gzip : we disable timestamp with -n option */
|
|
|
|
snprintf(command, PATH_MAX, "xdelta3 -d -q -R -c -s %s %s | gzip -n > %s", from, delta, to);
|
|
|
|
} else {
|
|
|
|
snprintf(command, PATH_MAX, "xdelta3 -d -q -s %s %s %s", from, delta, to);
|
2009-02-19 13:12:34 -05:00
|
|
|
}
|
2008-02-27 10:09:49 -05:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "command: %s\n", command);
|
2008-02-27 10:09:49 -05:00
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_PATCH_START;
|
|
|
|
event.delta = d;
|
|
|
|
EVENT(handle, &event);
|
2008-02-27 10:09:49 -05:00
|
|
|
|
|
|
|
int retval = system(command);
|
|
|
|
if(retval == 0) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_PATCH_DONE;
|
|
|
|
EVENT(handle, &event);
|
2008-02-27 10:09:49 -05:00
|
|
|
|
|
|
|
/* delete the delta file */
|
|
|
|
unlink(delta);
|
|
|
|
|
|
|
|
/* Delete the 'from' package but only if it is an intermediate
|
|
|
|
* package. The starting 'from' package should be kept, just
|
|
|
|
* as if deltas were not used. */
|
|
|
|
if(dlts != delta_path) {
|
|
|
|
unlink(from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREE(from);
|
|
|
|
FREE(to);
|
|
|
|
FREE(delta);
|
|
|
|
|
|
|
|
if(retval != 0) {
|
|
|
|
/* one delta failed for this package, cancel the remaining ones */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_PATCH_FAILED;
|
|
|
|
EVENT(handle, &event);
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED;
|
2008-02-27 10:09:49 -05:00
|
|
|
ret = 1;
|
|
|
|
break;
|
2007-10-19 13:17:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-09-01 17:00:48 -04:00
|
|
|
if(deltas_found) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_PATCHES_DONE;
|
|
|
|
EVENT(handle, &event);
|
2011-09-01 17:00:48 -04:00
|
|
|
}
|
2007-10-19 13:17:53 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2007-10-19 13:17:53 -04:00
|
|
|
}
|
|
|
|
|
2011-09-01 18:16:56 -04:00
|
|
|
/**
|
|
|
|
* Prompts to delete the file now that we know it is invalid.
|
|
|
|
* @param handle the context handle
|
2008-12-07 12:58:24 -05:00
|
|
|
* @param filename the absolute path of the file to test
|
2011-08-08 20:55:44 -04:00
|
|
|
* @param reason an error code indicating the reason for package invalidity
|
2007-10-19 13:17:52 -04:00
|
|
|
*
|
2011-08-08 20:42:52 -04:00
|
|
|
* @return 1 if file was removed, 0 otherwise
|
2007-10-19 13:17:52 -04:00
|
|
|
*/
|
2011-09-01 18:16:56 -04:00
|
|
|
static int prompt_to_delete(alpm_handle_t *handle, const char *filepath,
|
2011-10-28 22:03:24 -04:00
|
|
|
alpm_errno_t reason)
|
2007-10-19 13:17:52 -04:00
|
|
|
{
|
2014-06-15 13:42:40 -04:00
|
|
|
alpm_question_corrupted_t question = {
|
|
|
|
.type = ALPM_QUESTION_CORRUPTED_PKG,
|
|
|
|
.remove = 0,
|
|
|
|
.filepath = filepath,
|
|
|
|
.reason = reason
|
|
|
|
};
|
|
|
|
QUESTION(handle, &question);
|
|
|
|
if(question.remove) {
|
2011-08-08 20:42:52 -04:00
|
|
|
unlink(filepath);
|
2007-10-19 13:17:52 -04:00
|
|
|
}
|
2014-06-15 13:42:40 -04:00
|
|
|
return question.remove;
|
2007-10-19 13:17:52 -04:00
|
|
|
}
|
|
|
|
|
2011-09-20 16:23:21 -04:00
|
|
|
static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
|
2011-04-21 22:57:08 -04:00
|
|
|
{
|
2011-09-20 16:23:21 -04:00
|
|
|
alpm_list_t *i, *errors = NULL;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2011-04-21 22:57:08 -04:00
|
|
|
|
|
|
|
if(!deltas) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check integrity of deltas */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_INTEGRITY_START;
|
|
|
|
EVENT(handle, &event);
|
2011-04-21 22:57:08 -04:00
|
|
|
for(i = deltas; i; i = i->next) {
|
2011-09-19 15:32:53 -04:00
|
|
|
alpm_delta_t *d = i->data;
|
2011-06-16 12:49:34 -04:00
|
|
|
char *filepath = _alpm_filecache_find(handle, d->delta);
|
2011-04-21 22:57:08 -04:00
|
|
|
|
2012-02-19 23:24:35 -05:00
|
|
|
if(_alpm_test_checksum(filepath, d->delta_md5, ALPM_PKG_VALIDATION_MD5SUM)) {
|
2011-09-20 16:23:21 -04:00
|
|
|
errors = alpm_list_add(errors, filepath);
|
|
|
|
} else {
|
|
|
|
FREE(filepath);
|
2011-04-21 22:57:08 -04:00
|
|
|
}
|
|
|
|
}
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DELTA_INTEGRITY_DONE;
|
|
|
|
EVENT(handle, &event);
|
2011-09-20 16:23:21 -04:00
|
|
|
|
2011-04-21 22:57:08 -04:00
|
|
|
if(errors) {
|
2011-09-20 16:23:21 -04:00
|
|
|
for(i = errors; i; i = i->next) {
|
|
|
|
char *filepath = i->data;
|
|
|
|
prompt_to_delete(handle, filepath, ALPM_ERR_DLT_INVALID);
|
|
|
|
FREE(filepath);
|
|
|
|
}
|
|
|
|
alpm_list_free(errors);
|
2011-07-01 12:01:39 -04:00
|
|
|
handle->pm_errno = ALPM_ERR_DLT_INVALID;
|
2011-04-21 22:57:08 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2011-09-01 17:00:48 -04:00
|
|
|
return 0;
|
2011-04-21 22:57:08 -04:00
|
|
|
}
|
|
|
|
|
2011-10-21 12:19:45 -04:00
|
|
|
static struct dload_payload *build_payload(alpm_handle_t *handle,
|
|
|
|
const char *filename, size_t size, alpm_list_t *servers)
|
|
|
|
{
|
|
|
|
struct dload_payload *payload;
|
|
|
|
|
|
|
|
CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
|
|
|
|
STRDUP(payload->remote_name, filename, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
|
|
|
|
payload->max_size = size;
|
|
|
|
payload->servers = servers;
|
|
|
|
return payload;
|
|
|
|
}
|
|
|
|
|
2011-10-14 19:59:04 -04:00
|
|
|
static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t **deltas)
|
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
alpm_handle_t *handle = repo->handle;
|
|
|
|
|
|
|
|
for(i = handle->trans->add; i; i = i->next) {
|
|
|
|
alpm_pkg_t *spkg = i->data;
|
|
|
|
|
2012-04-01 01:37:19 -04:00
|
|
|
if(spkg->origin != ALPM_PKG_FROM_FILE && repo == spkg->origin_data.db) {
|
2011-10-14 19:59:04 -04:00
|
|
|
alpm_list_t *delta_path = spkg->delta_path;
|
|
|
|
|
|
|
|
if(!repo->servers) {
|
|
|
|
handle->pm_errno = ALPM_ERR_SERVER_NONE;
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n",
|
|
|
|
alpm_strerror(handle->pm_errno), repo->treename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(delta_path) {
|
|
|
|
/* using deltas */
|
|
|
|
alpm_list_t *dlts;
|
|
|
|
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
|
|
|
alpm_delta_t *delta = dlts->data;
|
|
|
|
if(delta->download_size != 0) {
|
2011-10-21 12:19:45 -04:00
|
|
|
struct dload_payload *payload = build_payload(
|
2012-02-13 11:12:39 -05:00
|
|
|
handle, delta->delta, delta->delta_size, repo->servers);
|
2011-10-21 12:19:45 -04:00
|
|
|
ASSERT(payload, return -1);
|
|
|
|
*files = alpm_list_add(*files, payload);
|
2011-10-14 19:59:04 -04:00
|
|
|
}
|
|
|
|
/* keep a list of all the delta files for md5sums */
|
|
|
|
*deltas = alpm_list_add(*deltas, delta);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if(spkg->download_size != 0) {
|
|
|
|
struct dload_payload *payload;
|
|
|
|
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
|
2011-10-21 12:19:45 -04:00
|
|
|
payload = build_payload(handle, spkg->filename, spkg->size, repo->servers);
|
|
|
|
ASSERT(payload, return -1);
|
2011-10-14 19:59:04 -04:00
|
|
|
*files = alpm_list_add(*files, payload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-15 22:17:32 -04:00
|
|
|
static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload,
|
|
|
|
const char *cachedir)
|
|
|
|
{
|
2014-01-10 10:25:17 -05:00
|
|
|
alpm_event_pkgdownload_t event = {
|
|
|
|
.type = ALPM_EVENT_PKGDOWNLOAD_START,
|
|
|
|
.file = payload->remote_name
|
|
|
|
};
|
2011-10-15 22:17:32 -04:00
|
|
|
const alpm_list_t *server;
|
|
|
|
|
2012-03-16 13:08:10 -04:00
|
|
|
payload->handle = handle;
|
|
|
|
payload->allow_resume = 1;
|
|
|
|
|
2014-01-10 10:25:17 -05:00
|
|
|
EVENT(handle, &event);
|
2011-10-15 22:17:32 -04:00
|
|
|
for(server = payload->servers; server; server = server->next) {
|
|
|
|
const char *server_url = server->data;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/* print server + filename into a buffer */
|
|
|
|
len = strlen(server_url) + strlen(payload->remote_name) + 2;
|
|
|
|
MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
|
|
|
|
snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
|
|
|
|
|
2013-01-28 20:24:20 -05:00
|
|
|
if(_alpm_download(payload, cachedir, NULL, NULL) != -1) {
|
2014-01-10 10:25:17 -05:00
|
|
|
event.type = ALPM_EVENT_PKGDOWNLOAD_DONE;
|
|
|
|
EVENT(handle, &event);
|
2011-10-15 22:17:32 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2012-03-16 13:08:10 -04:00
|
|
|
|
2012-04-07 12:23:55 -04:00
|
|
|
FREE(payload->fileurl);
|
2012-03-16 13:08:10 -04:00
|
|
|
payload->unlink_on_fail = 0;
|
2011-10-15 22:17:32 -04:00
|
|
|
}
|
|
|
|
|
2014-01-10 10:25:17 -05:00
|
|
|
event.type = ALPM_EVENT_PKGDOWNLOAD_FAILED;
|
|
|
|
EVENT(handle, &event);
|
2011-10-15 22:17:32 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:04:00 -04:00
|
|
|
static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-04-21 22:40:00 -04:00
|
|
|
const char *cachedir;
|
2011-10-14 19:59:04 -04:00
|
|
|
alpm_list_t *i, *files = NULL;
|
2011-08-16 20:10:22 -04:00
|
|
|
int errors = 0;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2005-04-14 17:07:38 -04:00
|
|
|
|
2011-06-07 14:15:43 -04:00
|
|
|
cachedir = _alpm_filecache_setup(handle);
|
2011-06-03 14:18:36 -04:00
|
|
|
handle->trans->state = STATE_DOWNLOADING;
|
2007-11-09 19:54:19 -05:00
|
|
|
|
2008-06-02 00:10:30 -04:00
|
|
|
/* Total progress - figure out the total download size if required to
|
|
|
|
* pass to the callback. This function is called once, and it is up to the
|
|
|
|
* frontend to compute incremental progress. */
|
|
|
|
if(handle->totaldlcb) {
|
|
|
|
off_t total_size = (off_t)0;
|
|
|
|
/* sum up the download size for each package and store total */
|
2011-06-03 14:18:36 -04:00
|
|
|
for(i = handle->trans->add; i; i = i->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
2008-06-02 00:10:30 -04:00
|
|
|
total_size += spkg->download_size;
|
|
|
|
}
|
|
|
|
handle->totaldlcb(total_size);
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
for(i = handle->dbs_sync; i; i = i->next) {
|
2011-10-14 19:59:04 -04:00
|
|
|
errors += find_dl_candidates(i->data, &files, deltas);
|
|
|
|
}
|
2011-06-24 00:18:01 -04:00
|
|
|
|
2011-10-14 19:59:04 -04:00
|
|
|
if(files) {
|
2011-10-14 22:43:14 -04:00
|
|
|
/* check for necessary disk space for download */
|
|
|
|
if(handle->checkspace) {
|
|
|
|
off_t *file_sizes;
|
|
|
|
size_t idx, num_files;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space for download\n");
|
|
|
|
|
|
|
|
num_files = alpm_list_count(files);
|
|
|
|
CALLOC(file_sizes, num_files, sizeof(off_t), goto finish);
|
|
|
|
|
|
|
|
for(i = files, idx = 0; i; i = i->next, idx++) {
|
|
|
|
const struct dload_payload *payload = i->data;
|
|
|
|
file_sizes[idx] = payload->max_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = _alpm_check_downloadspace(handle, cachedir, num_files, file_sizes);
|
|
|
|
free(file_sizes);
|
|
|
|
|
|
|
|
if(ret != 0) {
|
|
|
|
errors++;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_RETRIEVE_START;
|
|
|
|
EVENT(handle, &event);
|
2014-01-10 10:25:16 -05:00
|
|
|
event.type = ALPM_EVENT_RETRIEVE_DONE;
|
2011-10-14 19:59:04 -04:00
|
|
|
for(i = files; i; i = i->next) {
|
2011-10-15 22:17:32 -04:00
|
|
|
if(download_single_file(handle, i->data, cachedir) == -1) {
|
2011-09-27 08:53:38 -04:00
|
|
|
errors++;
|
2014-01-10 10:25:16 -05:00
|
|
|
event.type = ALPM_EVENT_RETRIEVE_FAILED;
|
2011-10-14 19:59:04 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));
|
2011-04-21 19:31:19 -04:00
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2014-01-10 10:25:16 -05:00
|
|
|
EVENT(handle, &event);
|
2011-10-14 22:43:14 -04:00
|
|
|
}
|
2011-10-14 19:59:04 -04:00
|
|
|
|
2011-10-14 22:43:14 -04:00
|
|
|
finish:
|
|
|
|
if(files) {
|
2011-10-14 19:59:04 -04:00
|
|
|
alpm_list_free_inner(files, (alpm_list_fn_free)_alpm_dload_payload_reset);
|
|
|
|
FREELIST(files);
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
|
|
|
|
2011-10-14 19:59:04 -04:00
|
|
|
for(i = handle->trans->add; i; i = i->next) {
|
|
|
|
alpm_pkg_t *pkg = i->data;
|
2010-05-14 15:58:31 -04:00
|
|
|
pkg->infolevel &= ~INFRQ_DSIZE;
|
|
|
|
pkg->download_size = 0;
|
|
|
|
}
|
|
|
|
|
2008-06-02 00:10:30 -04:00
|
|
|
/* clear out value to let callback know we are done */
|
|
|
|
if(handle->totaldlcb) {
|
|
|
|
handle->totaldlcb(0);
|
|
|
|
}
|
2011-08-15 13:43:34 -04:00
|
|
|
|
2011-08-16 20:10:22 -04:00
|
|
|
return errors;
|
2011-04-21 22:40:00 -04:00
|
|
|
}
|
|
|
|
|
2013-02-10 22:39:57 -05:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2012-11-02 10:21:48 -04:00
|
|
|
static int check_keyring(alpm_handle_t *handle)
|
|
|
|
{
|
|
|
|
size_t current = 0, numtargs;
|
|
|
|
alpm_list_t *i, *errors = NULL;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2012-11-02 10:21:48 -04:00
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_KEYRING_START;
|
|
|
|
EVENT(handle, &event);
|
2012-11-02 10:21:48 -04:00
|
|
|
|
|
|
|
numtargs = alpm_list_count(handle->trans->add);
|
|
|
|
|
|
|
|
for(i = handle->trans->add; i; i = i->next, current++) {
|
|
|
|
alpm_pkg_t *pkg = i->data;
|
|
|
|
alpm_siglevel_t level;
|
|
|
|
|
|
|
|
int percent = (current * 100) / numtargs;
|
|
|
|
PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", percent,
|
|
|
|
numtargs, current);
|
|
|
|
|
|
|
|
if(pkg->origin == ALPM_PKG_FROM_FILE) {
|
|
|
|
continue; /* pkg_load() has been already called, this package is valid */
|
|
|
|
}
|
|
|
|
|
|
|
|
level = alpm_db_get_siglevel(alpm_pkg_get_db(pkg));
|
|
|
|
if((level & ALPM_SIG_PACKAGE) && pkg->base64_sig) {
|
|
|
|
unsigned char *decoded_sigdata = NULL;
|
|
|
|
size_t data_len;
|
2013-10-15 01:53:51 -04:00
|
|
|
int decode_ret = alpm_decode_signature(pkg->base64_sig,
|
2012-11-02 10:21:48 -04:00
|
|
|
&decoded_sigdata, &data_len);
|
|
|
|
if(decode_ret == 0) {
|
|
|
|
alpm_list_t *keys = NULL;
|
2013-10-15 01:53:51 -04:00
|
|
|
if(alpm_extract_keyid(handle, pkg->name, decoded_sigdata,
|
2012-11-02 10:21:48 -04:00
|
|
|
data_len, &keys) == 0) {
|
|
|
|
alpm_list_t *k;
|
|
|
|
for(k = keys; k; k = k->next) {
|
|
|
|
char *key = k->data;
|
|
|
|
if(_alpm_key_in_keychain(handle, key) == 0) {
|
|
|
|
if(!alpm_list_find_str(errors, key)) {
|
|
|
|
errors = alpm_list_add(errors, strdup(key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FREELIST(keys);
|
|
|
|
}
|
2014-01-03 14:43:05 -05:00
|
|
|
free(decoded_sigdata);
|
2012-11-02 10:21:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PROGRESS(handle, ALPM_PROGRESS_KEYRING_START, "", 100,
|
|
|
|
numtargs, current);
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_KEYRING_DONE;
|
|
|
|
EVENT(handle, &event);
|
2012-11-02 10:21:48 -04:00
|
|
|
|
|
|
|
if(errors) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_KEY_DOWNLOAD_START;
|
|
|
|
EVENT(handle, &event);
|
2012-11-02 10:21:48 -04:00
|
|
|
int fail = 0;
|
|
|
|
alpm_list_t *k;
|
|
|
|
for(k = errors; k; k = k->next) {
|
|
|
|
char *key = k->data;
|
|
|
|
if(_alpm_key_import(handle, key) == -1) {
|
|
|
|
fail = 1;
|
|
|
|
}
|
|
|
|
}
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_KEY_DOWNLOAD_DONE;
|
|
|
|
EVENT(handle, &event);
|
2012-11-02 10:21:48 -04:00
|
|
|
if(fail) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("required key missing from keyring\n"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-02-10 22:39:57 -05:00
|
|
|
#endif /* HAVE_LIBGPGME */
|
2012-11-02 10:21:48 -04:00
|
|
|
|
2011-09-20 17:52:18 -04:00
|
|
|
static int check_validity(alpm_handle_t *handle,
|
2013-10-14 00:55:20 -04:00
|
|
|
size_t total, uint64_t total_bytes)
|
2011-04-21 22:40:00 -04:00
|
|
|
{
|
2011-09-20 17:52:18 -04:00
|
|
|
struct validity {
|
|
|
|
alpm_pkg_t *pkg;
|
|
|
|
char *path;
|
|
|
|
alpm_siglist_t *siglist;
|
|
|
|
alpm_siglevel_t level;
|
2012-02-18 01:31:37 -05:00
|
|
|
alpm_pkgvalidation_t validation;
|
2011-10-28 22:03:24 -04:00
|
|
|
alpm_errno_t error;
|
2011-09-20 17:52:18 -04:00
|
|
|
};
|
2013-10-14 00:55:20 -04:00
|
|
|
size_t current = 0;
|
|
|
|
uint64_t current_bytes = 0;
|
2011-09-20 17:52:18 -04:00
|
|
|
alpm_list_t *i, *errors = NULL;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2011-08-29 17:27:00 -04:00
|
|
|
|
2007-10-19 13:17:53 -04:00
|
|
|
/* Check integrity of packages */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_INTEGRITY_START;
|
|
|
|
EVENT(handle, &event);
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
for(i = handle->trans->add; i; i = i->next, current++) {
|
2012-02-18 01:31:37 -05:00
|
|
|
struct validity v = { i->data, NULL, NULL, 0, 0, 0 };
|
2011-08-29 17:27:00 -04:00
|
|
|
int percent = (int)(((double)current_bytes / total_bytes) * 100);
|
2011-04-22 00:39:01 -04:00
|
|
|
|
2011-09-01 18:35:50 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", percent,
|
2011-09-20 00:47:06 -04:00
|
|
|
total, current);
|
2012-04-01 01:37:19 -04:00
|
|
|
if(v.pkg->origin == ALPM_PKG_FROM_FILE) {
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
continue; /* pkg_load() has been already called, this package is valid */
|
|
|
|
}
|
|
|
|
|
2011-09-20 17:52:18 -04:00
|
|
|
current_bytes += v.pkg->size;
|
|
|
|
v.path = _alpm_filecache_find(handle, v.pkg->filename);
|
|
|
|
v.level = alpm_db_get_siglevel(alpm_pkg_get_db(v.pkg));
|
2011-03-25 21:40:16 -04:00
|
|
|
|
2011-09-20 17:52:18 -04:00
|
|
|
if(_alpm_pkg_validate_internal(handle, v.path, v.pkg,
|
2012-02-18 01:31:37 -05:00
|
|
|
v.level, &v.siglist, &v.validation) == -1) {
|
2014-03-08 01:58:30 -05:00
|
|
|
struct validity *invalid;
|
2011-09-20 17:52:18 -04:00
|
|
|
v.error = handle->pm_errno;
|
2014-03-08 01:58:30 -05:00
|
|
|
MALLOC(invalid, sizeof(struct validity), return -1);
|
2011-09-20 17:52:18 -04:00
|
|
|
memcpy(invalid, &v, sizeof(struct validity));
|
|
|
|
errors = alpm_list_add(errors, invalid);
|
|
|
|
} else {
|
|
|
|
alpm_siglist_cleanup(v.siglist);
|
|
|
|
free(v.siglist);
|
|
|
|
free(v.path);
|
2012-02-18 01:31:37 -05:00
|
|
|
v.pkg->validation = v.validation;
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2011-09-19 22:01:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PROGRESS(handle, ALPM_PROGRESS_INTEGRITY_START, "", 100,
|
2011-09-20 00:47:06 -04:00
|
|
|
total, current);
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_INTEGRITY_DONE;
|
|
|
|
EVENT(handle, &event);
|
2011-09-19 22:01:26 -04:00
|
|
|
|
|
|
|
if(errors) {
|
2011-09-20 17:52:18 -04:00
|
|
|
for(i = errors; i; i = i->next) {
|
|
|
|
struct validity *v = i->data;
|
2013-07-21 06:00:11 -04:00
|
|
|
if(v->error == ALPM_ERR_PKG_MISSING_SIG) {
|
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR,
|
|
|
|
_("%s: missing required signature\n"), v->pkg->name);
|
|
|
|
} else if(v->error == ALPM_ERR_PKG_INVALID_SIG) {
|
2012-11-02 10:29:11 -04:00
|
|
|
_alpm_process_siglist(handle, v->pkg->name, v->siglist,
|
2011-09-20 17:52:18 -04:00
|
|
|
v->level & ALPM_SIG_PACKAGE_OPTIONAL,
|
|
|
|
v->level & ALPM_SIG_PACKAGE_MARGINAL_OK,
|
|
|
|
v->level & ALPM_SIG_PACKAGE_UNKNOWN_OK);
|
2012-11-02 10:34:54 -04:00
|
|
|
prompt_to_delete(handle, v->path, v->error);
|
2011-09-20 17:52:18 -04:00
|
|
|
} else if(v->error == ALPM_ERR_PKG_INVALID_CHECKSUM) {
|
|
|
|
prompt_to_delete(handle, v->path, v->error);
|
|
|
|
}
|
|
|
|
alpm_siglist_cleanup(v->siglist);
|
|
|
|
free(v->siglist);
|
|
|
|
free(v->path);
|
|
|
|
free(v);
|
2011-09-19 22:01:26 -04:00
|
|
|
}
|
2011-09-20 17:52:18 -04:00
|
|
|
alpm_list_free(errors);
|
|
|
|
|
2012-11-02 10:29:11 -04:00
|
|
|
if(!handle->pm_errno) {
|
|
|
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
|
2011-09-20 17:52:18 -04:00
|
|
|
}
|
2012-11-02 10:29:11 -04:00
|
|
|
return -1;
|
2011-09-19 22:01:26 -04:00
|
|
|
}
|
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
|
|
|
|
size_t total, size_t total_bytes)
|
|
|
|
{
|
|
|
|
size_t current = 0, current_bytes = 0;
|
|
|
|
int errors = 0;
|
|
|
|
alpm_list_t *i;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2011-09-19 22:01:26 -04:00
|
|
|
|
|
|
|
/* load packages from disk now that they are known-valid */
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_LOAD_START;
|
|
|
|
EVENT(handle, &event);
|
2011-09-19 22:01:26 -04:00
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
for(i = handle->trans->add; i; i = i->next, current++) {
|
2011-09-19 22:01:26 -04:00
|
|
|
alpm_pkg_t *spkg = i->data;
|
|
|
|
char *filepath;
|
|
|
|
int percent = (int)(((double)current_bytes / total_bytes) * 100);
|
|
|
|
|
|
|
|
PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", percent,
|
2011-09-20 00:47:06 -04:00
|
|
|
total, current);
|
2012-04-01 01:37:19 -04:00
|
|
|
if(spkg->origin == ALPM_PKG_FROM_FILE) {
|
2011-09-19 22:01:26 -04:00
|
|
|
continue; /* pkg_load() has been already called, this package is valid */
|
|
|
|
}
|
|
|
|
|
|
|
|
current_bytes += spkg->size;
|
|
|
|
filepath = _alpm_filecache_find(handle, spkg->filename);
|
|
|
|
|
|
|
|
/* load the package file and replace pkgcache entry with it in the target list */
|
|
|
|
/* TODO: alpm_pkg_get_db() will not work on this target anymore */
|
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
|
|
|
"replacing pkgcache entry with package file for target %s\n",
|
|
|
|
spkg->name);
|
2011-09-19 21:40:32 -04:00
|
|
|
alpm_pkg_t *pkgfile =_alpm_pkg_load_internal(handle, filepath, 1);
|
|
|
|
if(!pkgfile) {
|
|
|
|
errors++;
|
|
|
|
*data = alpm_list_add(*data, strdup(spkg->filename));
|
2011-09-20 00:28:05 -04:00
|
|
|
free(filepath);
|
2011-09-19 21:40:32 -04:00
|
|
|
continue;
|
|
|
|
}
|
2011-09-20 00:28:05 -04:00
|
|
|
free(filepath);
|
2011-09-28 02:53:43 -04:00
|
|
|
/* copy over the install reason */
|
|
|
|
pkgfile->reason = spkg->reason;
|
2012-02-18 01:31:37 -05:00
|
|
|
/* copy over validation method */
|
|
|
|
pkgfile->validation = spkg->validation;
|
Use sync.c for upgrade transaction prepare and commit
This patch utilizes the power of sync.c to fix FS#3492 and FS#5798.
Now an upgrade transaction is just a sync transaction internally (in alpm),
so all sync features are available with -U as well:
* conflict resolving
* sync dependencies from sync repos
* remove unresolvable targets
See http://www.archlinux.org/pipermail/pacman-dev/2009-June/008725.html
for the concept.
We use "mixed" target list, where PKG_FROM_FILE origin indicates local
package file, PKG_FROM_CACHE indicates sync package. The front-end can add
only one type of packages (depending on transaction type) atm, but if alpm
resolves dependencies for -U, we may get a real mixed trans->packages list.
_alpm_pkg_free_trans() was modified so that it can handle both target types
_alpm_add_prepare() was removed, we use _alpm_sync_prepare() instead
_alpm_add_commit() was renamed to _alpm_upgrade_targets()
sync.c (and deps.c) was modified slightly to handle mixed target lists,
the modifications are straightforward. There is one notable change here: We
don't create new upgrade trans in sync.c, we replace the pkgcache entries
with the loaded package files in the target list (this is a bit hackish) and
call _alpm_upgrade_targets(). This implies a TODO (pkg->origin_data.db is
not accessible anymore), but it doesn't hurt anything with pacman front-end,
so it will be fixed later (otherwise this patch would be huge).
I updated the documentation of -U and I added a new pactest, upgrade090.py,
to test the syncdeps feature of -U.
Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu>
Signed-off-by: Dan McGee <dan@archlinux.org>
2009-06-09 11:23:46 -04:00
|
|
|
i->data = pkgfile;
|
2011-09-28 02:53:43 -04:00
|
|
|
/* spkg has been removed from the target list, so we can free the
|
|
|
|
* sync-specific fields */
|
|
|
|
_alpm_pkg_free_trans(spkg);
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2008-12-17 05:55:07 -05:00
|
|
|
|
2011-09-19 22:01:26 -04:00
|
|
|
PROGRESS(handle, ALPM_PROGRESS_LOAD_START, "", 100,
|
2011-09-20 00:47:06 -04:00
|
|
|
total, current);
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_LOAD_DONE;
|
|
|
|
EVENT(handle, &event);
|
2008-12-17 05:55:07 -05:00
|
|
|
|
2008-02-26 18:50:17 -05:00
|
|
|
if(errors) {
|
2011-08-08 20:42:52 -04:00
|
|
|
if(!handle->pm_errno) {
|
|
|
|
RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
|
|
|
|
}
|
|
|
|
return -1;
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2011-01-11 22:12:08 -05:00
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
int _alpm_sync_commit(alpm_handle_t *handle, alpm_list_t **data)
|
|
|
|
{
|
|
|
|
alpm_list_t *i, *deltas = NULL;
|
2013-10-14 00:55:20 -04:00
|
|
|
size_t total = 0;
|
|
|
|
uint64_t total_bytes = 0;
|
2011-09-20 00:47:06 -04:00
|
|
|
alpm_trans_t *trans = handle->trans;
|
2014-01-10 10:25:14 -05:00
|
|
|
alpm_event_t event;
|
2011-09-20 00:47:06 -04:00
|
|
|
|
|
|
|
if(download_files(handle, &deltas)) {
|
|
|
|
alpm_list_free(deltas);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-20 16:23:21 -04:00
|
|
|
if(validate_deltas(handle, deltas)) {
|
2011-09-20 00:47:06 -04:00
|
|
|
alpm_list_free(deltas);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
alpm_list_free(deltas);
|
|
|
|
|
|
|
|
/* Use the deltas to generate the packages */
|
|
|
|
if(apply_deltas(handle)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-01-09 23:32:38 -05:00
|
|
|
#ifdef HAVE_LIBGPGME
|
2012-11-02 10:21:48 -04:00
|
|
|
/* make sure all required signatures are in keyring */
|
|
|
|
if(check_keyring(handle)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-20 00:47:06 -04:00
|
|
|
/* get the total size of all packages so we can adjust the progress bar more
|
|
|
|
* realistically if there are small and huge packages involved */
|
|
|
|
for(i = trans->add; i; i = i->next) {
|
|
|
|
alpm_pkg_t *spkg = i->data;
|
2012-04-01 01:37:19 -04:00
|
|
|
if(spkg->origin != ALPM_PKG_FROM_FILE) {
|
2011-09-20 00:47:06 -04:00
|
|
|
total_bytes += spkg->size;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
/* this can only happen maliciously */
|
|
|
|
total_bytes = total_bytes ? total_bytes : 1;
|
|
|
|
|
2011-09-20 17:52:18 -04:00
|
|
|
/* this one is special: -1 is failure, 1 is retry, 0 is success */
|
|
|
|
while(1) {
|
|
|
|
int ret = check_validity(handle, total, total_bytes);
|
|
|
|
if(ret == 0) {
|
|
|
|
break;
|
|
|
|
} else if(ret < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2011-09-20 00:47:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(trans->flags & ALPM_TRANS_FLAG_DOWNLOADONLY) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(load_packages(handle, data, total, total_bytes)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
trans->state = STATE_COMMITING;
|
2009-01-02 11:43:05 -05:00
|
|
|
|
|
|
|
/* fileconflict check */
|
2013-02-12 07:00:53 -05:00
|
|
|
if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_FILECONFLICTS_START;
|
|
|
|
EVENT(handle, &event);
|
2009-01-02 11:43:05 -05:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "looking for file conflicts\n");
|
2011-06-03 14:18:36 -04:00
|
|
|
alpm_list_t *conflict = _alpm_db_find_fileconflicts(handle,
|
|
|
|
trans->add, trans->remove);
|
2009-01-02 11:43:05 -05:00
|
|
|
if(conflict) {
|
|
|
|
if(data) {
|
|
|
|
*data = conflict;
|
|
|
|
} else {
|
2014-02-03 12:09:18 -05:00
|
|
|
alpm_list_free_inner(conflict, (alpm_list_fn_free)alpm_fileconflict_free);
|
2009-01-02 11:43:05 -05:00
|
|
|
alpm_list_free(conflict);
|
|
|
|
}
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_FILE_CONFLICTS, -1);
|
2009-01-02 11:43:05 -05:00
|
|
|
}
|
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_FILECONFLICTS_DONE;
|
|
|
|
EVENT(handle, &event);
|
2005-04-13 17:01:28 -04:00
|
|
|
}
|
2009-01-02 11:43:05 -05:00
|
|
|
|
2010-11-16 00:57:39 -05:00
|
|
|
/* check available disk space */
|
2011-12-21 17:42:47 -05:00
|
|
|
if(handle->checkspace && !(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DISKSPACE_START;
|
|
|
|
EVENT(handle, &event);
|
2010-11-16 02:07:43 -05:00
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space\n");
|
2011-06-03 13:36:13 -04:00
|
|
|
if(_alpm_check_diskspace(handle) == -1) {
|
2012-03-12 22:47:29 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("not enough free disk space\n"));
|
2011-04-21 22:57:08 -04:00
|
|
|
return -1;
|
2010-11-16 01:54:30 -05:00
|
|
|
}
|
2010-11-16 02:07:43 -05:00
|
|
|
|
2014-01-10 10:25:14 -05:00
|
|
|
event.type = ALPM_EVENT_DISKSPACE_DONE;
|
|
|
|
EVENT(handle, &event);
|
2010-11-16 00:57:39 -05:00
|
|
|
}
|
|
|
|
|
2009-01-02 11:43:05 -05:00
|
|
|
/* remove conflicting and to-be-replaced packages */
|
2011-09-20 00:47:06 -04:00
|
|
|
if(trans->remove) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
|
2009-01-02 11:43:05 -05:00
|
|
|
/* we want the frontend to be aware of commit details */
|
2011-09-19 14:18:42 -04:00
|
|
|
if(_alpm_remove_packages(handle, 0) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not commit removal transaction\n"));
|
2011-04-21 22:57:08 -04:00
|
|
|
return -1;
|
2009-01-02 11:43:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* install targets */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_DEBUG, "installing packages\n");
|
2011-06-03 14:18:36 -04:00
|
|
|
if(_alpm_upgrade_packages(handle) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(handle, ALPM_LOG_ERROR, _("could not commit transaction\n"));
|
2011-04-21 22:57:08 -04:00
|
|
|
return -1;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2005-04-13 17:01:28 -04:00
|
|
|
|
2011-04-21 22:57:08 -04:00
|
|
|
return 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2014-01-22 18:06:11 -05:00
|
|
|
/* vim: set noet: */
|