summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/Makefile.am7
-rw-r--r--lib/libalpm/add.c5
-rw-r--r--lib/libalpm/alpm.c41
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/backup.c7
-rw-r--r--lib/libalpm/be_files.c1
-rw-r--r--lib/libalpm/cache.c47
-rw-r--r--lib/libalpm/cache.h5
-rw-r--r--lib/libalpm/conflict.c4
-rw-r--r--lib/libalpm/db.c6
-rw-r--r--lib/libalpm/deps.c25
-rw-r--r--lib/libalpm/error.c2
-rw-r--r--lib/libalpm/group.c2
-rw-r--r--lib/libalpm/handle.c11
-rw-r--r--lib/libalpm/list.c7
-rw-r--r--lib/libalpm/package.c2
-rw-r--r--lib/libalpm/provide.c2
-rw-r--r--lib/libalpm/remove.c6
-rw-r--r--lib/libalpm/server.c518
-rw-r--r--lib/libalpm/server.h20
-rw-r--r--lib/libalpm/sync.c36
-rw-r--r--lib/libalpm/trans.c2
-rw-r--r--lib/libalpm/util.c74
-rw-r--r--lib/libalpm/util.h1
24 files changed, 345 insertions, 489 deletions
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index a656d7e6..9bee7b59 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -1,7 +1,6 @@
AUTOMAKE_OPTIONS = gnu
DEFINES = -pedantic -D_GNU_SOURCE
-AM_CFLAGS = $(DEFINES) \
- -I$(top_srcdir)/lib/libftp
+AM_CFLAGS = $(DEFINES) -I$(top_srcdir)/lib/libfetch
SUBDIRS = po
localedir = $(datadir)/locale
@@ -38,8 +37,8 @@ include_HEADERS = alpm.h
libalpm_la_SOURCES = $(TARGETS)
-libalpm_la_LDFLAGS = -no-undefined -version-info $(PM_VERSION_INFO)
-libalpm_la_LIBADD = $(top_srcdir)/lib/libftp/libftp.la
+libalpm_la_LDFLAGS = -no-undefined -version-info $(PM_VERSION_INFO) -L$(top_srcdir)/lib/libfetch
+libalpm_la_LIBADD = -lfetch
if HAS_DOXYGEN
all: doxygen.in
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 82b238bd..16cb13a5 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -306,7 +306,7 @@ int _alpm_add_prepare(pmtrans_t *trans, pmdb_t *db, pmlist_t **data)
int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
{
int i, ret = 0, errors = 0, needdisp = 0;
- double percent;
+ double percent = 0.0;
register struct archive *archive;
struct archive_entry *entry;
char expath[PATH_MAX], cwd[PATH_MAX] = "", *what;
@@ -360,7 +360,6 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* copy over the install reason */
if(!(local->infolevel & INFRQ_DESC)) {
- _alpm_log(PM_LOG_DEBUG, _("loading DESC info for '%s'"), local->name);
_alpm_db_read(db, INFRQ_DESC, local);
}
info->reason = local->reason;
@@ -732,7 +731,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* Update the requiredby field by scanning the whole database
* looking for packages depending on the package to add */
- for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); lp; lp = lp->next) {
pmpkg_t *tmpp = lp->data;
pmlist_t *tmppm = NULL;
if(tmpp == NULL) {
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 0c5f28e7..5eb36006 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -197,8 +197,8 @@ int alpm_db_unregister(pmdb_t *db)
handle->db_local = NULL;
found = 1;
} else {
- pmdb_t *data;
- handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, db, _alpm_db_cmp, (void **)&data);
+ void *data;
+ handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, db, _alpm_db_cmp, &data);
if(data) {
found = 1;
}
@@ -240,12 +240,8 @@ void *alpm_db_getinfo(PM_DB *db, unsigned char parm)
case PM_DB_TREENAME: data = db->treename; break;
case PM_DB_FIRSTSERVER:
server = (pmserver_t*)db->servers->data;
- if(!strcmp(server->protocol, "file")) {
- snprintf(path, PATH_MAX, "%s://%s", server->protocol, server->path);
- } else {
- snprintf(path, PATH_MAX, "%s://%s%s", server->protocol,
- server->server, server->path);
- }
+ snprintf(path, PATH_MAX, "%s://%s%s", server->s_url->scheme,
+ server->s_url->host, server->s_url->doc);
data = strdup(path);
break;
default:
@@ -292,7 +288,7 @@ int alpm_db_setserver(pmdb_t *db, char *url)
}
db->servers = _alpm_list_add(db->servers, server);
_alpm_log(PM_LOG_FLOW2, _("adding new server to database '%s': protocol '%s', server '%s', path '%s'"),
- db->treename, server->protocol, server->server, server->path);
+ db->treename, server->s_url->scheme, server->s_url->host, server->s_url->doc);
} else {
FREELIST(db->servers);
_alpm_log(PM_LOG_FLOW2, _("serverlist flushed for '%s'"), db->treename);
@@ -343,12 +339,15 @@ int alpm_db_update(int force, PM_DB *db)
ret = _alpm_downloadfiles_forreal(db->servers, path, files, lastupdate, newmtime);
FREELIST(files);
- if(ret != 0) {
- if(ret > 0) {
- _alpm_log(PM_LOG_DEBUG, _("failed to sync db: %s [%d]\n"), alpm_strerror(ret), ret);
- pm_errno = PM_ERR_DB_SYNC;
- }
- return(ret);
+ if(ret == 1) {
+ /* mtimes match, do nothing */
+ pm_errno = 0;
+ return(1);
+ } else if(ret == -1) {
+ /* we use fetchLastErrString and fetchLastErrCode here, error returns from
+ * libfetch */
+ _alpm_log(PM_LOG_DEBUG, _("failed to sync db: %s [%d]\n"), fetchLastErrString, fetchLastErrCode);
+ RET_ERR(PM_ERR_DB_SYNC, -1);
} else {
if(strlen(newmtime)) {
_alpm_log(PM_LOG_DEBUG, _("sync: new mtime for %s: %s\n"), db->treename, newmtime);
@@ -358,7 +357,7 @@ int alpm_db_update(int force, PM_DB *db)
/* remove the old dir */
_alpm_log(PM_LOG_FLOW2, _("flushing database %s/%s"), handle->dbpath, db->treename);
- for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db, INFRQ_NONE); lp; lp = lp->next) {
if(_alpm_db_remove(db, lp->data) == -1) {
if(lp->data) {
_alpm_log(PM_LOG_ERROR, _("could not remove database entry %s/%s"), db->treename,
@@ -405,7 +404,7 @@ pmlist_t *alpm_db_getpkgcache(pmdb_t *db)
ASSERT(handle != NULL, return(NULL));
ASSERT(db != NULL, return(NULL));
- return(_alpm_db_get_pkgcache(db));
+ return(_alpm_db_get_pkgcache(db, INFRQ_NONE));
}
/** Get the list of packages that a package provides
@@ -496,7 +495,6 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
}
break;
/* Depends entry */
- /* not needed: the cache is loaded with DEPENDS by default
case PM_PKG_DEPENDS:
case PM_PKG_REQUIREDBY:
case PM_PKG_CONFLICTS:
@@ -506,7 +504,7 @@ void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm)
_alpm_log(PM_LOG_DEBUG, "loading DEPENDS info for '%s'", pkg->name);
_alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg);
}
- break;*/
+ break;
/* Files entry */
case PM_PKG_FILES:
case PM_PKG_BACKUP:
@@ -832,7 +830,7 @@ int alpm_trans_init(unsigned char type, unsigned int flags, alpm_trans_cb_event
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
/* lock db */
- snprintf(path, PATH_MAX, "%s/%s", handle->root, PM_LOCK);
+ snprintf(path, PATH_MAX, "%s%s", handle->root, PM_LOCK);
handle->lckfd = _alpm_lckmk(path);
if(handle->lckfd == -1) {
RET_ERR(PM_ERR_HANDLE_LOCK, -1);
@@ -949,7 +947,7 @@ int alpm_trans_release()
close(handle->lckfd);
handle->lckfd = -1;
}
- snprintf(path, PATH_MAX, "%s/%s", handle->root, PM_LOCK);
+ snprintf(path, PATH_MAX, "%s%s", handle->root, PM_LOCK);
if(_alpm_lckrm(path)) {
_alpm_log(PM_LOG_WARNING, _("could not remove lock file %s"), path);
alpm_logaction(_("warning: could not remove lock file %s"), path);
@@ -1373,7 +1371,6 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this
} else {
if(!strcmp(key, "SERVER")) {
/* add to the list */
- _alpm_log(PM_LOG_DEBUG, _("config: %s: server: %s\n"), section, ptr);
if(alpm_db_setserver(db, strdup(ptr)) != 0) {
/* pm_errno is set by alpm_set_option */
return(-1);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e3715b42..37ae9768 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -35,7 +35,7 @@ extern "C" {
#define PM_ROOT "/"
#define PM_DBPATH "var/lib/pacman"
#define PM_CACHEDIR "var/cache/pacman/pkg"
-#define PM_LOCK "/tmp/pacman.lck"
+#define PM_LOCK "tmp/pacman.lck"
#define PM_EXT_PKG ".pkg.tar.gz"
@@ -444,6 +444,7 @@ extern enum __pmerrno_t {
PM_ERR_PKG_CANT_FRESH,
PM_ERR_PKG_INVALID_NAME,
PM_ERR_PKG_CORRUPTED,
+ PM_ERR_PKG_REPO_NOT_FOUND,
/* Groups */
PM_ERR_GRP_NOT_FOUND,
/* Dependencies */
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index 1c969835..cf29abf0 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -27,6 +27,7 @@
#include <string.h>
/* pacman */
#include "backup.h"
+#include "util.h"
/* Look for a filename in a pmpkg_t.backup list. If we find it,
* then we return the md5 or sha1 hash (parsed from the same line)
@@ -47,7 +48,7 @@ char *_alpm_needbackup(char *file, pmlist_t *backup)
/* tab delimiter */
ptr = strchr(str, '\t');
if(ptr == NULL) {
- free(str);
+ FREE(str);
continue;
}
*ptr = '\0';
@@ -55,10 +56,10 @@ char *_alpm_needbackup(char *file, pmlist_t *backup)
/* now str points to the filename and ptr points to the md5 or sha1 hash */
if(!strcmp(file, str)) {
char *md5 = strdup(ptr);
- free(str);
+ FREE(str);
return(md5);
}
- free(str);
+ FREE(str);
}
return(NULL);
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index c2acb66a..6f9b1088 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -196,6 +196,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
if(stat(path, &buf)) {
/* directory doesn't exist or can't be opened */
+ _alpm_log(PM_LOG_ERROR, _("cannot find '%s-%s' in db '%s'"), info->name, info->version, db->treename);
return(-1);
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index 1115d111..b488d5be 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -32,6 +32,7 @@
#include "alpm.h"
#include "list.h"
#include "util.h"
+#include "error.h"
#include "package.h"
#include "group.h"
#include "db.h"
@@ -40,11 +41,11 @@
/* Returns a new package cache from db.
* It frees the cache if it already exists.
*/
-int _alpm_db_load_pkgcache(pmdb_t *db)
+int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel)
{
pmpkg_t *info;
/* The group cache needs INFRQ_DESC as well */
- unsigned char infolevel = INFRQ_DEPENDS | INFRQ_DESC;
+ /*unsigned char infolevel = INFRQ_DEPENDS | INFRQ_DESC;*/
if(db == NULL) {
return(-1);
@@ -82,19 +83,43 @@ void _alpm_db_free_pkgcache(pmdb_t *db)
}
}
-pmlist_t *_alpm_db_get_pkgcache(pmdb_t *db)
+pmlist_t *_alpm_db_get_pkgcache(pmdb_t *db, unsigned char infolevel)
{
if(db == NULL) {
return(NULL);
}
if(db->pkgcache == NULL) {
- _alpm_db_load_pkgcache(db);
+ _alpm_db_load_pkgcache(db, infolevel);
}
+ _alpm_db_ensure_pkgcache(db, infolevel);
+
return(db->pkgcache);
}
+int _alpm_db_ensure_pkgcache(pmdb_t *db, unsigned char infolevel)
+{
+ int reloaded = 0;
+ /* for each pkg, check and reload if the requested
+ * info is not already cached
+ */
+
+ pmlist_t *p;
+ for(p = db->pkgcache; p; p = p->next) {
+ pmpkg_t *pkg = (pmpkg_t *)p->data;
+ if(infolevel != INFRQ_NONE && !(pkg->infolevel & infolevel)) {
+ _alpm_db_read(db, infolevel, pkg);
+ reloaded = 1;
+ }
+ }
+ if(reloaded) {
+ _alpm_log(PM_LOG_DEBUG, _("package cache reloaded (infolevel=%#x) for repository '%s'"),
+ infolevel, db->treename);
+ }
+ return(0);
+}
+
int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
{
pmpkg_t *newpkg;
@@ -117,13 +142,15 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
{
+ void *vdata;
pmpkg_t *data;
if(db == NULL || pkg == NULL) {
return(-1);
}
- db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, _alpm_pkg_cmp, (void **)&data);
+ db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, _alpm_pkg_cmp, &vdata);
+ data = vdata;
if(data == NULL) {
/* package not found */
return(-1);
@@ -143,7 +170,7 @@ pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, char *target)
return(NULL);
}
- return(_alpm_pkg_isin(target, _alpm_db_get_pkgcache(db)));
+ return(_alpm_pkg_isin(target, _alpm_db_get_pkgcache(db, INFRQ_NONE)));
}
/* Returns a new group cache from db.
@@ -157,19 +184,15 @@ int _alpm_db_load_grpcache(pmdb_t *db)
}
if(db->pkgcache == NULL) {
- _alpm_db_load_pkgcache(db);
+ _alpm_db_load_pkgcache(db, INFRQ_DESC);
}
_alpm_log(PM_LOG_DEBUG, _("loading group cache for repository '%s'"), db->treename);
- for(lp = db->pkgcache; lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db, INFRQ_DESC); lp; lp = lp->next) {
pmlist_t *i;
pmpkg_t *pkg = lp->data;
- if(!(pkg->infolevel & INFRQ_DESC)) {
- _alpm_db_read(pkg->data, INFRQ_DESC, pkg);
- }
-
for(i = pkg->groups; i; i = i->next) {
if(!_alpm_list_is_strin(i->data, db->grpcache)) {
pmgrp_t *grp = _alpm_grp_new();
diff --git a/lib/libalpm/cache.h b/lib/libalpm/cache.h
index e6572970..b1187225 100644
--- a/lib/libalpm/cache.h
+++ b/lib/libalpm/cache.h
@@ -27,11 +27,12 @@
#include "db.h"
/* packages */
-int _alpm_db_load_pkgcache(pmdb_t *db);
+int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel);
void _alpm_db_free_pkgcache(pmdb_t *db);
int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg);
int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg);
-pmlist_t *_alpm_db_get_pkgcache(pmdb_t *db);
+pmlist_t *_alpm_db_get_pkgcache(pmdb_t *db, unsigned char infolevel);
+int _alpm_db_ensure_pkgcache(pmdb_t *db, unsigned char infolevel);
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, char *target);
/* groups */
int _alpm_db_load_grpcache(pmdb_t *db);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 6e7f0126..18a9f06f 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -70,7 +70,7 @@ pmlist_t *_alpm_checkconflicts(pmdb_t *db, pmlist_t *packages)
}
/* CHECK 1: check targets against database */
_alpm_log(PM_LOG_DEBUG, _("checkconflicts: targ '%s' vs db"), tp->name);
- for(k = _alpm_db_get_pkgcache(db); k; k = k->next) {
+ for(k = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); k; k = k->next) {
pmpkg_t *dp = (pmpkg_t *)k->data;
if(!strcmp(dp->name, tp->name)) {
/* a package cannot conflict with itself -- that's just not nice */
@@ -142,7 +142,7 @@ pmlist_t *_alpm_checkconflicts(pmdb_t *db, pmlist_t *packages)
}
/* CHECK 3: check database against targets */
_alpm_log(PM_LOG_DEBUG, _("checkconflicts: db vs targ '%s'"), tp->name);
- for(k = _alpm_db_get_pkgcache(db); k; k = k->next) {
+ for(k = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); k; k = k->next) {
pmlist_t *conflicts = NULL;
int usenewconflicts = 0;
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index fe421261..58b283c3 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -84,8 +84,8 @@ void _alpm_db_free(void *data)
pmdb_t *db = data;
FREELISTSERVERS(db->servers);
- free(db->path);
- free(db);
+ FREE(db->path);
+ FREE(db);
return;
}
@@ -109,7 +109,7 @@ pmlist_t *_alpm_db_search(pmdb_t *db, pmlist_t *needles)
targ = strdup(i->data);
_alpm_log(PM_LOG_DEBUG, "searching for target '%s'\n", targ);
- for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
+ for(j = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); j; j = j->next) {
pmpkg_t *pkg = j->data;
char *haystack;
int match = 0;
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 2d28fde0..cdbec038 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -127,6 +127,8 @@ pmlist_t *_alpm_sortbydeps(pmlist_t *targets, int mode)
/* run thru targets, moving up packages as necessary */
for(i = newtargs; i; i = i->next) {
pmpkg_t *p = (pmpkg_t*)i->data;
+ _alpm_log(PM_LOG_DEBUG, "sorting %s", p->name);
+ _alpm_db_read(p->data, INFRQ_DEPENDS, p);
for(j = p->depends; j; j = j->next) {
pmdepend_t dep;
pmpkg_t *q = NULL;
@@ -208,6 +210,7 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist
if((oldpkg = _alpm_db_get_pkgfromcache(db, tp->name)) == NULL) {
continue;
}
+ _alpm_db_read(db, INFRQ_DEPENDS, oldpkg);
for(j = oldpkg->requiredby; j; j = j->next) {
char *ver;
pmpkg_t *p;
@@ -220,6 +223,7 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist
/* this package is also in the upgrade list, so don't worry about it */
continue;
}
+ _alpm_db_read(db, INFRQ_DEPENDS, p);
for(k = p->depends; k && !found; k = k->next) {
/* find the dependency info in p->depends */
_alpm_splitdep(k->data, &depend);
@@ -276,12 +280,19 @@ pmlist_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, unsigned char op, pmlist
continue;
}
+ /* ensure package has depends data */
+ pmdb_t *pkgdb = tp->data;
+ _alpm_db_read(pkgdb, INFRQ_DEPENDS, tp);
+ if(!tp->depends) {
+ _alpm_log(PM_LOG_DEBUG, _("no dependencies for target '%s'"), tp->name);
+ }
+
for(j = tp->depends; j; j = j->next) {
/* split into name/version pairs */
_alpm_splitdep((char *)j->data, &depend);
found = 0;
/* check database for literal packages */
- for(k = _alpm_db_get_pkgcache(db); k && !found; k = k->next) {
+ for(k = _alpm_db_get_pkgcache(db, INFRQ_DESC|INFRQ_DEPENDS); k && !found; k = k->next) {
pmpkg_t *p = (pmpkg_t *)k->data;
if(!strcmp(p->name, depend.name)) {
if(depend.mod == PM_DEP_MOD_ANY) {
@@ -493,7 +504,13 @@ pmlist_t *_alpm_removedeps(pmdb_t *db, pmlist_t *targs)
}
for(i = targs; i; i = i->next) {
- for(j = ((pmpkg_t *)i->data)->depends; j; j = j->next) {
+ pmpkg_t *pkg = i->data;
+ if(pkg) {
+ _alpm_db_read(db, INFRQ_DEPENDS, pkg);
+ } else {
+ continue;
+ }
+ for(j = pkg->depends; j; j = j->next) {
pmdepend_t depend;
pmpkg_t *dep;
int needed = 0;
@@ -569,6 +586,7 @@ int _alpm_resolvedeps(pmdb_t *local, pmlist_t *dbs_sync, pmpkg_t *syncpkg, pmlis
return(-1);
}
+ _alpm_log(PM_LOG_DEBUG, _("started resolving dependencies"));
targ = _alpm_list_add(NULL, syncpkg);
deps = _alpm_checkdeps(trans, local, PM_TRANS_TYPE_ADD, targ);
FREELISTPTR(targ);
@@ -599,6 +617,7 @@ int _alpm_resolvedeps(pmdb_t *local, pmlist_t *dbs_sync, pmpkg_t *syncpkg, pmlis
/* check literals */
for(j = dbs_sync; !sync && j; j = j->next) {
sync = _alpm_db_get_pkgfromcache(j->data, miss->depend.name);
+ _alpm_db_read(j->data, INFRQ_DEPENDS, sync);
}
/* check provides */
for(j = dbs_sync; !sync && j; j = j->next) {
@@ -670,6 +689,8 @@ int _alpm_resolvedeps(pmdb_t *local, pmlist_t *dbs_sync, pmpkg_t *syncpkg, pmlis
_alpm_log(PM_LOG_DEBUG, _("dependency cycle detected: %s"), sync->name);
}
}
+
+ _alpm_log(PM_LOG_DEBUG, _("finished resolving dependencies"));
FREELIST(deps);
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index fbeca9b4..f1d7356c 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -101,6 +101,8 @@ char *alpm_strerror(int err)
return _("package name is not valid");
case PM_ERR_PKG_CORRUPTED:
return _("corrupted package");
+ case PM_ERR_PKG_REPO_NOT_FOUND:
+ return _("no such repository");
/* Groups */
case PM_ERR_GRP_NOT_FOUND:
return _("group not found");
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index 4df56484..a578c777 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -57,7 +57,7 @@ void _alpm_grp_free(void *data)
}
FREELIST(grp->packages);
- free(grp);
+ FREE(grp);
return;
}
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 6c1b98c5..dd9d50b6 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -31,7 +31,7 @@
#include <syslog.h>
#include <libintl.h>
#include <time.h>
-#include <ftplib.h>
+/////#include <ftplib.h>
/* pacman */
#include "util.h"
#include "log.h"
@@ -113,7 +113,7 @@ int _alpm_handle_free(pmhandle_t *handle)
FREELIST(handle->ignorepkg);
FREELIST(handle->holdpkg);
FREELIST(handle->needles);
- free(handle);
+ FREE(handle);
return(0);
}
@@ -224,9 +224,9 @@ int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long
pm_logcb = (alpm_cb_log)data;
break;
case PM_OPT_DLCB:
- pm_dlcb = (FtpCallback)data;
+ pm_dlcb = (download_progress_cb)data;
break;
- case PM_OPT_DLFNM:
+/* case PM_OPT_DLFNM:
pm_dlfnm = (char *)data;
break;
case PM_OPT_DLOFFSET:
@@ -253,6 +253,7 @@ int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long
case PM_OPT_DLETA_S:
pm_dleta_s = (unsigned char *)data;
break;
+*/
case PM_OPT_UPGRADEDELAY:
handle->upgradedelay = data;
break;
@@ -331,6 +332,7 @@ int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data)
case PM_OPT_DLCB: *data = (long)pm_dlcb; break;
case PM_OPT_UPGRADEDELAY: *data = (long)handle->upgradedelay; break;
case PM_OPT_LOGMASK: *data = pm_logmask; break;
+/*
case PM_OPT_DLFNM: *data = (long)pm_dlfnm; break;
case PM_OPT_DLOFFSET: *data = (long)pm_dloffset; break;
case PM_OPT_DLT0: *data = (long)pm_dlt0; break;
@@ -340,6 +342,7 @@ int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data)
case PM_OPT_DLETA_H: *data = (long)pm_dleta_h; break;
case PM_OPT_DLETA_M: *data = (long)pm_dleta_m; break;
case PM_OPT_DLETA_S: *data = (long)pm_dleta_s; break;
+*/
case PM_OPT_PROXYHOST: *data = (long)handle->proxyhost; break;
case PM_OPT_PROXYPORT: *data = handle->proxyport; break;
case PM_OPT_XFERCOMMAND: *data = (long)handle->xfercommand; break;
diff --git a/lib/libalpm/list.c b/lib/libalpm/list.c
index be41a462..0f48030b 100644
--- a/lib/libalpm/list.c
+++ b/lib/libalpm/list.c
@@ -26,6 +26,7 @@
#include <assert.h>
/* pacman */
#include "list.h"
+#include "util.h"
pmlist_t *_alpm_list_new()
{
@@ -48,10 +49,10 @@ void _alpm_list_free(pmlist_t *list, _alpm_fn_free fn)
while(it) {
ptr = it->next;
- if(fn) {
+ if(fn && it->data) {
fn(it->data);
}
- free(it);
+ FREE(it);
it = ptr;
}
}
@@ -180,7 +181,7 @@ pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, v
*data = i->data;
}
i->data = NULL;
- free(i);
+ FREE(i);
}
return(haystack);
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index aa035769..16e0dc32 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -156,7 +156,7 @@ void _alpm_pkg_free(void *data)
if(pkg->origin == PKG_FROM_FILE) {
FREE(pkg->data);
}
- free(pkg);
+ FREE(pkg);
return;
}
diff --git a/lib/libalpm/provide.c b/lib/libalpm/provide.c
index cd5db3e0..e2d58952 100644
--- a/lib/libalpm/provide.c
+++ b/lib/libalpm/provide.c
@@ -39,7 +39,7 @@ pmlist_t *_alpm_db_whatprovides(pmdb_t *db, char *package)
return(NULL);
}
- for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
+ for(lp = _alpm_db_get_pkgcache(db, INFRQ_DEPENDS); lp; lp = lp->next) {
pmpkg_t *info = lp->data;
if(_alpm_list_is_strin(package, info->provides)) {
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 39937eed..5659e1e9 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -192,7 +192,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
/* iterate through the list backwards, unlinking files */
for(lp = _alpm_list_last(info->files); lp; lp = lp->prev) {
int nb = 0;
- double percent;
+ double percent = 0.0;
char *file = lp->data;
char *md5 =_alpm_needbackup(file, info->backup);
char *sha1 =_alpm_needbackup(file, info->backup);
@@ -294,6 +294,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
for(lp = info->depends; lp; lp = lp->next) {
pmpkg_t *depinfo = NULL;
pmdepend_t depend;
+ void *vdata;
char *data;
if(_alpm_splitdep((char*)lp->data, &depend)) {
continue;
@@ -324,7 +325,8 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
}
}
/* splice out this entry from requiredby */
- depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, info->name, str_cmp, (void **)&data);
+ depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, info->name, str_cmp, &vdata);
+ data = vdata;
FREE(data);
_alpm_log(PM_LOG_DEBUG, _("updating 'requiredby' field for package '%s'"), depinfo->name);
if(_alpm_db_write(db, depinfo, INFRQ_DEPENDS)) {
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index d86002d2..a41b9282 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -28,7 +28,6 @@
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
-#include <ftplib.h>
/* pacman */
#include "server.h"
@@ -37,20 +36,14 @@
#include "alpm.h"
#include "util.h"
#include "handle.h"
+#include "log.h"
-FtpCallback pm_dlcb = NULL;
-/* progress bar */
-char *pm_dlfnm=NULL;
-int *pm_dloffset=NULL;
-struct timeval *pm_dlt0=NULL, *pm_dlt=NULL;
-float *pm_dlrate=NULL;
-int *pm_dlxfered1=NULL;
-unsigned char *pm_dleta_h=NULL, *pm_dleta_m=NULL, *pm_dleta_s=NULL;
+download_progress_cb pm_dlcb = NULL;
pmserver_t *_alpm_server_new(char *url)
{
+ struct url *u;
pmserver_t *server;
- char *ptr;
server = (pmserver_t *)malloc(sizeof(pmserver_t));
if(server == NULL) {
@@ -59,56 +52,28 @@ pmserver_t *_alpm_server_new(char *url)
}
memset(server, 0, sizeof(pmserver_t));
-
- /* parse our special url */
- ptr = strstr(url, "://");
- if(ptr == NULL) {
- RET_ERR(PM_ERR_SERVER_BAD_LOCATION, NULL);
+ u = fetchParseURL(url);
+ if(!u) {
+ _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid, ignoring"), url);
+ return(NULL);
}
- *ptr = '\0';
- ptr++; ptr++; ptr++;
- if(ptr == NULL || *ptr == '\0') {
- RET_ERR(PM_ERR_SERVER_BAD_LOCATION, NULL);
+ if(strlen(u->scheme) == 0) {
+ _alpm_log(PM_LOG_WARNING, _("url scheme not specified, assuming http"));
+ strcpy(u->scheme, "http");
}
- server->protocol = strdup(url);
- if(!strcmp(server->protocol, "ftp") || !strcmp(server->protocol, "http")) {
- char *slash;
- /* split the url into domain and path */
- slash = strchr(ptr, '/');
- if(slash == NULL) {
- /* no path included, default to / */
- server->path = strdup("/");
- } else {
- /* add a trailing slash if we need to */
- if(slash[strlen(slash)-1] == '/') {
- server->path = strdup(slash);
- } else {
- if((server->path = (char *)malloc(strlen(slash)+2)) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(strlen(slash+2)));
- RET_ERR(PM_ERR_MEMORY, NULL);
- }
- sprintf(server->path, "%s/", slash);
- }
- *slash = '\0';
- }
- server->server = strdup(ptr);
- } else if(!strcmp(server->protocol, "file")){
- /* add a trailing slash if we need to */
- if(ptr[strlen(ptr)-1] == '/') {
- server->path = strdup(ptr);
- } else {
- server->path = (char *)malloc(strlen(ptr)+2);
- if(server->path == NULL) {
- _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(strlen(ptr+2)));
- RET_ERR(PM_ERR_MEMORY, NULL);
- }
- sprintf(server->path, "%s/", ptr);
- }
- } else {
- RET_ERR(PM_ERR_SERVER_PROTOCOL_UNSUPPORTED, NULL);
+
+ if(strcmp(u->scheme,"ftp") == 0 && strlen(u->user) == 0) {
+ strcpy(u->user, "anonymous");
+ strcpy(u->pwd, "libalpm@guest");
}
- return(server);
+ /* This isn't needed... we can actually kill the whole pmserver_t interface
+ * and replace it with libfetch's 'struct url'
+ */
+ server->s_url = u;
+ server->path = strdup(u->doc);
+
+ return server;
}
void _alpm_server_free(void *data)
@@ -120,10 +85,9 @@ void _alpm_server_free(void *data)
}
/* free memory */
- FREE(server->protocol);
- FREE(server->server);
FREE(server->path);
- free(server);
+ fetchFreeURL(server->s_url);
+ FREE(server);
}
/*
@@ -134,7 +98,7 @@ void _alpm_server_free(void *data)
*/
int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *files)
{
- return(!!_alpm_downloadfiles_forreal(servers, localpath, files, NULL, NULL));
+ return(_alpm_downloadfiles_forreal(servers, localpath, files, NULL, NULL));
}
/*
@@ -147,14 +111,13 @@ int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *file
* of the remote file (from MDTM FTP cmd or Last-Modified HTTP header).
*
* RETURN: 0 for successful download
- * -1 if the mtimes are identical
- * 1 on error
+ * 1 if the mtimes are identical
+ * -1 on error
*/
int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
pmlist_t *files, const char *mtime1, char *mtime2)
{
- int fsz;
- netbuf *control = NULL;
+ int dltotal_bytes = 0;
pmlist_t *lp;
int done = 0;
pmlist_t *complete = NULL;
@@ -164,74 +127,122 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
return(0);
}
- _alpm_log(PM_LOG_DEBUG, _("server check, %d\n"),servers);
for(i = servers; i && !done; i = i->next) {
- _alpm_log(PM_LOG_DEBUG, _("server check, done? %d\n"),done);
pmserver_t *server = (pmserver_t*)i->data;
- if(!handle->xfercommand && strcmp(server->protocol, "file")) {
- if(!strcmp(server->protocol, "ftp") && !handle->proxyhost) {
- FtpInit();
- _alpm_log(PM_LOG_DEBUG, _("connecting to %s:21\n"), server->server);
- if(!FtpConnect(server->server, &control)) {
- _alpm_log(PM_LOG_WARNING, _("cannot connect to %s\n"), server->server);
- continue;
+ /* get each file in the list */
+ for(lp = files; lp; lp = lp->next) {
+ char realfile[PATH_MAX];
+ char output[PATH_MAX];
+ char *fn = (char *)lp->data;
+
+ snprintf(realfile, PATH_MAX, "%s/%s", localpath, fn);
+ snprintf(output, PATH_MAX, "%s/%s.part", localpath, fn);
+
+ if(_alpm_list_is_strin(fn, complete)) {
+ continue;
+ }
+
+ if(!handle->xfercommand) {
+ FILE *dlf, *localf = NULL;
+ struct url_stat ust;
+ struct stat st;
+ int chk_resume = 0;
+
+ if(stat(output, &st) == 0 && st.st_size > 0) {
+ _alpm_log(PM_LOG_DEBUG, _("existing file found, using it\n"));
+ server->s_url->offset = (off_t)st.st_size;
+ dltotal_bytes = st.st_size;
+ localf = fopen(output, "a");
+ chk_resume = 1;
+ } else {
+ server->s_url->offset = (off_t)0;
+ dltotal_bytes = 0;
}
- if(!FtpLogin("anonymous", "libalpm@guest", control)) {
- _alpm_log(PM_LOG_WARNING, _("anonymous login failed\n"));
- FtpQuit(control);
- continue;
- }
- if(!FtpChdir(server->path, control)) {
- _alpm_log(PM_LOG_WARNING, _("could not cwd to %s: %s\n"), server->path, FtpLastResponse(control));
- FtpQuit(control);
- continue;
+
+ FREE(server->s_url->doc);
+ int len = strlen(server->path) + strlen(fn) + 2;
+ server->s_url->doc = (char *)malloc(len);
+ snprintf(server->s_url->doc, len, "%s/%s", server->path, fn);
+
+ /* libfetch does not reset the error code, reset it in the case of previous errors */
+ fetchLastErrCode = 0;
+
+ /* 10s timeout - TODO make a config option */
+ fetchTimeout = 10000;
+
+ /* Make libfetch super verbose... worthwhile for testing */
+ if(pm_logmask & PM_LOG_DEBUG) {
+ fetchDebug = 1;
+ dlf = fetchXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp"));
+ } else {
+ dlf = fetchXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p"));
}
- if(!handle->nopassiveftp) {
- if(!FtpOptions(FTPLIB_CONNMODE, FTPLIB_PASSIVE, control)) {
- _alpm_log(PM_LOG_WARNING, _("failed to set passive mode\n"));
+ if(fetchLastErrCode != 0 || dlf == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from '%s://%s%s', %d : %s\n"), fn,
+ server->s_url->scheme, server->s_url->host, server->s_url->doc, fetchLastErrCode,
+ fetchLastErrString);
+ if(localf != NULL) {
+ fclose(localf);
}
+ return(-1);
} else {
- _alpm_log(PM_LOG_DEBUG, _("FTP passive mode not set\n"));
+ _alpm_log(PM_LOG_DEBUG, _("server connection to %s complete"), server->s_url->host);
}
- } else if(handle->proxyhost) {
- char *host;
- unsigned port;
- host = (handle->proxyhost) ? handle->proxyhost : server->server;
- port = (handle->proxyport) ? handle->proxyport : 80;
- if(strchr(host, ':')) {
- _alpm_log(PM_LOG_DEBUG, _("connecting to %s\n"), host);
- } else {
- _alpm_log(PM_LOG_DEBUG, _("connecting to %s:%u\n"), host, port);
+
+ if(ust.mtime && mtime1) {
+ char strtime[15];
+ _alpm_time2string(ust.mtime, strtime);
+ if(strcmp(mtime1, strtime) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn);
+ complete = _alpm_list_add(complete, fn);
+ if(localf != NULL) {
+ fclose(localf);
+ }
+ if(dlf != NULL) {
+ fclose(dlf);
+ }
+ return(1);
+ }
}
- if(!HttpConnect(host, port, &control)) {
- _alpm_log(PM_LOG_WARNING, _("cannot connect to %s\n"), host);
- continue;
+
+ if(ust.mtime && mtime2) {
+ _alpm_time2string(ust.mtime, mtime2);
}
- }
- /* set up our progress bar's callback (and idle timeout) */
- if(strcmp(server->protocol, "file") && control) {
- if(pm_dlcb) {
- FtpOptions(FTPLIB_CALLBACK, (long)pm_dlcb, control);
- } else {
- _alpm_log(PM_LOG_DEBUG, _("downloadfiles: progress bar's callback is not set\n"));
+ if(chk_resume && server->s_url->offset == 0) {
+ _alpm_log(PM_LOG_WARNING, _("cannot resume download, starting over"));
+ if(localf != NULL) {
+ fclose(localf);
+ localf = NULL;
+ }
}
- FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
- FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
- FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
- }
- }
- /* get each file in the list */
- for(lp = files; lp; lp = lp->next) {
- char *fn = (char *)lp->data;
+ if(localf == NULL) {
+ _alpm_rmrf(output);
+ server->s_url->offset = (off_t)0;
+ dltotal_bytes = 0;
+ localf = fopen(output, "w");
+ }
- if(_alpm_list_is_strin(fn, complete)) {
- continue;
- }
+ /* Progress 0 - initialize */
+ if(pm_dlcb) pm_dlcb(fn, 0, ust.size);
- if(handle->xfercommand && strcmp(server->protocol, "file")) {
+ int nread = 0;
+ char buffer[PM_DLBUF_LEN];
+ while((nread = fread(buffer, 1, PM_DLBUF_LEN, dlf)) > 0) {
+ int nwritten = 0;
+ while((nwritten += fwrite(buffer, 1, (nread - nwritten), localf)) < nread) ;
+ dltotal_bytes += nread;
+
+ if(pm_dlcb) pm_dlcb(fn, dltotal_bytes, ust.size);
+ }
+
+ fclose(localf);
+ fclose(dlf);
+ rename(output, realfile);
+ complete = _alpm_list_add(complete, fn);
+ } else {
int ret;
int usepart = 0;
char *ptr1, *ptr2;
@@ -240,8 +251,8 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
char url[PATH_MAX];
char cwd[PATH_MAX];
/* build the full download url */
- snprintf(url, PATH_MAX, "%s://%s%s%s", server->protocol, server->server,
- server->path, fn);
+ snprintf(url, PATH_MAX, "%s://%s%s/%s", server->s_url->scheme, server->s_url->host,
+ server->s_url->doc, fn);
/* replace all occurrences of %o with fn.part */
strncpy(origCmd, handle->xfercommand, sizeof(origCmd));
ptr1 = origCmd;
@@ -291,213 +302,6 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
}
}
chdir(cwd);
- } else {
- char output[PATH_MAX];
- unsigned int j;
- int filedone = 0;
- char *ptr;
- struct stat st;
- snprintf(output, PATH_MAX, "%s/%s.part", localpath, fn);
- if(pm_dlfnm) {
- strncpy(pm_dlfnm, fn, PM_DLFNM_LEN);
- }
- /* drop filename extension */
- ptr = strstr(fn, PM_EXT_DB);
- if(pm_dlfnm && ptr && (ptr-fn) < PM_DLFNM_LEN) {
- pm_dlfnm[ptr-fn] = '\0';
- }
- ptr = strstr(fn, PM_EXT_PKG);
- if(ptr && (ptr-fn) < PM_DLFNM_LEN) {
- pm_dlfnm[ptr-fn] = '\0';
- }
- if(pm_dlfnm) {
- for(j = strlen(pm_dlfnm); j < PM_DLFNM_LEN; j++) {
- (pm_dlfnm)[j] = ' ';
- }
- pm_dlfnm[PM_DLFNM_LEN] = '\0';
- }
- if(pm_dloffset) {
- *pm_dloffset = 0;
- }
-
- /* ETA setup */
- if(pm_dlt0 && pm_dlt && pm_dlrate && pm_dlxfered1 && pm_dleta_h && pm_dleta_m && pm_dleta_s) {
- gettimeofday(pm_dlt0, NULL);
- *pm_dlt = *pm_dlt0;
- *pm_dlrate = 0;
- *pm_dlxfered1 = 0;
- *pm_dleta_h = 0;
- *pm_dleta_m = 0;
- *pm_dleta_s = 0;
- }
-
- if(!strcmp(server->protocol, "ftp") && !handle->proxyhost) {
- if(!FtpSize(fn, &fsz, FTPLIB_IMAGE, control)) {
- _alpm_log(PM_LOG_WARNING, _("failed to get filesize for %s\n"), fn);
- }
- /* check mtimes */
- if(mtime1) {
- char fmtime[64];
- if(!FtpModDate(fn, fmtime, sizeof(fmtime)-1, control)) {
- _alpm_log(PM_LOG_WARNING, _("failed to get mtime for %s\n"), fn);
- } else {
- _alpm_strtrim(fmtime);
- if(mtime1 && !strcmp(mtime1, fmtime)) {
- /* mtimes are identical, skip this file */
- _alpm_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn);
- filedone = -1;
- complete = _alpm_list_add(complete, fn);
- } else {
- if(mtime2) {
- strncpy(mtime2, fmtime, 15); /* YYYYMMDDHHMMSS (=14b) */
- mtime2[14] = '\0';
- }
- }
- }
- }
- if(!filedone) {
- if(!stat(output, &st)) {
- *pm_dloffset = (int)st.st_size;
- if(!FtpRestart(*pm_dloffset, control)) {
- _alpm_log(PM_LOG_WARNING, _("failed to resume download -- restarting\n"));
- /* can't resume: */
- /* unlink the file in order to restart download from scratch */
- unlink(output);
- }
- }
- if(!FtpGet(output, fn, FTPLIB_IMAGE, control)) {
- _alpm_log(PM_LOG_WARNING, _("\nfailed downloading %s from %s: %s\n"),
- fn, server->server, FtpLastResponse(control));
- /* we leave the partially downloaded file in place so it can be resumed later */
- } else {
- _alpm_log(PM_LOG_DEBUG, _("downloaded %s from %s\n"),
- fn, server->server);
- filedone = 1;
- }
- }
- } else if(!strcmp(server->protocol, "http") || (handle->proxyhost && strcmp(server->protocol, "file"))) {
- char src[PATH_MAX];
- char *host;
- unsigned port;
- struct tm fmtime1;
- struct tm fmtime2;
- memset(&fmtime1, 0, sizeof(struct tm));
- memset(&fmtime2, 0, sizeof(struct tm));
- if(!strcmp(server->protocol, "http") && !handle->proxyhost) {
- /* HTTP servers hang up after each request (but not proxies), so
- * we have to re-connect for each file.
- */
- host = (handle->proxyhost) ? handle->proxyhost : server->server;
- port = (handle->proxyhost) ? handle->proxyport : 80;
- if(strchr(host, ':')) {
- _alpm_log(PM_LOG_DEBUG, _("connecting to %s\n"), host);
- } else {
- _alpm_log(PM_LOG_DEBUG, _("connecting to %s:%u\n"), host, port);
- }
- if(!HttpConnect(host, port, &control)) {
- _alpm_log(PM_LOG_WARNING, _("cannot connect to %s\n"), host);
- continue;
- }
- /* set up our progress bar's callback (and idle timeout) */
- if(strcmp(server->protocol, "file") && control) {
- if(pm_dlcb) {
- FtpOptions(FTPLIB_CALLBACK, (long)pm_dlcb, control);
- } else {
- _alpm_log(PM_LOG_DEBUG, _("downloadfiles: progress bar's callback is not set\n"));
- }
- FtpOptions(FTPLIB_IDLETIME, (long)1000, control);
- FtpOptions(FTPLIB_CALLBACKARG, (long)&fsz, control);
- FtpOptions(FTPLIB_CALLBACKBYTES, (10*1024), control);
- }
- }
-
- if(!stat(output, &st)) {
- *pm_dloffset = (int)st.st_size;
- }
- if(!handle->proxyhost) {
- snprintf(src, PATH_MAX, "%s%s", server->path, fn);
- } else {
- snprintf(src, PATH_MAX, "%s://%s%s%s", server->protocol, server->server, server->path, fn);
- }
- if(mtime1 && strlen(mtime1)) {
- struct tm tmref;
- time_t t, tref;
- int diff;
- /* date conversion from YYYYMMDDHHMMSS to "rfc1123-date" */
- sscanf(mtime1, "%4d%2d%2d%2d%2d%2d",
- &fmtime1.tm_year, &fmtime1.tm_mon, &fmtime1.tm_mday,
- &fmtime1.tm_hour, &fmtime1.tm_min, &fmtime1.tm_sec);
- fmtime1.tm_year -= 1900;
- fmtime1.tm_mon--;
- /* compute the week day because some web servers (like lighttpd) need them. */
- /* we set tmref to "Thu, 01 Jan 1970 00:00:00" */
- memset(&tmref, 0, sizeof(struct tm));
- tmref.tm_mday = 1;
- tref = mktime(&tmref);
- /* then we compute the difference with mtime1 */
- t = mktime(&fmtime1);
- diff = ((t-tref)/3600/24)%7;
- fmtime1.tm_wday = diff+(diff >= 3 ? -3 : 4);
-
- }
- fmtime2.tm_year = 0;
- if(!HttpGet(server->server, output, src, &fsz, control, *pm_dloffset,
- (mtime1) ? &fmtime1 : NULL, (mtime2) ? &fmtime2 : NULL)) {
- if(strstr(FtpLastResponse(control), "304")) {
- _alpm_log(PM_LOG_DEBUG, _("mtimes are identical, skipping %s\n"), fn);
- filedone = -1;
- complete = _alpm_list_add(complete, fn);
- } else {
- _alpm_log(PM_LOG_WARNING, _("\nfailed downloading %s from %s: %s\n"),
- src, server->server, FtpLastResponse(control));
- /* we leave the partially downloaded file in place so it can be resumed later */
- }
- } else {
- if(mtime2) {
- if(fmtime2.tm_year) {
- /* date conversion from "rfc1123-date" to YYYYMMDDHHMMSS */
- sprintf(mtime2, "%4d%02d%02d%02d%02d%02d",
- fmtime2.tm_year+1900, fmtime2.tm_mon+1, fmtime2.tm_mday,
- fmtime2.tm_hour, fmtime2.tm_min, fmtime2.tm_sec);
- } else {
- _alpm_log(PM_LOG_WARNING, _("failed to get mtime for %s\n"), fn);
- }
- }
- filedone = 1;
- }
- } else if(!strcmp(server->protocol, "file")) {
- char src[PATH_MAX];
- snprintf(src, PATH_MAX, "%s%s", server->path, fn);
- _alpm_log(PM_LOG_DEBUG, _("copying %s to %s/%s\n"), src, localpath, fn);
- /* local repository, just copy the file */
- if(_alpm_copyfile(src, output)) {
- _alpm_log(PM_LOG_WARNING, _("failed copying %s\n"), src);
- } else {
- filedone = 1;
- }
- }
-
- if(filedone > 0) {
- char completefile[PATH_MAX];
- if(!strcmp(server->protocol, "file")) {
- EVENT(handle->trans, PM_TRANS_EVT_RETRIEVE_LOCAL, pm_dlfnm, server->path);
- } else if(pm_dlcb) {
- pm_dlcb(control, fsz-*pm_dloffset, &fsz);
- }
- complete = _alpm_list_add(complete, fn);
- /* rename "output.part" file to "output" file */
- snprintf(completefile, PATH_MAX, "%s/%s", localpath, fn);
- rename(output, completefile);
- } else if(filedone < 0) {
- return(-1);
- }
- }
- }
- if(!handle->xfercommand) {
- if(!strcmp(server->protocol, "ftp") && !handle->proxyhost) {
- FtpQuit(control);
- } else if(!strcmp(server->protocol, "http") || (handle->proxyhost && strcmp(server->protocol, "file"))) {
- HttpQuit(control);
}
}
@@ -506,42 +310,32 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
}
}
- _alpm_log(PM_LOG_DEBUG, _("end _alpm_downloadfiles_forreal - return %d"),!done);
return(!done);
}
char *_alpm_fetch_pkgurl(char *target)
{
- char spath[PATH_MAX];
- char url[PATH_MAX];
- char *host, *path, *fn;
- struct stat buf;
-
- strncpy(url, target, PATH_MAX);
- host = strstr(url, "://");
- *host = '\0';
- host += 3;
- path = strchr(host, '/');
- *path = '\0';
- path++;
- fn = strrchr(path, '/');
- if(fn) {
- *fn = '\0';
- if(path[0] == '/') {
- snprintf(spath, PATH_MAX, "%s/", path);
- } else {
- snprintf(spath, PATH_MAX, "/%s/", path);
- }
- fn++;
- } else {
- fn = path;
- strcpy(spath, "/");
+ struct stat st;
+ struct url *s_url;
+
+ s_url = fetchParseURL(target);
+ if(!s_url) {
+ _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid, ignoring"), target);
+ return(NULL);
+ }
+ if(strlen(s_url->scheme) == 0) {
+ _alpm_log(PM_LOG_WARNING, _("url scheme not specified, assuming http"));
+ strcpy(s_url->scheme, "http");
}
- /* do not download the file if it exists in the current dir
- */
- if(stat(fn, &buf) == 0) {
- _alpm_log(PM_LOG_DEBUG, _(" %s is already in the current directory\n"), fn);
+ if(strcmp(s_url->scheme,"ftp") == 0 && strlen(s_url->user) == 0) {
+ strcpy(s_url->user, "anonymous");
+ strcpy(s_url->pwd, "libalpm@guest");
+ }
+
+ /* do not download the file if it exists in the current dir */
+ if(stat(s_url->doc, &st) == 0) {
+ _alpm_log(PM_LOG_DEBUG, _(" %s is already in the current directory\n"), s_url->doc);
} else {
pmserver_t *server;
pmlist_t *servers = NULL;
@@ -551,27 +345,21 @@ char *_alpm_fetch_pkgurl(char *target)
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmserver_t));
return(NULL);
}
- server->protocol = url;
- server->server = host;
- server->path = spath;
+ server->s_url = s_url;
+ server->path = strdup(s_url->doc);
servers = _alpm_list_add(servers, server);
- files = _alpm_list_add(NULL, fn);
+ files = _alpm_list_add(NULL, s_url->doc);
if(_alpm_downloadfiles(servers, ".", files)) {
_alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), target);
return(NULL);
}
FREELISTPTR(files);
-
FREELIST(servers);
}
/* return the target with the raw filename, no URL */
- #if defined(__OpenBSD__) || defined(__APPLE__)
- return(strdup(fn));
- #else
- return(strndup(fn, PATH_MAX));
- #endif
+ return(strdup(s_url->doc));
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/server.h b/lib/libalpm/server.h
index 218c172a..258df223 100644
--- a/lib/libalpm/server.h
+++ b/lib/libalpm/server.h
@@ -23,7 +23,8 @@
#include "list.h"
#include <time.h>
-#include <ftplib.h>
+
+#include <fetch.h>
#define FREESERVER(p) \
do { \
@@ -37,11 +38,14 @@ do { \
/* Servers */
typedef struct __pmserver_t {
- char *protocol;
- char *server;
char *path;
+ struct url *s_url;
} pmserver_t;
+#define PM_DLBUF_LEN (1024 * 10)
+
+typedef void (*download_progress_cb)(const char *filename, int xfered, int total);
+
pmserver_t *_alpm_server_new(char *url);
void _alpm_server_free(void *data);
int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *files);
@@ -50,15 +54,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
char *_alpm_fetch_pkgurl(char *target);
-extern FtpCallback pm_dlcb;
-
-/* progress bar */
-extern char *pm_dlfnm;
-extern int *pm_dloffset;
-extern struct timeval *pm_dlt0, *pm_dlt;
-extern float *pm_dlrate;
-extern int *pm_dlxfered1;
-extern unsigned char *pm_dleta_h, *pm_dleta_m, *pm_dleta_s;
+extern download_progress_cb pm_dlcb;
#endif /* _ALPM_SERVER_H */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 523d2372..6c4939da 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -84,7 +84,7 @@ void _alpm_sync_free(void *data)
} else {
FREEPKG(sync->data);
}
- free(sync);
+ FREE(sync);
}
/* Test for existence of a package in a pmlist_t* of pmsyncpkg_t*
@@ -125,13 +125,13 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync
/* check for "recommended" package replacements */
_alpm_log(PM_LOG_FLOW1, _("checking for package replacements"));
for(i = dbs_sync; i; i = i->next) {
- for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) {
+ for(j = _alpm_db_get_pkgcache(i->data, INFRQ_DESC); j; j = j->next) {
pmpkg_t *spkg = j->data;
for(k = spkg->replaces; k; k = k->next) {
pmlist_t *m;
- for(m = _alpm_db_get_pkgcache(db_local); m; m = m->next) {
+ for(m = _alpm_db_get_pkgcache(db_local, INFRQ_NONE); m; m = m->next) {
pmpkg_t *lpkg = m->data;
- if(!strcmp(k->data, lpkg->name)) {
+ if(strcmp(k->data, lpkg->name) == 0) {
_alpm_log(PM_LOG_DEBUG, _("checking replacement '%s' for package '%s'"), k->data, spkg->name);
if(_alpm_list_is_strin(lpkg->name, handle->ignorepkg)) {
_alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"),
@@ -181,7 +181,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync
/* match installed packages with the sync dbs and compare versions */
_alpm_log(PM_LOG_FLOW1, _("checking for package upgrades"));
- for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
+ for(i = _alpm_db_get_pkgcache(db_local, INFRQ_NONE); i; i = i->next) {
int cmp;
int replace=0;
pmpkg_t *local = i->data;
@@ -262,7 +262,7 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync,
pmpkg_t *local;
pmpkg_t *spkg = NULL;
pmsyncpkg_t *sync;
- int cmp;
+ int cmp, repo_found = 0;
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
@@ -273,9 +273,11 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync,
if(targ) {
*targ = '\0';
targ++;
+ _alpm_log(PM_LOG_DEBUG, _("searching for target in repo '%s'"), targline);
for(j = dbs_sync; j && !spkg; j = j->next) {
pmdb_t *dbs = j->data;
if(strcmp(dbs->treename, targline) == 0) {
+ repo_found = 1;
spkg = _alpm_db_get_pkgfromcache(dbs, targ);
if(spkg == NULL) {
/* Search provides */
@@ -291,6 +293,10 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync,
}
}
}
+ if(!repo_found) {
+ _alpm_log(PM_LOG_ERROR, _("repository '%s' not found"), targline);
+ RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
+ }
} else {
targ = targline;
for(j = dbs_sync; j && !spkg; j = j->next) {
@@ -396,7 +402,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync, p
/* Resolve targets dependencies */
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
- _alpm_log(PM_LOG_FLOW1, _("resolving targets dependencies"));
+ _alpm_log(PM_LOG_FLOW1, _("resolving target's dependencies"));
for(i = trans->packages; i; i = i->next) {
pmpkg_t *spkg = ((pmsyncpkg_t *)i->data)->pkg;
if(_alpm_resolvedeps(db_local, dbs_sync, spkg, list, trail, trans, data) == -1) {
@@ -421,8 +427,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync, p
} else {
/* remove the original targets from the list if requested */
if((trans->flags & PM_TRANS_FLAG_DEPENDSONLY)) {
+ void *vp;
pmpkg_t *p;
- trans->packages = _alpm_list_remove(trans->packages, spkg, pkg_cmp, (void**)&p);
+ trans->packages = _alpm_list_remove(trans->packages, spkg, pkg_cmp, &vp);
+ p = vp;
FREEPKG(p);
}
}
@@ -550,10 +558,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync, p
}
if(rmpkg) {
pmsyncpkg_t *rsync = find_pkginsync(rmpkg, trans->packages);
- pmsyncpkg_t *spkg = NULL;
+ void *vpkg;
_alpm_log(PM_LOG_FLOW2, _("removing '%s' from target list"), rmpkg);
- trans->packages = _alpm_list_remove(trans->packages, rsync, ptr_cmp, (void **)&spkg);
- FREESYNC(spkg);
+ trans->packages = _alpm_list_remove(trans->packages, rsync, ptr_cmp, &vpkg);
+ FREESYNC(vpkg);
continue;
}
}
@@ -587,10 +595,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync, p
sync->data = _alpm_list_add(sync->data, q);
if(rsync) {
/* remove it from the target list */
- pmsyncpkg_t *spkg = NULL;
+ void *vpkg;
_alpm_log(PM_LOG_FLOW2, _("removing '%s' from target list"), miss->depend.name);
- trans->packages = _alpm_list_remove(trans->packages, rsync, ptr_cmp, (void **)&spkg);
- FREESYNC(spkg);
+ trans->packages = _alpm_list_remove(trans->packages, rsync, ptr_cmp, &vpkg);
+ FREESYNC(vpkg);
}
} else {
/* abort */
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 4946bfe0..55d3cf7c 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -82,7 +82,7 @@ void _alpm_trans_free(void *data)
FREELIST(trans->skiplist);
- free(trans);
+ FREE(trans);
}
int _alpm_trans_init(pmtrans_t *trans, unsigned char type, unsigned int flags, alpm_trans_cb_event event, alpm_trans_cb_conv conv, alpm_trans_cb_progress progress)
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 98f16406..2d34ac58 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -138,14 +138,14 @@ int _alpm_makepath(char *path)
strcat(full, ptr);
if(stat(full, &buf)) {
if(mkdir(full, 0755)) {
- free(orig);
+ FREE(orig);
umask(oldmask);
return(1);
}
}
}
}
- free(orig);
+ FREE(orig);
umask(oldmask);
return(0);
}
@@ -302,37 +302,36 @@ int _alpm_rmrf(char *path)
struct dirent *dp;
DIR *dirp;
char name[PATH_MAX];
+ struct stat st;
- if(!unlink(path)) {
- return(0);
- } else {
- if(errno == ENOENT) {
- return(0);
- } else if(errno == EPERM) {
- /* fallthrough */
- } else if(errno == EISDIR) {
- /* fallthrough */
- } else if(errno == ENOTDIR) {
- return(1);
- } else {
- /* not a directory */
- return(1);
- }
-
- if((dirp = opendir(path)) == (DIR *)-1) {
- return(1);
- }
- for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
- if(dp->d_ino) {
- sprintf(name, "%s/%s", path, dp->d_name);
- if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
- errflag += _alpm_rmrf(name);
+ if(stat(path, &st) == 0) {
+ if(S_ISREG(st.st_mode)) {
+ if(!unlink(path)) {
+ return(0);
+ } else {
+ if(errno == ENOENT) {
+ return(0);
+ } else {
+ /* not a directory */
+ return(1);
}
}
- }
- closedir(dirp);
- if(rmdir(path)) {
- errflag++;
+ } else if(S_ISDIR(st.st_mode)) {
+ if((dirp = opendir(path)) == (DIR *)-1) {
+ return(1);
+ }
+ for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
+ if(dp->d_ino) {
+ sprintf(name, "%s/%s", path, dp->d_name);
+ if(strcmp(dp->d_name, "..") && strcmp(dp->d_name, ".")) {
+ errflag += _alpm_rmrf(name);
+ }
+ }
+ }
+ closedir(dirp);
+ if(rmdir(path)) {
+ errflag++;
+ }
}
return(errflag);
}
@@ -605,6 +604,7 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data)
return(0);
}
}
+#endif
/* match a string against a regular expression */
int _alpm_reg_match(char *string, char *pattern)
@@ -620,6 +620,18 @@ int _alpm_reg_match(char *string, char *pattern)
return(!(result));
}
-#endif
+/* convert a time_t to a string - buffer MUST be large enough for
+ * YYYYMMDDHHMMSS - 15 chars */
+void _alpm_time2string(time_t t, char *buffer)
+{
+ if(buffer) {
+ struct tm *lt;
+ lt = localtime(&t);
+ sprintf(buffer, "%4d%02d%02d%02d%02d%02d",
+ lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec);
+ buffer[14] = '\0';
+ }
+}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index c96c13bf..37b944cb 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -71,6 +71,7 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data);
#endif
#endif
int _alpm_reg_match(char *string, char *pattern);
+void _alpm_time2string(time_t t, char *buffer);
#ifdef __sun__
char* strsep(char** str, const char* delims);
char* mkdtemp(char *template);