2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* package.c
|
2006-10-15 15:31:03 -04:00
|
|
|
*
|
2009-07-01 03:08:33 -04:00
|
|
|
* Copyright (c) 2006-2009 Pacman Development Team <pacman-dev@archlinux.org>
|
|
|
|
* 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, 2006 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
2007-06-03 23:57:38 -04:00
|
|
|
#include <ctype.h>
|
2007-01-24 03:51:50 -05:00
|
|
|
#include <errno.h>
|
2007-02-10 18:44:39 -05:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
2007-04-29 12:47:02 -04:00
|
|
|
/* libarchive */
|
|
|
|
#include <archive.h>
|
|
|
|
#include <archive_entry.h>
|
|
|
|
|
2007-03-05 17:13:33 -05:00
|
|
|
/* libalpm */
|
2007-02-09 16:54:57 -05:00
|
|
|
#include "package.h"
|
2007-03-05 17:13:33 -05:00
|
|
|
#include "alpm_list.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
2006-11-20 04:10:23 -05:00
|
|
|
#include "db.h"
|
2007-02-17 03:55:05 -05:00
|
|
|
#include "cache.h"
|
2007-10-29 22:06:13 -04:00
|
|
|
#include "delta.h"
|
2006-11-20 04:10:23 -05:00
|
|
|
#include "handle.h"
|
2007-11-13 00:01:14 -05:00
|
|
|
#include "deps.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** \addtogroup alpm_packages Package Functions
|
|
|
|
* @brief Functions to manipulate libalpm packages
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Free a package.
|
|
|
|
* @param pkg package pointer to free
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
|
|
|
int SYMEXPORT alpm_pkg_free(pmpkg_t *pkg)
|
|
|
|
{
|
2008-01-21 22:23:54 -05:00
|
|
|
ALPM_LOG_FUNC;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
|
|
|
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
|
|
|
|
|
|
/* Only free packages loaded in user space */
|
|
|
|
if(pkg->origin != PKG_FROM_CACHE) {
|
|
|
|
_alpm_pkg_free(pkg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Check the integrity (with md5) of a package from the sync cache.
|
|
|
|
* @param pkg package pointer
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2007-07-18 10:26:21 -04:00
|
|
|
int SYMEXPORT alpm_pkg_checkmd5sum(pmpkg_t *pkg)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2007-08-20 13:28:51 -04:00
|
|
|
char *fpath;
|
2008-02-26 18:50:17 -05:00
|
|
|
int retval;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
|
|
/* We only inspect packages from sync repositories */
|
|
|
|
ASSERT(pkg->origin == PKG_FROM_CACHE, RET_ERR(PM_ERR_PKG_INVALID, -1));
|
2007-08-14 10:14:35 -04:00
|
|
|
ASSERT(pkg->origin_data.db != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2007-08-20 13:28:51 -04:00
|
|
|
fpath = _alpm_filecache_find(alpm_pkg_get_filename(pkg));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2008-02-26 18:50:17 -05:00
|
|
|
retval = _alpm_test_md5sum(fpath, alpm_pkg_get_md5sum(pkg));
|
|
|
|
|
|
|
|
if(retval == 0) {
|
|
|
|
return(0);
|
|
|
|
} else if (retval == 1) {
|
|
|
|
pm_errno = PM_ERR_PKG_INVALID;
|
2007-06-03 23:57:38 -04:00
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(retval);
|
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2008-02-13 23:42:34 -05:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->filename;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_name(pmpkg_t *pkg)
|
2005-04-23 13:18:31 -04:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
return pkg->name;
|
2005-04-23 13:18:31 -04:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_version(pmpkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
return pkg->version;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_desc(pmpkg_t *pkg)
|
2007-02-06 12:39:32 -05:00
|
|
|
{
|
2007-02-07 00:57:28 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-02-06 15:57:17 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->desc;
|
|
|
|
}
|
2007-02-06 15:57:17 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_url(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
2007-05-18 02:22:18 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
2007-04-22 22:48:10 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-02-06 12:39:32 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->url;
|
2007-02-06 12:39:32 -05:00
|
|
|
}
|
|
|
|
|
2007-09-19 01:21:56 -04:00
|
|
|
time_t SYMEXPORT alpm_pkg_get_builddate(pmpkg_t *pkg)
|
2006-03-08 13:07:58 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
ALPM_LOG_FUNC;
|
2006-03-08 13:07:58 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
2007-09-19 01:21:56 -04:00
|
|
|
ASSERT(handle != NULL, return(0));
|
|
|
|
ASSERT(pkg != NULL, return(0));
|
2007-07-18 10:26:21 -04:00
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
|
|
|
return pkg->builddate;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-09-19 01:21:56 -04:00
|
|
|
time_t SYMEXPORT alpm_pkg_get_installdate(pmpkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
2007-09-19 01:21:56 -04:00
|
|
|
ASSERT(handle != NULL, return(0));
|
|
|
|
ASSERT(pkg != NULL, return(0));
|
2007-07-18 10:26:21 -04:00
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->installdate;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_packager(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->packager;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
|
|
|
return pkg->md5sum;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
|
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->arch;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2008-06-01 22:47:31 -04:00
|
|
|
off_t SYMEXPORT alpm_pkg_get_size(pmpkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(pkg != NULL, return(-1));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-02-03 22:24:32 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->size;
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2008-06-01 22:47:31 -04:00
|
|
|
off_t SYMEXPORT alpm_pkg_get_isize(pmpkg_t *pkg)
|
2007-07-18 10:26:21 -04:00
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(pkg != NULL, return(-1));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-02-03 22:24:32 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->isize;
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
pmpkgreason_t SYMEXPORT alpm_pkg_get_reason(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(pkg != NULL, return(-1));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2006-09-28 16:51:33 -04:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->reason;
|
|
|
|
}
|
2006-09-28 16:51:33 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-02-10 18:44:39 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->licenses;
|
|
|
|
}
|
2007-02-10 18:44:39 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
2007-02-03 22:24:32 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
2007-01-31 22:00:34 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-01-19 18:44:50 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->groups;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2009-10-11 14:51:47 -04:00
|
|
|
int SYMEXPORT alpm_pkg_has_force(pmpkg_t *pkg)
|
2008-05-31 09:06:30 -04:00
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(pkg != NULL, return(-1));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
|
|
|
}
|
|
|
|
return pkg->force;
|
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(pmpkg_t *pkg)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->depends;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2007-09-26 00:02:30 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
|
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
|
|
|
|
}
|
|
|
|
return pkg->optdepends;
|
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(pmpkg_t *pkg)
|
2007-02-17 03:55:05 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
ALPM_LOG_FUNC;
|
2007-03-12 00:47:58 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
2007-05-14 02:54:16 -04:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
|
2007-02-17 03:55:05 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->conflicts;
|
2007-02-17 03:55:05 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_provides(pmpkg_t *pkg)
|
2006-11-22 04:03:41 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-22 04:03:41 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DEPENDS);
|
2006-11-22 04:03:41 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->provides;
|
2006-11-22 04:03:41 -05:00
|
|
|
}
|
|
|
|
|
2007-10-19 13:17:51 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DELTAS)) {
|
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DELTAS);
|
|
|
|
}
|
|
|
|
return pkg->deltas;
|
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-03-01 14:07:38 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_DESC);
|
2007-03-01 14:07:38 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->replaces;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_files(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-03-01 14:07:38 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
2007-08-14 10:14:35 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local
|
2007-07-18 10:26:21 -04:00
|
|
|
&& !(pkg->infolevel & INFRQ_FILES)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
2007-03-01 14:07:38 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->files;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
2007-08-14 10:14:35 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local
|
2007-07-18 10:26:21 -04:00
|
|
|
&& !(pkg->infolevel & INFRQ_FILES)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_FILES);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->backup;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2008-08-17 12:32:39 -04:00
|
|
|
pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
ASSERT(pkg->origin == PKG_FROM_CACHE, return(NULL));
|
|
|
|
|
|
|
|
return(pkg->origin_data.db);
|
|
|
|
}
|
|
|
|
|
2007-12-09 00:42:04 -05:00
|
|
|
/**
|
|
|
|
* Open a package changelog for reading. Similar to fopen in functionality,
|
|
|
|
* except that the returned 'file stream' could really be from an archive
|
|
|
|
* as well as from the database.
|
|
|
|
* @param pkg the package to read the changelog of (either file or db)
|
|
|
|
* @return a 'file stream' to the package changelog
|
|
|
|
*/
|
|
|
|
void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
ASSERT(handle != NULL, return(NULL));
|
|
|
|
ASSERT(pkg != NULL, return(NULL));
|
|
|
|
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE) {
|
|
|
|
char clfile[PATH_MAX];
|
|
|
|
snprintf(clfile, PATH_MAX, "%s/%s/%s-%s/changelog",
|
|
|
|
alpm_option_get_dbpath(),
|
|
|
|
alpm_db_get_name(handle->db_local),
|
|
|
|
alpm_pkg_get_name(pkg),
|
|
|
|
alpm_pkg_get_version(pkg));
|
|
|
|
return fopen(clfile, "r");
|
|
|
|
} else if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
struct archive *archive = NULL;
|
|
|
|
struct archive_entry *entry;
|
|
|
|
const char *pkgfile = pkg->origin_data.file;
|
|
|
|
int ret = ARCHIVE_OK;
|
|
|
|
|
|
|
|
if((archive = archive_read_new()) == NULL) {
|
2008-04-06 21:09:27 -04:00
|
|
|
RET_ERR(PM_ERR_LIBARCHIVE, NULL);
|
2007-12-09 00:42:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
archive_read_support_compression_all(archive);
|
|
|
|
archive_read_support_format_all(archive);
|
|
|
|
|
|
|
|
if (archive_read_open_filename(archive, pkgfile,
|
|
|
|
ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
|
|
|
|
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
while((ret = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
|
|
|
|
const char *entry_name = archive_entry_pathname(entry);
|
|
|
|
|
|
|
|
if(strcmp(entry_name, ".CHANGELOG") == 0) {
|
|
|
|
return(archive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* we didn't find a changelog */
|
|
|
|
archive_read_finish(archive);
|
|
|
|
errno = ENOENT;
|
|
|
|
}
|
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read data from an open changelog 'file stream'. Similar to fread in
|
|
|
|
* functionality, this function takes a buffer and amount of data to read.
|
|
|
|
* @param ptr a buffer to fill with raw changelog data
|
|
|
|
* @param size the size of the buffer
|
|
|
|
* @param pkg the package that the changelog is being read from
|
|
|
|
* @param fp a 'file stream' to the package changelog
|
|
|
|
* @return the number of characters read, or 0 if there is no more data
|
|
|
|
*/
|
|
|
|
size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size,
|
|
|
|
const pmpkg_t *pkg, const void *fp)
|
|
|
|
{
|
|
|
|
size_t ret = 0;
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE) {
|
|
|
|
ret = fread(ptr, 1, size, (FILE*)fp);
|
|
|
|
} else if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
ret = archive_read_data((struct archive*)fp, ptr, size);
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
int SYMEXPORT alpm_pkg_changelog_feof(const pmpkg_t *pkg, void *fp)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE) {
|
|
|
|
ret = feof((FILE*)fp);
|
|
|
|
} else if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
// note: this doesn't quite work, no feof in libarchive
|
|
|
|
ret = archive_read_data((struct archive*)fp, NULL, 0);
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a package changelog for reading. Similar to fclose in functionality,
|
|
|
|
* except that the 'file stream' could really be from an archive as well as
|
|
|
|
* from the database.
|
|
|
|
* @param pkg the package that the changelog was read from
|
|
|
|
* @param fp a 'file stream' to the package changelog
|
|
|
|
* @return whether closing the package changelog stream was successful
|
|
|
|
*/
|
|
|
|
int SYMEXPORT alpm_pkg_changelog_close(const pmpkg_t *pkg, void *fp)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
if(pkg->origin == PKG_FROM_CACHE) {
|
|
|
|
ret = fclose((FILE*)fp);
|
|
|
|
} else if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
ret = archive_read_finish((struct archive *)fp);
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2009-10-11 14:51:47 -04:00
|
|
|
int SYMEXPORT alpm_pkg_has_scriptlet(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2006-11-20 04:10:23 -05:00
|
|
|
/* Sanity checks */
|
2007-07-18 10:26:21 -04:00
|
|
|
ASSERT(handle != NULL, return(-1));
|
|
|
|
ASSERT(pkg != NULL, return(-1));
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-08-14 10:14:35 -04:00
|
|
|
if(pkg->origin == PKG_FROM_CACHE && pkg->origin_data.db == handle->db_local
|
2007-07-18 10:26:21 -04:00
|
|
|
&& !(pkg->infolevel & INFRQ_SCRIPTLET)) {
|
2007-08-14 10:14:35 -04:00
|
|
|
_alpm_db_read(pkg->origin_data.db, pkg, INFRQ_SCRIPTLET);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return pkg->scriptlet;
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-08-25 19:07:02 -04:00
|
|
|
/**
|
|
|
|
* @brief Compute the packages requiring a given package.
|
|
|
|
* @param pkg a package
|
|
|
|
* @return the list of packages requiring pkg
|
2008-07-01 15:06:32 -04:00
|
|
|
*/
|
2007-08-25 19:07:02 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_pkg_compute_requiredby(pmpkg_t *pkg)
|
|
|
|
{
|
2008-07-01 16:53:13 -04:00
|
|
|
const alpm_list_t *i;
|
2007-08-25 19:07:02 -04:00
|
|
|
alpm_list_t *reqs = NULL;
|
|
|
|
|
|
|
|
pmdb_t *localdb = alpm_option_get_localdb();
|
|
|
|
for(i = _alpm_db_get_pkgcache(localdb); i; i = i->next) {
|
|
|
|
if(!i->data) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pmpkg_t *cachepkg = i->data;
|
2008-07-01 16:53:13 -04:00
|
|
|
if(_alpm_dep_edge(cachepkg, pkg)) {
|
2009-10-21 00:25:38 -04:00
|
|
|
const char *cachepkgname = pkg->name;
|
2008-07-01 16:53:13 -04:00
|
|
|
reqs = alpm_list_add(reqs, strdup(cachepkgname));
|
2007-08-25 19:07:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(reqs);
|
|
|
|
}
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/** Compare two version strings and determine which one is 'newer'.
|
|
|
|
* Returns a value comparable to the way strcmp works. Returns 1
|
|
|
|
* if a is newer than b, 0 if a and b are the same version, or -1
|
|
|
|
* if b is newer than a.
|
|
|
|
*
|
|
|
|
* This function has been adopted from the rpmvercmp function located
|
|
|
|
* at lib/rpmvercmp.c, and was most recently updated against rpm
|
|
|
|
* version 4.4.2.3. Small modifications have been made to make it more
|
|
|
|
* consistent with the libalpm coding style.
|
2008-05-30 00:12:44 -04:00
|
|
|
*
|
|
|
|
* Keep in mind that the pkgrel is only compared if it is available
|
|
|
|
* on both versions handed to this function. For example, comparing
|
|
|
|
* 1.5-1 and 1.5 will yield 0; comparing 1.5-1 and 1.5-2 will yield
|
|
|
|
* -1 as expected. This is mainly for supporting versioned dependencies
|
|
|
|
* that do not include the pkgrel.
|
2008-05-14 01:30:04 -04:00
|
|
|
*/
|
2008-05-14 01:37:51 -04:00
|
|
|
int SYMEXPORT alpm_pkg_vercmp(const char *a, const char *b)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2008-05-14 01:30:04 -04:00
|
|
|
char oldch1, oldch2;
|
|
|
|
char *str1, *str2;
|
2007-07-18 10:26:21 -04:00
|
|
|
char *ptr1, *ptr2;
|
|
|
|
char *one, *two;
|
|
|
|
int rc;
|
2008-05-14 01:30:04 -04:00
|
|
|
int isnum;
|
|
|
|
int ret = 0;
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* libalpm added code. ensure our strings are not null */
|
|
|
|
if(!a) {
|
|
|
|
if(!b) return(0);
|
|
|
|
return(-1);
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2008-05-14 01:30:04 -04:00
|
|
|
if(!b) return(1);
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* easy comparison to see if versions are identical */
|
|
|
|
if(strcmp(a, b) == 0) return(0);
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
str1 = strdup(a);
|
|
|
|
str2 = strdup(b);
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
one = str1;
|
|
|
|
two = str2;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* loop through each version segment of str1 and str2 and compare them */
|
|
|
|
while(*one && *two) {
|
2007-07-18 10:26:21 -04:00
|
|
|
while(*one && !isalnum((int)*one)) one++;
|
|
|
|
while(*two && !isalnum((int)*two)) two++;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* If we ran to the end of either, we are finished with the loop */
|
|
|
|
if(!(*one && *two)) break;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
ptr1 = one;
|
|
|
|
ptr2 = two;
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* grab first completely alpha or completely numeric segment */
|
|
|
|
/* leave one and two pointing to the start of the alpha or numeric */
|
|
|
|
/* segment and walk ptr1 and ptr2 to end of segment */
|
2007-07-18 10:26:21 -04:00
|
|
|
if(isdigit((int)*ptr1)) {
|
|
|
|
while(*ptr1 && isdigit((int)*ptr1)) ptr1++;
|
|
|
|
while(*ptr2 && isdigit((int)*ptr2)) ptr2++;
|
2008-05-14 01:30:04 -04:00
|
|
|
isnum = 1;
|
2007-07-18 10:26:21 -04:00
|
|
|
} else {
|
2008-05-14 01:30:04 -04:00
|
|
|
while(*ptr1 && isalpha((int)*ptr1)) ptr1++;
|
2007-07-18 10:26:21 -04:00
|
|
|
while(*ptr2 && isalpha((int)*ptr2)) ptr2++;
|
2008-05-14 01:30:04 -04:00
|
|
|
isnum = 0;
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* save character at the end of the alpha or numeric segment */
|
|
|
|
/* so that they can be restored after the comparison */
|
2007-07-18 10:26:21 -04:00
|
|
|
oldch1 = *ptr1;
|
|
|
|
*ptr1 = '\0';
|
|
|
|
oldch2 = *ptr2;
|
|
|
|
*ptr2 = '\0';
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* this cannot happen, as we previously tested to make sure that */
|
|
|
|
/* the first string has a non-null segment */
|
|
|
|
if (one == ptr1) {
|
|
|
|
ret = -1; /* arbitrary */
|
|
|
|
goto cleanup;
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
2008-05-14 01:30:04 -04:00
|
|
|
|
|
|
|
/* take care of the case where the two version segments are */
|
|
|
|
/* different types: one numeric, the other alpha (i.e. empty) */
|
|
|
|
/* numeric segments are always newer than alpha segments */
|
|
|
|
/* XXX See patch #60884 (and details) from bugzilla #50977. */
|
|
|
|
if (two == ptr2) {
|
|
|
|
ret = isnum ? 1 : -1;
|
|
|
|
goto cleanup;
|
2007-07-18 10:26:21 -04:00
|
|
|
}
|
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
if (isnum) {
|
|
|
|
/* this used to be done by converting the digit segments */
|
|
|
|
/* to ints using atoi() - it's changed because long */
|
|
|
|
/* digit segments can overflow an int - this should fix that. */
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* throw away any leading zeros - it's a number, right? */
|
|
|
|
while (*one == '0') one++;
|
|
|
|
while (*two == '0') two++;
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* whichever number has more digits wins */
|
|
|
|
if (strlen(one) > strlen(two)) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (strlen(two) > strlen(one)) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* strcmp will return which one is greater - even if the two */
|
|
|
|
/* segments are alpha or if they are numeric. don't return */
|
|
|
|
/* if they are equal because there might be more segments to */
|
|
|
|
/* compare */
|
|
|
|
rc = strcmp(one, two);
|
|
|
|
if (rc) {
|
|
|
|
ret = rc < 1 ? -1 : 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore character that was replaced by null above */
|
2007-07-18 10:26:21 -04:00
|
|
|
*ptr1 = oldch1;
|
|
|
|
one = ptr1;
|
2008-05-14 01:30:04 -04:00
|
|
|
*ptr2 = oldch2;
|
2007-07-18 10:26:21 -04:00
|
|
|
two = ptr2;
|
2008-05-30 00:12:44 -04:00
|
|
|
|
|
|
|
/* libalpm added code. check if version strings have hit the pkgrel
|
|
|
|
* portion. depending on which strings have hit, take correct action.
|
|
|
|
* this is all based on the premise that we only have one dash in
|
|
|
|
* the version string, and it separates pkgver from pkgrel. */
|
|
|
|
if(*ptr1 == '-' && *ptr2 == '-') {
|
|
|
|
/* no-op, continue comparing since we are equivalent throughout */
|
|
|
|
} else if(*ptr1 == '-') {
|
2008-07-23 00:41:50 -04:00
|
|
|
/* ptr1 has hit the pkgrel and ptr2 has not. continue version
|
|
|
|
* comparison after stripping the pkgrel from ptr1. */
|
|
|
|
*ptr1 = '\0';
|
2008-05-30 00:12:44 -04:00
|
|
|
} else if(*ptr2 == '-') {
|
2008-07-23 00:41:50 -04:00
|
|
|
/* ptr2 has hit the pkgrel and ptr1 has not. continue version
|
|
|
|
* comparison after stripping the pkgrel from ptr2. */
|
|
|
|
*ptr2 = '\0';
|
2008-05-30 00:12:44 -04:00
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-14 01:30:04 -04:00
|
|
|
/* this catches the case where all numeric and alpha segments have */
|
|
|
|
/* compared identically but the segment separating characters were */
|
|
|
|
/* different */
|
|
|
|
if ((!*one) && (!*two)) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2008-07-23 00:41:50 -04:00
|
|
|
/* the final showdown. we never want a remaining alpha string to
|
|
|
|
* beat an empty string. the logic is a bit weird, but:
|
|
|
|
* - if one is empty and two is not an alpha, two is newer.
|
|
|
|
* - if one is an alpha, two is newer.
|
|
|
|
* - otherwise one is newer.
|
|
|
|
* */
|
|
|
|
if ( ( !*one && !isalpha((int)*two) )
|
|
|
|
|| isalpha((int)*one) ) {
|
2008-05-14 01:30:04 -04:00
|
|
|
ret = -1;
|
|
|
|
} else {
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
free(str1);
|
|
|
|
free(str2);
|
|
|
|
return(ret);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2008-05-30 00:12:44 -04:00
|
|
|
/** @} */
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-13 20:03:54 -04:00
|
|
|
pmpkg_t *_alpm_pkg_new(void)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
pmpkg_t* pkg;
|
|
|
|
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-10-29 02:00:52 -04:00
|
|
|
CALLOC(pkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
return(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2008-01-11 01:01:58 -05:00
|
|
|
pmpkg_t *newpkg;
|
2008-01-11 02:00:15 -05:00
|
|
|
alpm_list_t *i;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
ALPM_LOG_FUNC;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-10-29 02:00:52 -04:00
|
|
|
CALLOC(newpkg, 1, sizeof(pmpkg_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
STRDUP(newpkg->filename, pkg->filename, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->name, pkg->name, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->version, pkg->version, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->desc, pkg->desc, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->url, pkg->url, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
newpkg->builddate = pkg->builddate;
|
|
|
|
newpkg->installdate = pkg->installdate;
|
|
|
|
STRDUP(newpkg->packager, pkg->packager, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->md5sum, pkg->md5sum, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
STRDUP(newpkg->arch, pkg->arch, RET_ERR(PM_ERR_MEMORY, newpkg));
|
|
|
|
newpkg->size = pkg->size;
|
|
|
|
newpkg->isize = pkg->isize;
|
|
|
|
newpkg->scriptlet = pkg->scriptlet;
|
|
|
|
newpkg->force = pkg->force;
|
|
|
|
newpkg->reason = pkg->reason;
|
|
|
|
|
2008-07-24 20:02:17 -04:00
|
|
|
newpkg->licenses = alpm_list_strdup(pkg->licenses);
|
|
|
|
newpkg->replaces = alpm_list_strdup(pkg->replaces);
|
|
|
|
newpkg->groups = alpm_list_strdup(pkg->groups);
|
|
|
|
newpkg->files = alpm_list_strdup(pkg->files);
|
|
|
|
newpkg->backup = alpm_list_strdup(pkg->backup);
|
|
|
|
for(i = pkg->depends; i; i = alpm_list_next(i)) {
|
2008-01-11 02:00:15 -05:00
|
|
|
newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
|
|
|
|
}
|
2008-07-24 20:02:17 -04:00
|
|
|
newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
|
|
|
|
newpkg->conflicts = alpm_list_strdup(pkg->conflicts);
|
|
|
|
newpkg->provides = alpm_list_strdup(pkg->provides);
|
|
|
|
newpkg->deltas = alpm_list_copy_data(pkg->deltas, sizeof(pmdelta_t));
|
2008-01-11 01:01:58 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* internal */
|
2008-01-11 01:01:58 -05:00
|
|
|
newpkg->origin = pkg->origin;
|
2007-08-14 10:14:35 -04:00
|
|
|
if(newpkg->origin == PKG_FROM_FILE) {
|
|
|
|
newpkg->origin_data.file = strdup(pkg->origin_data.file);
|
|
|
|
} else {
|
|
|
|
newpkg->origin_data.db = pkg->origin_data.db;
|
|
|
|
}
|
2008-01-11 01:01:58 -05:00
|
|
|
newpkg->infolevel = pkg->infolevel;
|
2007-07-18 10:26:21 -04:00
|
|
|
|
|
|
|
return(newpkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
void _alpm_pkg_free(pmpkg_t *pkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-01-30 03:14:10 -05:00
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
FREE(pkg->filename);
|
|
|
|
FREE(pkg->name);
|
|
|
|
FREE(pkg->version);
|
|
|
|
FREE(pkg->desc);
|
|
|
|
FREE(pkg->url);
|
|
|
|
FREE(pkg->packager);
|
|
|
|
FREE(pkg->md5sum);
|
|
|
|
FREE(pkg->arch);
|
2007-07-18 10:26:21 -04:00
|
|
|
FREELIST(pkg->licenses);
|
2008-01-11 01:01:58 -05:00
|
|
|
FREELIST(pkg->replaces);
|
|
|
|
FREELIST(pkg->groups);
|
2007-07-18 10:26:21 -04:00
|
|
|
FREELIST(pkg->files);
|
|
|
|
FREELIST(pkg->backup);
|
2008-01-11 02:00:15 -05:00
|
|
|
alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
|
|
|
|
alpm_list_free(pkg->depends);
|
2007-09-26 00:02:30 -04:00
|
|
|
FREELIST(pkg->optdepends);
|
2007-07-18 10:26:21 -04:00
|
|
|
FREELIST(pkg->conflicts);
|
|
|
|
FREELIST(pkg->provides);
|
2008-01-12 02:27:02 -05:00
|
|
|
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
|
|
|
|
alpm_list_free(pkg->deltas);
|
2008-02-16 11:47:22 -05:00
|
|
|
alpm_list_free(pkg->delta_path);
|
2009-03-07 13:44:34 -05:00
|
|
|
alpm_list_free(pkg->removes);
|
2008-01-11 01:01:58 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
2007-08-14 10:14:35 -04:00
|
|
|
FREE(pkg->origin_data.file);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
FREE(pkg);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
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
|
|
|
/* This function should be used when removing a target from upgrade/sync target list
|
|
|
|
* Case 1: If pkg is a loaded package file (PKG_FROM_FILE), it will be freed.
|
|
|
|
* Case 2: If pkg is a pkgcache entry (PKG_FROM_CACHE), it won't be freed,
|
|
|
|
* only the transaction specific fields of pkg will be freed.
|
|
|
|
*/
|
2009-06-07 08:30:11 -04:00
|
|
|
void _alpm_pkg_free_trans(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
ALPM_LOG_FUNC;
|
|
|
|
|
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
_alpm_pkg_free(pkg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-07 08:30:11 -04:00
|
|
|
alpm_list_free(pkg->removes);
|
|
|
|
pkg->removes = NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-31 09:06:30 -04:00
|
|
|
/* Is spkg an upgrade for locapkg? */
|
|
|
|
int _alpm_pkg_compare_versions(pmpkg_t *spkg, pmpkg_t *localpkg)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
int cmp = 0;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
ALPM_LOG_FUNC;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2008-05-31 09:06:30 -04:00
|
|
|
cmp = alpm_pkg_vercmp(alpm_pkg_get_version(spkg),
|
|
|
|
alpm_pkg_get_version(localpkg));
|
2007-07-18 10:26:21 -04:00
|
|
|
|
2008-05-31 09:06:30 -04:00
|
|
|
if(cmp < 0 && alpm_pkg_has_force(spkg)) {
|
2007-07-18 10:26:21 -04:00
|
|
|
cmp = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return(cmp);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Helper function for comparing packages
|
|
|
|
*/
|
|
|
|
int _alpm_pkg_cmp(const void *p1, const void *p2)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
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
|
|
|
pmpkg_t *pkg1 = (pmpkg_t *)p1;
|
|
|
|
pmpkg_t *pkg2 = (pmpkg_t *)p2;
|
2009-10-21 00:25:38 -04:00
|
|
|
return(strcmp(pkg1->name, pkg2->name));
|
2007-11-18 13:05:47 -05:00
|
|
|
}
|
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
/* Test for existence of a package in a alpm_list_t*
|
|
|
|
* of pmpkg_t*
|
|
|
|
*/
|
2008-05-01 17:58:33 -04:00
|
|
|
pmpkg_t *_alpm_pkg_find(alpm_list_t *haystack, const char *needle)
|
2006-11-20 04:10:23 -05:00
|
|
|
{
|
2007-07-18 10:26:21 -04:00
|
|
|
alpm_list_t *lp;
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
ALPM_LOG_FUNC;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
if(needle == NULL || haystack == NULL) {
|
|
|
|
return(NULL);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-01-30 03:14:10 -05:00
|
|
|
|
2007-07-18 10:26:21 -04:00
|
|
|
for(lp = haystack; lp; lp = lp->next) {
|
|
|
|
pmpkg_t *info = lp->data;
|
2006-11-20 04:10:23 -05:00
|
|
|
|
2009-10-21 00:25:38 -04:00
|
|
|
if(info && strcmp(info->name, needle) == 0) {
|
2007-07-18 10:26:21 -04:00
|
|
|
return(info);
|
|
|
|
}
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
2007-07-18 10:26:21 -04:00
|
|
|
return(NULL);
|
2006-11-20 04:10:23 -05:00
|
|
|
}
|
|
|
|
|
2007-11-09 20:13:29 -05:00
|
|
|
/** Test if a package should be ignored.
|
|
|
|
*
|
|
|
|
* Checks if the package is ignored via IgnorePkg, or if the package is
|
|
|
|
* in a group ignored via IgnoreGrp.
|
|
|
|
*
|
|
|
|
* @param pkg the package to test
|
|
|
|
*
|
|
|
|
* @return 1 if the package should be ignored, 0 otherwise
|
|
|
|
*/
|
|
|
|
int _alpm_pkg_should_ignore(pmpkg_t *pkg)
|
|
|
|
{
|
|
|
|
alpm_list_t *groups = NULL;
|
|
|
|
|
|
|
|
/* first see if the package is ignored */
|
|
|
|
if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next see if the package is in a group that is ignored */
|
|
|
|
for(groups = handle->ignoregrp; groups; groups = alpm_list_next(groups)) {
|
|
|
|
char *grp = (char *)alpm_list_getdata(groups);
|
|
|
|
if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|