diff options
Diffstat (limited to 'lib/libalpm/db.c')
-rw-r--r-- | lib/libalpm/db.c | 78 |
1 files changed, 30 insertions, 48 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 1485c34a..e8ae11a3 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -39,8 +39,7 @@ #include "alpm_list.h" #include "log.h" #include "util.h" -#include "error.h" -#include "server.h" +#include "dload.h" #include "handle.h" #include "cache.h" #include "alpm.h" @@ -190,14 +189,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); @@ -217,7 +211,6 @@ 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; @@ -250,29 +243,21 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) /* 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); + ret = _alpm_download_single_file(path, db->servers, dbpath, + lastupdate, &newmtime); + 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); + /* pm_errno was set by the download code */ + _alpm_log(PM_LOG_DEBUG, "failed to sync db: %s\n", alpm_strerrorlast()); + return(-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); - } + /* form the path to the db location */ snprintf(path, PATH_MAX, "%s%s" DBEXT, dbpath, db->treename); /* remove the old dir */ @@ -293,6 +278,12 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) if(_alpm_db_install(db, path) == -1) { return -1; } + /* if we have a new mtime, set the DB last update value */ + if(newmtime) { + _alpm_log(PM_LOG_DEBUG, "sync: new mtime for %s: %ju\n", + db->treename, (uintmax_t)newmtime); + _alpm_db_setlastupdate(db, newmtime); + } } return(0); @@ -319,8 +310,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 +318,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); } @@ -445,26 +434,21 @@ 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; @@ -500,18 +484,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(®, 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(®, name, 0, 0, 0) == 0 || strstr(name, targ))) { + matched = name; } /* check desc */ - else if (regexec(®, alpm_pkg_get_desc(pkg), 0, 0, 0) == 0) { - matched = alpm_pkg_get_desc(pkg); + else if (desc && regexec(®, desc, 0, 0, 0) == 0) { + matched = desc; } /* check provides */ /* TODO: should we be doing this, and should we print something |