summaryrefslogtreecommitdiff
path: root/lib/libalpm/db.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/db.c')
-rw-r--r--lib/libalpm/db.c207
1 files changed, 20 insertions, 187 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 1485c34a..df16c3c9 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -39,8 +39,6 @@
#include "alpm_list.h"
#include "log.h"
#include "util.h"
-#include "error.h"
-#include "server.h"
#include "handle.h"
#include "cache.h"
#include "alpm.h"
@@ -190,14 +188,9 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
}
if(url && strlen(url)) {
- pmserver_t *server;
- if((server = _alpm_server_new(url)) == NULL) {
- /* pm_errno is set by _alpm_server_new */
- return(-1);
- }
- db->servers = alpm_list_add(db->servers, server);
- _alpm_log(PM_LOG_DEBUG, "adding new server to database '%s': protocol '%s', server '%s', path '%s'\n",
- db->treename, server->s_url->scheme, server->s_url->host, server->s_url->doc);
+ db->servers = alpm_list_add(db->servers, strdup(url));
+ _alpm_log(PM_LOG_DEBUG, "adding new server URL to database '%s': %s\n",
+ db->treename, url);
} else {
FREELIST(db->servers);
_alpm_log(PM_LOG_DEBUG, "serverlist flushed for '%s'\n", db->treename);
@@ -206,98 +199,6 @@ int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url)
return(0);
}
-/** Update a package database
- * @param force if true, then forces the update, otherwise update only in case
- * the database isn't up to date
- * @param db pointer to the package database to update
- * @return 0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up
- * to date
- */
-int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
-{
- alpm_list_t *lp;
- char path[PATH_MAX];
- alpm_list_t *files = NULL;
- time_t newmtime = 0, lastupdate = 0;
- const char *dbpath;
- int ret;
-
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- /* Verify we are in a transaction. This is done _mainly_ because we need a DB
- * lock - if we update without a db lock, we may kludge some other pacman
- * process that _has_ a lock.
- */
- ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(handle->trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- ASSERT(handle->trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1));
-
- if(!alpm_list_find_ptr(handle->dbs_sync, db)) {
- RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
- }
-
- if(!force) {
- /* get the lastupdate time */
- lastupdate = _alpm_db_getlastupdate(db);
- if(lastupdate == 0) {
- _alpm_log(PM_LOG_DEBUG, "failed to get lastupdate time for %s\n",
- db->treename);
- }
- }
-
- /* build a one-element list */
- snprintf(path, PATH_MAX, "%s" DBEXT, db->treename);
- files = alpm_list_add(files, strdup(path));
-
- dbpath = alpm_option_get_dbpath();
-
- ret = _alpm_downloadfiles_forreal(db->servers, dbpath, files, lastupdate,
- &newmtime, NULL, 0);
- FREELIST(files);
- if(ret == 1) {
- /* mtimes match, do nothing */
- pm_errno = 0;
- return(1);
- } else if(ret == -1) {
- /* we use downloadLastErrString and downloadLastErrCode here, error returns from
- * libdownload */
- _alpm_log(PM_LOG_DEBUG, "failed to sync db: %s [%d]\n",
- downloadLastErrString, downloadLastErrCode);
- RET_ERR(PM_ERR_DB_SYNC, -1);
- } else {
- if(newmtime != 0) {
- _alpm_log(PM_LOG_DEBUG, "sync: new mtime for %s: %ju\n",
- db->treename, (uintmax_t)newmtime);
- _alpm_db_setlastupdate(db, newmtime);
- }
- snprintf(path, PATH_MAX, "%s%s" DBEXT, dbpath, db->treename);
-
- /* remove the old dir */
- _alpm_log(PM_LOG_DEBUG, "flushing database %s\n", db->path);
- for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
- pmpkg_t *pkg = lp->data;
- if(pkg && _alpm_db_remove(db, pkg) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s%s\n"), db->treename,
- alpm_pkg_get_name(pkg));
- RET_ERR(PM_ERR_DB_REMOVE, -1);
- }
- }
-
- /* Cache needs to be rebuild */
- _alpm_db_free_pkgcache(db);
-
- /* uncompress the sync database */
- if(_alpm_db_install(db, path) == -1) {
- return -1;
- }
- }
-
- return(0);
-}
-
/** Get the name of a package database
* @param db pointer to the package database
* @return the name of the package database, NULL on error
@@ -319,8 +220,7 @@ const char SYMEXPORT *alpm_db_get_name(const pmdb_t *db)
*/
const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
{
- char path[PATH_MAX];
- pmserver_t *s;
+ char *url;
ALPM_LOG_FUNC;
@@ -328,10 +228,9 @@ const char SYMEXPORT *alpm_db_get_url(const pmdb_t *db)
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
- s = (pmserver_t*)db->servers->data;
+ url = (char*)db->servers->data;
- snprintf(path, PATH_MAX, "%s://%s%s", s->s_url->scheme, s->s_url->host, s->s_url->doc);
- return strdup(path);
+ return(url);
}
@@ -367,23 +266,6 @@ alpm_list_t SYMEXPORT *alpm_db_getpkgcache(pmdb_t *db)
return(_alpm_db_get_pkgcache(db));
}
-/** Get the list of packages that a package provides
- * @param db pointer to the package database to get the package from
- * @param name name of the package
- * @return the list of packages on success, NULL on error
- */
-alpm_list_t SYMEXPORT *alpm_db_whatprovides(pmdb_t *db, const char *name)
-{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(handle != NULL, return(NULL));
- ASSERT(db != NULL, return(NULL));
- ASSERT(name != NULL && strlen(name) != 0, return(NULL));
-
- return(_alpm_db_whatprovides(db, name));
-}
-
/** Get a group entry from a package database
* @param db pointer to the package database to get the group from
* @param name of the group
@@ -445,35 +327,31 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename)
CALLOC(db->path, 1, pathsize, RET_ERR(PM_ERR_MEMORY, NULL));
sprintf(db->path, "%s%s/", dbpath, treename);
-
- strncpy(db->treename, treename, PATH_MAX);
+ STRDUP(db->treename, treename, RET_ERR(PM_ERR_MEMORY, NULL));
return(db);
}
void _alpm_db_free(pmdb_t *db)
{
- alpm_list_t *tmp;
-
ALPM_LOG_FUNC;
/* cleanup pkgcache */
_alpm_db_free_pkgcache(db);
/* cleanup server list */
- for(tmp = db->servers; tmp; tmp = alpm_list_next(tmp)) {
- _alpm_server_free(tmp->data);
- }
- alpm_list_free(db->servers);
+ FREELIST(db->servers);
FREE(db->path);
+ FREE(db->treename);
FREE(db);
return;
}
-int _alpm_db_cmp(const void *db1, const void *db2)
+int _alpm_db_cmp(const void *d1, const void *d2)
{
- ALPM_LOG_FUNC;
- return(strcmp(((pmdb_t *)db1)->treename, ((pmdb_t *)db2)->treename));
+ pmdb_t *db1 = (pmdb_t *)db1;
+ pmdb_t *db2 = (pmdb_t *)db2;
+ return(strcmp(db1->treename, db2->treename));
}
alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
@@ -500,18 +378,16 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, const alpm_list_t *needles)
for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
pmpkg_t *pkg = j->data;
const char *matched = NULL;
+ const char *name = alpm_pkg_get_name(pkg);
+ const char *desc = alpm_pkg_get_desc(pkg);
- /* check name */
- if (regexec(&reg, alpm_pkg_get_name(pkg), 0, 0, 0) == 0) {
- matched = alpm_pkg_get_name(pkg);
- }
- /* check plain text name */
- else if (strstr(alpm_pkg_get_name(pkg), targ)) {
- matched = alpm_pkg_get_name(pkg);
+ /* check name as regex AND as plain text */
+ if(name && (regexec(&reg, name, 0, 0, 0) == 0 || strstr(name, targ))) {
+ matched = name;
}
/* check desc */
- else if (regexec(&reg, alpm_pkg_get_desc(pkg), 0, 0, 0) == 0) {
- matched = alpm_pkg_get_desc(pkg);
+ else if (desc && regexec(&reg, desc, 0, 0, 0) == 0) {
+ matched = desc;
}
/* check provides */
/* TODO: should we be doing this, and should we print something
@@ -641,47 +517,4 @@ pmdb_t *_alpm_db_register_sync(const char *treename)
return(db);
}
-/* helper function for alpm_list_find and _alpm_db_whatprovides
- *
- * @return "provision.name" == needle (as string)
- */
-int _alpm_prov_cmp(const void *provision, const void *needle)
-{
- char *tmpptr;
- char *provname = strdup(provision);
- int retval = 0;
- tmpptr = strchr(provname, '=');
-
- if(tmpptr != NULL) { /* provision-version */
- *tmpptr='\0';
- }
- retval = strcmp(provname, needle);
- free(provname);
- return(retval);
-}
-
-/* return a alpm_list_t of packages in "db" that provide "package"
- */
-alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, const char *package)
-{
- alpm_list_t *pkgs = NULL;
- alpm_list_t *lp;
-
- ALPM_LOG_FUNC;
-
- if(db == NULL || package == NULL || strlen(package) == 0) {
- return(NULL);
- }
-
- for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
- pmpkg_t *info = lp->data;
-
- if(alpm_list_find(alpm_pkg_get_provides(info), (const void *)package, _alpm_prov_cmp)) {
- pkgs = alpm_list_add(pkgs, info);
- }
- }
-
- return(pkgs);
-}
-
/* vim: set ts=2 sw=2 noet: */