2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* db.c
|
2007-11-16 21:18:45 -05:00
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2006-2011 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) 2006 by David Kimpe <dnaku@frugalware.org>
|
|
|
|
* 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2007-01-16 22:57:53 -05:00
|
|
|
#include <regex.h>
|
2007-03-05 17:13:33 -05:00
|
|
|
|
|
|
|
/* libalpm */
|
|
|
|
#include "db.h"
|
|
|
|
#include "alpm_list.h"
|
2005-03-28 03:21:17 -05:00
|
|
|
#include "log.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
#include "util.h"
|
2006-10-15 15:31:03 -04:00
|
|
|
#include "handle.h"
|
2005-03-28 03:21:17 -05:00
|
|
|
#include "alpm.h"
|
2008-05-11 17:49:01 -04:00
|
|
|
#include "package.h"
|
2010-10-13 08:56:35 -04:00
|
|
|
#include "group.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** \addtogroup alpm_databases Database Functions
|
|
|
|
* @brief Functions to query and manipulate the database of libalpm
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Register a sync database of packages. */
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_db_t SYMEXPORT *alpm_register_syncdb(alpm_handle_t *handle,
|
2011-06-27 17:29:49 -04:00
|
|
|
const char *treename, alpm_siglevel_t level)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
|
|
|
/* Sanity checks */
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return NULL);
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(treename != NULL && strlen(treename) != 0,
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL));
|
2007-06-03 23:57:38 -04:00
|
|
|
/* Do not register a database if a transaction is on-going */
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, NULL));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-06-27 17:29:49 -04:00
|
|
|
return _alpm_db_register_sync(handle, treename, level);
|
2007-08-26 22:42:17 -04:00
|
|
|
}
|
|
|
|
|
2007-08-21 23:29:10 -04:00
|
|
|
/* Helper function for alpm_db_unregister{_all} */
|
2011-06-28 00:11:43 -04:00
|
|
|
void _alpm_db_unregister(alpm_db_t *db)
|
2007-08-21 23:29:10 -04:00
|
|
|
{
|
|
|
|
if(db == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "unregistering database '%s'\n", db->treename);
|
2007-08-21 23:29:10 -04:00
|
|
|
_alpm_db_free(db);
|
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Unregister all package databases. */
|
2012-02-02 00:45:52 -05:00
|
|
|
int SYMEXPORT alpm_unregister_all_syncdbs(alpm_handle_t *handle)
|
2007-07-09 11:02:29 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db;
|
2007-07-09 11:02:29 -04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-14 11:01:08 -04:00
|
|
|
CHECK_HANDLE(handle, return -1);
|
2007-07-09 11:02:29 -04:00
|
|
|
/* Do not unregister a database if a transaction is on-going */
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
|
2007-07-09 11:02:29 -04:00
|
|
|
|
2011-03-29 03:20:54 -04:00
|
|
|
/* unregister all sync dbs */
|
2007-07-09 11:02:29 -04:00
|
|
|
for(i = handle->dbs_sync; i; i = i->next) {
|
2010-07-10 22:06:21 -04:00
|
|
|
db = i->data;
|
|
|
|
db->ops->unregister(db);
|
2007-07-09 11:02:29 -04:00
|
|
|
i->data = NULL;
|
|
|
|
}
|
|
|
|
FREELIST(handle->dbs_sync);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-07-09 11:02:29 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Unregister a package database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
int SYMEXPORT alpm_db_unregister(alpm_db_t *db)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
|
|
|
int found = 0;
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_handle_t *handle;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(db != NULL, return -1);
|
2007-06-03 23:57:38 -04:00
|
|
|
/* Do not unregister a database if a transaction is on-going */
|
2011-06-07 17:06:16 -04:00
|
|
|
handle = db->handle;
|
2011-06-14 11:01:08 -04:00
|
|
|
handle->pm_errno = 0;
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
if(db == handle->db_local) {
|
|
|
|
handle->db_local = NULL;
|
2007-06-03 23:57:38 -04:00
|
|
|
found = 1;
|
|
|
|
} else {
|
2007-08-21 23:29:10 -04:00
|
|
|
/* Warning : this function shouldn't be used to unregister all sync
|
|
|
|
* databases by walking through the list returned by
|
|
|
|
* alpm_option_get_syncdbs, because the db is removed from that list here.
|
2007-07-09 11:02:29 -04:00
|
|
|
*/
|
2007-06-03 23:57:38 -04:00
|
|
|
void *data;
|
2011-06-07 17:06:16 -04:00
|
|
|
handle->dbs_sync = alpm_list_remove(handle->dbs_sync,
|
2007-08-21 23:29:10 -04:00
|
|
|
db, _alpm_db_cmp, &data);
|
2007-06-03 23:57:38 -04:00
|
|
|
if(data) {
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!found) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(handle, ALPM_ERR_DB_NOT_FOUND, -1);
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2010-07-10 22:06:21 -04:00
|
|
|
db->ops->unregister(db);
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2010-10-18 17:39:04 -04:00
|
|
|
/** Get the serverlist of a database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_db_get_servers(const alpm_db_t *db)
|
2010-10-18 17:39:04 -04:00
|
|
|
{
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-13 18:43:09 -04:00
|
|
|
return db->servers;
|
2010-10-18 17:39:04 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Set the serverlist of a database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
int SYMEXPORT alpm_db_set_servers(alpm_db_t *db, alpm_list_t *servers)
|
2010-10-18 17:39:04 -04:00
|
|
|
{
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(db != NULL, return -1);
|
2010-10-18 17:39:04 -04:00
|
|
|
if(db->servers) FREELIST(db->servers);
|
|
|
|
db->servers = servers;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *sanitize_url(const char *url)
|
|
|
|
{
|
|
|
|
char *newurl;
|
|
|
|
size_t len = strlen(url);
|
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(newurl, url, return NULL);
|
2010-10-18 17:39:04 -04:00
|
|
|
/* strip the trailing slash if one exists */
|
|
|
|
if(newurl[len - 1] == '/') {
|
|
|
|
newurl[len - 1] = '\0';
|
|
|
|
}
|
|
|
|
return newurl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Add a download server to a database.
|
|
|
|
* @param db database pointer
|
|
|
|
* @param url url of the server
|
|
|
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2011-06-28 00:11:43 -04:00
|
|
|
int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char *url)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2008-08-03 19:16:08 -04:00
|
|
|
char *newurl;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(db != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2010-10-18 17:39:04 -04:00
|
|
|
newurl = sanitize_url(url);
|
|
|
|
if(!newurl) {
|
|
|
|
return -1;
|
2008-08-03 19:16:08 -04:00
|
|
|
}
|
2010-10-18 17:39:04 -04:00
|
|
|
db->servers = alpm_list_add(db->servers, newurl);
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
|
2010-10-18 17:39:04 -04:00
|
|
|
db->treename, newurl);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Remove a download server from a database.
|
|
|
|
* @param db database pointer
|
|
|
|
* @param url url of the server
|
|
|
|
* @return 0 on success, 1 on server not present,
|
|
|
|
* -1 on error (pm_errno is set accordingly)
|
|
|
|
*/
|
2011-06-28 00:11:43 -04:00
|
|
|
int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
|
2010-10-18 17:39:04 -04:00
|
|
|
{
|
|
|
|
char *newurl, *vdata = NULL;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
2011-06-07 17:06:16 -04:00
|
|
|
ASSERT(db != NULL, return -1);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
2011-07-01 12:01:39 -04:00
|
|
|
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
|
2010-10-18 17:39:04 -04:00
|
|
|
|
|
|
|
newurl = sanitize_url(url);
|
|
|
|
if(!newurl) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
db->servers = alpm_list_remove_str(db->servers, newurl, &vdata);
|
|
|
|
free(newurl);
|
|
|
|
if(vdata) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "removed server URL from database '%s': %s\n",
|
2008-08-03 19:16:08 -04:00
|
|
|
db->treename, newurl);
|
2010-10-18 17:39:04 -04:00
|
|
|
free(vdata);
|
|
|
|
return 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2010-10-18 17:39:04 -04:00
|
|
|
return 1;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Get the name of a package database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
const char SYMEXPORT *alpm_db_get_name(const alpm_db_t *db)
|
2007-06-05 17:34:33 -04:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2007-06-05 17:34:33 -04:00
|
|
|
return db->treename;
|
|
|
|
}
|
|
|
|
|
2011-06-24 16:41:56 -04:00
|
|
|
/** Get the signature verification level for a database. */
|
2011-06-27 17:29:49 -04:00
|
|
|
alpm_siglevel_t SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db)
|
2011-06-24 16:41:56 -04:00
|
|
|
{
|
|
|
|
ASSERT(db != NULL, return -1);
|
2011-06-27 17:29:49 -04:00
|
|
|
if(db->siglevel & ALPM_SIG_USE_DEFAULT) {
|
2011-08-19 20:12:21 -04:00
|
|
|
return db->handle->siglevel;
|
2011-06-24 16:41:56 -04:00
|
|
|
} else {
|
2011-06-27 17:29:49 -04:00
|
|
|
return db->siglevel;
|
2011-06-24 16:41:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 00:05:21 -04:00
|
|
|
/** Check the validity of a database. */
|
|
|
|
int SYMEXPORT alpm_db_get_valid(alpm_db_t *db)
|
|
|
|
{
|
|
|
|
ASSERT(db != NULL, return -1);
|
|
|
|
db->handle->pm_errno = 0;
|
|
|
|
return db->ops->validate(db);
|
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Get a package entry from a package database. */
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2011-07-06 14:37:18 -04:00
|
|
|
alpm_pkg_t *pkg;
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
|
|
|
ASSERT(name != NULL && strlen(name) != 0,
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-07-06 14:37:18 -04:00
|
|
|
pkg = _alpm_db_get_pkgfromcache(db, name);
|
|
|
|
if(!pkg) {
|
|
|
|
RET_ERR(db->handle, ALPM_ERR_PKG_NOT_FOUND, NULL);
|
|
|
|
}
|
|
|
|
return pkg;
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Get the package cache of a package database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db)
|
2011-01-24 20:49:34 -05:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
2011-03-20 20:45:57 -04:00
|
|
|
return _alpm_db_get_pkgcache(db);
|
2011-01-24 20:49:34 -05:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Get a group entry from a package database. */
|
2012-02-02 00:45:52 -05:00
|
|
|
alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
|
|
|
ASSERT(name != NULL && strlen(name) != 0,
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-06-29 01:52:33 -04:00
|
|
|
return _alpm_db_get_groupfromcache(db, name);
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Get the group cache of a package database. */
|
2011-06-29 01:46:49 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-06-29 01:46:49 -04:00
|
|
|
return _alpm_db_get_groupcache(db);
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2011-03-06 12:44:03 -05:00
|
|
|
/** Searches a database. */
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t* needles)
|
2007-06-03 23:57:38 -04:00
|
|
|
{
|
2011-03-20 20:45:57 -04:00
|
|
|
ASSERT(db != NULL, return NULL);
|
2011-06-14 11:01:08 -04:00
|
|
|
db->handle->pm_errno = 0;
|
2007-06-03 23:57:38 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return _alpm_db_search(db, needles);
|
2007-06-03 23:57:38 -04:00
|
|
|
}
|
|
|
|
|
2009-05-20 15:46:23 -04:00
|
|
|
|
2007-06-03 23:57:38 -04:00
|
|
|
/** @} */
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *_alpm_db_new(const char *treename, int is_local)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_db_t *db;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
CALLOC(db, 1, sizeof(alpm_db_t), return NULL);
|
2011-06-07 17:06:16 -04:00
|
|
|
STRDUP(db->treename, treename, return NULL);
|
2011-08-17 22:06:04 -04:00
|
|
|
if(is_local) {
|
|
|
|
db->status |= DB_STATUS_LOCAL;
|
|
|
|
} else {
|
|
|
|
db->status &= ~DB_STATUS_LOCAL;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return db;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
void _alpm_db_free(alpm_db_t *db)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2007-08-21 23:29:10 -04:00
|
|
|
/* cleanup pkgcache */
|
|
|
|
_alpm_db_free_pkgcache(db);
|
|
|
|
/* cleanup server list */
|
2008-01-22 23:49:45 -05:00
|
|
|
FREELIST(db->servers);
|
2009-09-14 23:44:51 -04:00
|
|
|
FREE(db->_path);
|
2008-03-26 21:19:44 -04:00
|
|
|
FREE(db->treename);
|
2006-10-31 01:39:59 -05:00
|
|
|
FREE(db);
|
2006-10-15 15:31:03 -04:00
|
|
|
|
|
|
|
return;
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
const char *_alpm_db_path(alpm_db_t *db)
|
2009-09-14 23:44:51 -04:00
|
|
|
{
|
|
|
|
if(!db) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2009-09-14 23:44:51 -04:00
|
|
|
}
|
|
|
|
if(!db->_path) {
|
|
|
|
const char *dbpath;
|
|
|
|
size_t pathsize;
|
|
|
|
|
2011-08-19 20:12:21 -04:00
|
|
|
dbpath = db->handle->dbpath;
|
2009-09-14 23:44:51 -04:00
|
|
|
if(!dbpath) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("database path is undefined\n"));
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, NULL);
|
2009-09-14 23:44:51 -04:00
|
|
|
}
|
|
|
|
|
2011-08-17 22:06:04 -04:00
|
|
|
if(db->status & DB_STATUS_LOCAL) {
|
2009-09-14 23:44:51 -04:00
|
|
|
pathsize = strlen(dbpath) + strlen(db->treename) + 2;
|
2011-07-01 12:01:39 -04:00
|
|
|
CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, ALPM_ERR_MEMORY, NULL));
|
2009-09-14 23:44:51 -04:00
|
|
|
sprintf(db->_path, "%s%s/", dbpath, db->treename);
|
|
|
|
} else {
|
2010-10-09 09:31:29 -04:00
|
|
|
pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 4;
|
2011-07-01 12:01:39 -04:00
|
|
|
CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, ALPM_ERR_MEMORY, NULL));
|
2009-09-14 23:44:51 -04:00
|
|
|
/* all sync DBs now reside in the sync/ subdir of the dbpath */
|
2010-10-09 09:31:29 -04:00
|
|
|
sprintf(db->_path, "%ssync/%s.db", dbpath, db->treename);
|
2009-09-14 23:44:51 -04:00
|
|
|
}
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "database path for tree %s set to %s\n",
|
2009-09-14 23:44:51 -04:00
|
|
|
db->treename, db->_path);
|
|
|
|
}
|
2011-03-20 20:45:57 -04:00
|
|
|
return db->_path;
|
2009-09-14 23:44:51 -04: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
|
|
|
int _alpm_db_cmp(const void *d1, const void *d2)
|
2006-03-08 13:07:58 -05:00
|
|
|
{
|
2011-09-18 18:07:05 -04:00
|
|
|
const alpm_db_t *db1 = d1;
|
|
|
|
const alpm_db_t *db2 = d2;
|
2011-03-20 20:45:57 -04:00
|
|
|
return strcmp(db1->treename, db2->treename);
|
2006-03-08 13:07:58 -05:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t *_alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
|
2006-10-15 15:31:03 -04:00
|
|
|
{
|
2007-06-05 17:34:33 -04:00
|
|
|
const alpm_list_t *i, *j, *k;
|
|
|
|
alpm_list_t *ret = NULL;
|
2008-07-24 06:26:09 -04:00
|
|
|
/* copy the pkgcache- we will free the list var after each needle */
|
2011-02-25 09:22:09 -05:00
|
|
|
alpm_list_t *list = alpm_list_copy(_alpm_db_get_pkgcache(db));
|
2006-10-15 15:31:03 -04:00
|
|
|
|
|
|
|
for(i = needles; i; i = i->next) {
|
|
|
|
char *targ;
|
2007-02-26 18:32:08 -05:00
|
|
|
regex_t reg;
|
2006-10-15 15:31:03 -04:00
|
|
|
|
|
|
|
if(i->data == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-24 06:26:09 -04:00
|
|
|
ret = NULL;
|
2007-01-16 22:57:53 -05:00
|
|
|
targ = i->data;
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "searching for target '%s'\n", targ);
|
2007-11-16 21:18:45 -05:00
|
|
|
|
2007-02-26 18:32:08 -05:00
|
|
|
if(regcomp(®, targ, REG_EXTENDED | REG_NOSUB | REG_ICASE | REG_NEWLINE) != 0) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_INVALID_REGEX, NULL);
|
2007-02-26 18:32:08 -05:00
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2008-07-24 06:26:09 -04:00
|
|
|
for(j = list; j; j = j->next) {
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = j->data;
|
2007-03-03 03:13:59 -05:00
|
|
|
const char *matched = NULL;
|
2011-08-18 00:25:19 -04:00
|
|
|
const char *name = pkg->name;
|
2008-01-11 01:01:58 -05:00
|
|
|
const char *desc = alpm_pkg_get_desc(pkg);
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2008-01-11 01:01:58 -05:00
|
|
|
/* check name as regex AND as plain text */
|
|
|
|
if(name && (regexec(®, name, 0, 0, 0) == 0 || strstr(name, targ))) {
|
|
|
|
matched = name;
|
2007-11-15 01:07:31 -05:00
|
|
|
}
|
2007-01-16 22:57:53 -05:00
|
|
|
/* check desc */
|
2011-04-20 20:45:16 -04:00
|
|
|
else if(desc && regexec(®, desc, 0, 0, 0) == 0) {
|
2008-01-11 01:01:58 -05:00
|
|
|
matched = desc;
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2007-02-26 18:32:08 -05:00
|
|
|
/* TODO: should we be doing this, and should we print something
|
|
|
|
* differently when we do match it since it isn't currently printed? */
|
2009-06-06 13:30:30 -04:00
|
|
|
if(!matched) {
|
|
|
|
/* check provides */
|
2007-03-03 03:13:59 -05:00
|
|
|
for(k = alpm_pkg_get_provides(pkg); k; k = k->next) {
|
2011-08-09 02:00:16 -04:00
|
|
|
alpm_depend_t *provide = k->data;
|
|
|
|
if(regexec(®, provide->name, 0, 0, 0) == 0) {
|
2011-12-29 15:23:47 -05:00
|
|
|
matched = provide->name;
|
2007-01-16 22:57:53 -05:00
|
|
|
break;
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-06 13:30:30 -04:00
|
|
|
if(!matched) {
|
|
|
|
/* check groups */
|
|
|
|
for(k = alpm_pkg_get_groups(pkg); k; k = k->next) {
|
2011-04-20 20:45:16 -04:00
|
|
|
if(regexec(®, k->data, 0, 0, 0) == 0) {
|
2009-06-06 13:30:30 -04:00
|
|
|
matched = k->data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
|
2007-01-16 22:57:53 -05:00
|
|
|
if(matched != NULL) {
|
2011-12-29 15:23:47 -05:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG,
|
|
|
|
"search target '%s' matched '%s'\n", targ, matched);
|
2007-01-19 04:28:44 -05:00
|
|
|
ret = alpm_list_add(ret, pkg);
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
|
|
|
}
|
2007-02-26 18:32:08 -05:00
|
|
|
|
2008-07-24 06:26:09 -04:00
|
|
|
/* Free the existing search list, and use the returned list for the
|
|
|
|
* next needle. This allows for AND-based package searching. */
|
|
|
|
alpm_list_free(list);
|
|
|
|
list = ret;
|
2007-02-26 18:32:08 -05:00
|
|
|
regfree(®);
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2006-10-15 15:31:03 -04:00
|
|
|
}
|
2006-10-20 02:26:55 -04:00
|
|
|
|
2010-10-13 08:56:35 -04:00
|
|
|
/* Returns a new package cache from db.
|
|
|
|
* It frees the cache if it already exists.
|
|
|
|
*/
|
2011-06-28 00:11:43 -04:00
|
|
|
static int load_pkgcache(alpm_db_t *db)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
_alpm_db_free_pkgcache(db);
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "loading package cache for repository '%s'\n",
|
2010-10-13 08:56:35 -04:00
|
|
|
db->treename);
|
|
|
|
if(db->ops->populate(db) == -1) {
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG,
|
2010-10-13 08:56:35 -04:00
|
|
|
"failed to load package cache for repository '%s'\n", db->treename);
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
db->status |= DB_STATUS_PKGCACHE;
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-07-06 14:40:03 -04:00
|
|
|
static void free_groupcache(alpm_db_t *db)
|
|
|
|
{
|
|
|
|
alpm_list_t *lg;
|
|
|
|
|
|
|
|
if(db == NULL || !(db->status & DB_STATUS_GRPCACHE)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG,
|
|
|
|
"freeing group cache for repository '%s'\n", db->treename);
|
|
|
|
|
|
|
|
for(lg = db->grpcache; lg; lg = lg->next) {
|
|
|
|
_alpm_group_free(lg->data);
|
|
|
|
lg->data = NULL;
|
|
|
|
}
|
|
|
|
FREELIST(db->grpcache);
|
|
|
|
db->status &= ~DB_STATUS_GRPCACHE;
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
void _alpm_db_free_pkgcache(alpm_db_t *db)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
2011-06-07 21:42:15 -04:00
|
|
|
if(db == NULL || !(db->status & DB_STATUS_PKGCACHE)) {
|
2010-10-13 08:56:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG,
|
2011-06-07 21:42:15 -04:00
|
|
|
"freeing package cache for repository '%s'\n", db->treename);
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-09-19 15:27:21 -04:00
|
|
|
if(db->pkgcache) {
|
|
|
|
alpm_list_free_inner(db->pkgcache->list,
|
2011-01-24 20:49:34 -05:00
|
|
|
(alpm_list_fn_free)_alpm_pkg_free);
|
2011-09-19 15:27:21 -04:00
|
|
|
_alpm_pkghash_free(db->pkgcache);
|
|
|
|
}
|
2011-06-07 21:42:15 -04:00
|
|
|
db->status &= ~DB_STATUS_PKGCACHE;
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-07-06 14:40:03 -04:00
|
|
|
free_groupcache(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:56:29 -04:00
|
|
|
alpm_pkghash_t *_alpm_db_get_pkgcache_hash(alpm_db_t *db)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
if(db == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
if(!(db->status & DB_STATUS_VALID)) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_DB_INVALID, NULL);
|
2011-06-07 21:42:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(db->status & DB_STATUS_PKGCACHE)) {
|
|
|
|
load_pkgcache(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return db->pkgcache;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:11:43 -04:00
|
|
|
alpm_list_t *_alpm_db_get_pkgcache(alpm_db_t *db)
|
2011-01-24 20:49:34 -05:00
|
|
|
{
|
2011-06-28 00:56:29 -04:00
|
|
|
alpm_pkghash_t *hash = _alpm_db_get_pkgcache_hash(db);
|
2011-01-24 20:49:34 -05:00
|
|
|
|
|
|
|
if(hash == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2011-01-24 20:49:34 -05:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return hash->list;
|
2011-01-24 20:49:34 -05:00
|
|
|
}
|
|
|
|
|
2010-10-13 08:56:35 -04:00
|
|
|
/* "duplicate" pkg then add it to pkgcache */
|
2011-06-28 09:26:39 -04:00
|
|
|
int _alpm_db_add_pkgincache(alpm_db_t *db, alpm_pkg_t *pkg)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *newpkg;
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
if(db == NULL || pkg == NULL || !(db->status & DB_STATUS_PKGCACHE)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-08-19 12:06:55 -04:00
|
|
|
if(_alpm_pkg_dup(pkg, &newpkg)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding entry '%s' in '%s' cache\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
newpkg->name, db->treename);
|
2011-01-24 20:49:34 -05:00
|
|
|
db->pkgcache = _alpm_pkghash_add_sorted(db->pkgcache, newpkg);
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-07-06 14:40:03 -04:00
|
|
|
free_groupcache(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
int _alpm_db_remove_pkgfromcache(alpm_db_t *db, alpm_pkg_t *pkg)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *data = NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
if(db == NULL || pkg == NULL || !(db->status & DB_STATUS_PKGCACHE)) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "removing entry '%s' from '%s' cache\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
pkg->name, db->treename);
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-01-30 07:42:45 -05:00
|
|
|
db->pkgcache = _alpm_pkghash_remove(db->pkgcache, pkg, &data);
|
2010-10-13 08:56:35 -04:00
|
|
|
if(data == NULL) {
|
|
|
|
/* package not found */
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "cannot remove entry '%s' from '%s' cache: not found\n",
|
2011-08-18 00:25:19 -04:00
|
|
|
pkg->name, db->treename);
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_alpm_pkg_free(data);
|
|
|
|
|
2011-07-06 14:40:03 -04:00
|
|
|
free_groupcache(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *_alpm_db_get_pkgfromcache(alpm_db_t *db, const char *target)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
if(db == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-28 00:56:29 -04:00
|
|
|
alpm_pkghash_t *pkgcache = _alpm_db_get_pkgcache_hash(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
if(!pkgcache) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return _alpm_pkghash_find(pkgcache, target);
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns a new group cache from db.
|
|
|
|
*/
|
2011-06-28 00:11:43 -04:00
|
|
|
static int load_grpcache(alpm_db_t *db)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *lp;
|
|
|
|
|
|
|
|
if(db == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return -1;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 12:01:38 -04:00
|
|
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "loading group cache for repository '%s'\n",
|
2010-10-13 08:56:35 -04:00
|
|
|
db->treename);
|
|
|
|
|
2011-02-25 09:22:09 -05:00
|
|
|
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
|
2010-10-13 08:56:35 -04:00
|
|
|
const alpm_list_t *i;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg = lp->data;
|
2010-10-13 08:56:35 -04:00
|
|
|
|
|
|
|
for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {
|
|
|
|
const char *grpname = i->data;
|
|
|
|
alpm_list_t *j;
|
2011-06-28 00:37:16 -04:00
|
|
|
alpm_group_t *grp = NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
/* first look through the group cache for a group with this name */
|
|
|
|
for(j = db->grpcache; j; j = j->next) {
|
|
|
|
grp = j->data;
|
|
|
|
|
|
|
|
if(strcmp(grp->name, grpname) == 0
|
|
|
|
&& !alpm_list_find_ptr(grp->packages, pkg)) {
|
|
|
|
grp->packages = alpm_list_add(grp->packages, pkg);
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(found) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* we didn't find the group, so create a new one with this name */
|
2011-06-29 01:52:33 -04:00
|
|
|
grp = _alpm_group_new(grpname);
|
2011-06-07 17:06:16 -04:00
|
|
|
if(!grp) {
|
2011-07-06 14:40:03 -04:00
|
|
|
free_groupcache(db);
|
2011-06-07 17:06:16 -04:00
|
|
|
return -1;
|
|
|
|
}
|
2010-10-13 08:56:35 -04:00
|
|
|
grp->packages = alpm_list_add(grp->packages, pkg);
|
|
|
|
db->grpcache = alpm_list_add(db->grpcache, grp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
db->status |= DB_STATUS_GRPCACHE;
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-29 01:46:49 -04:00
|
|
|
alpm_list_t *_alpm_db_get_groupcache(alpm_db_t *db)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
if(db == NULL) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-07 21:42:15 -04:00
|
|
|
if(!(db->status & DB_STATUS_VALID)) {
|
2011-07-01 12:01:39 -04:00
|
|
|
RET_ERR(db->handle, ALPM_ERR_DB_INVALID, NULL);
|
2011-06-07 21:42:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!(db->status & DB_STATUS_GRPCACHE)) {
|
|
|
|
load_grpcache(db);
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return db->grpcache;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-29 01:52:33 -04:00
|
|
|
alpm_group_t *_alpm_db_get_groupfromcache(alpm_db_t *db, const char *target)
|
2010-10-13 08:56:35 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
|
|
|
|
if(db == NULL || target == NULL || strlen(target) == 0) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2011-06-29 01:46:49 -04:00
|
|
|
for(i = _alpm_db_get_groupcache(db); i; i = i->next) {
|
2011-06-28 00:37:16 -04:00
|
|
|
alpm_group_t *info = i->data;
|
2010-10-13 08:56:35 -04:00
|
|
|
|
|
|
|
if(strcmp(info->name, target) == 0) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return info;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return NULL;
|
2010-10-13 08:56:35 -04:00
|
|
|
}
|
|
|
|
|
2006-12-20 20:53:40 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|