Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.h6
-rw-r--r--lib/libalpm/dload.c53
-rw-r--r--lib/libalpm/error.c2
-rw-r--r--lib/libalpm/handle.c12
-rw-r--r--lib/libalpm/handle.h2
-rw-r--r--lib/libalpm/trans.c33
6 files changed, 62 insertions, 46 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ce8c6919..1a83f725 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -151,8 +151,9 @@ void alpm_option_add_ignoregrp(const char *grp);
void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
int alpm_option_remove_ignoregrp(const char *grp);
-unsigned short alpm_option_get_nopassiveftp();
-void alpm_option_set_nopassiveftp(unsigned short nopasv);
+const char *alpm_option_get_arch();
+void alpm_option_set_arch(const char *arch);
+
void alpm_option_set_usedelta(unsigned short usedelta);
pmdb_t *alpm_option_get_localdb();
@@ -509,6 +510,7 @@ enum _pmerrno_t {
PM_ERR_PKG_OPEN,
PM_ERR_PKG_CANT_REMOVE,
PM_ERR_PKG_INVALID_NAME,
+ PM_ERR_PKG_INVALID_ARCH,
PM_ERR_PKG_REPO_NOT_FOUND,
/* Deltas */
PM_ERR_DLT_INVALID,
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 4695731a..f8fb09fe 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -76,30 +76,6 @@ static char *get_tempfile(const char *path, const char *filename) {
return(tempfile);
}
-/* Build a 'struct url' from an url. */
-static struct url *url_for_string(const char *url)
-{
- struct url *ret = NULL;
- ret = fetchParseURL(url);
- if(!ret) {
- _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
- RET_ERR(PM_ERR_SERVER_BAD_URL, NULL);
- }
-
- /* if no URL scheme specified, assume HTTP */
- if(strlen(ret->scheme) == 0) {
- _alpm_log(PM_LOG_WARNING, _("url scheme not specified, assuming HTTP\n"));
- strcpy(ret->scheme, SCHEME_HTTP);
- }
- /* add a user & password for anonymous FTP */
- if(strcmp(ret->scheme,SCHEME_FTP) == 0 && strlen(ret->user) == 0) {
- strcpy(ret->user, "anonymous");
- strcpy(ret->pwd, "libalpm@guest");
- }
-
- return(ret);
-}
-
static int download_internal(const char *url, const char *localpath,
time_t mtimeold, time_t *mtimenew) {
fetchIO *dlf = NULL;
@@ -110,17 +86,20 @@ static int download_internal(const char *url, const char *localpath,
size_t dl_thisfile = 0, nread = 0;
char *tempfile, *destfile, *filename;
struct sigaction new_action, old_action;
- struct url *fileurl = url_for_string(url);
+ struct url *fileurl;
char buffer[PM_DLBUF_LEN];
- if(!fileurl) {
- return(-1);
- }
-
filename = get_filename(url);
if(!filename) {
return(-1);
}
+
+ fileurl = fetchParseURL(url);
+ if(!fileurl) {
+ _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
+ RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
+ }
+
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
@@ -161,7 +140,7 @@ static int download_internal(const char *url, const char *localpath,
sigaction(SIGPIPE, NULL, &old_action);
sigaction(SIGPIPE, &new_action, NULL);
- dlf = fetchXGet(fileurl, &ust, (handle->nopassiveftp ? "i" : "pi"));
+ dlf = fetchXGet(fileurl, &ust, "i");
if(fetchLastErrCode == FETCH_UNCHANGED) {
_alpm_log(PM_LOG_DEBUG, "mtimes are identical, skipping %s\n", filename);
@@ -214,14 +193,12 @@ static int download_internal(const char *url, const char *localpath,
while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
size_t nwritten = 0;
- while(nwritten < nread) {
- nwritten += fwrite(buffer, 1, (nread - nwritten), localf);
- if(ferror(localf)) {
- _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
- destfile, strerror(errno));
- ret = -1;
- goto cleanup;
- }
+ nwritten = fwrite(buffer, 1, nread, localf);
+ if((nwritten != nread) || ferror(localf)) {
+ _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
+ destfile, strerror(errno));
+ ret = -1;
+ goto cleanup;
}
dl_thisfile += nread;
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 81aaa8b1..6ff1d675 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -117,6 +117,8 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("cannot remove all files for package");
case PM_ERR_PKG_INVALID_NAME:
return _("package filename is not valid");
+ case PM_ERR_PKG_INVALID_ARCH:
+ return _("package architecture is not valid");
case PM_ERR_PKG_REPO_NOT_FOUND:
return _("no such repository");
/* Deltas */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index d1a35ad9..012d4121 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -79,6 +79,7 @@ void _alpm_handle_free(pmhandle_t *handle)
FREELIST(handle->cachedirs);
FREE(handle->logfile);
FREE(handle->lockfile);
+ FREE(handle->arch);
FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade);
FREELIST(handle->noextract);
@@ -213,13 +214,13 @@ alpm_list_t SYMEXPORT *alpm_option_get_ignoregrps()
return handle->ignoregrp;
}
-unsigned short SYMEXPORT alpm_option_get_nopassiveftp()
+const char SYMEXPORT *alpm_option_get_arch()
{
if (handle == NULL) {
pm_errno = PM_ERR_HANDLE_NULL;
- return -1;
+ return NULL;
}
- return handle->nopassiveftp;
+ return handle->arch;
}
pmdb_t SYMEXPORT *alpm_option_get_localdb()
@@ -529,9 +530,10 @@ int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
return(0);
}
-void SYMEXPORT alpm_option_set_nopassiveftp(unsigned short nopasv)
+void SYMEXPORT alpm_option_set_arch(const char *arch)
{
- handle->nopassiveftp = nopasv;
+ if(handle->arch) FREE(handle->arch);
+ if(arch) handle->arch = strdup(arch);
}
void SYMEXPORT alpm_option_set_usedelta(unsigned short usedelta)
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index c7c262cf..a1eb1cde 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -58,7 +58,7 @@ typedef struct _pmhandle_t {
/* options */
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
- unsigned short nopassiveftp; /* Don't use PASV ftp connections */
+ char *arch; /* Architecture of packages we should allow */
unsigned short usedelta; /* Download deltas if possible */
} pmhandle_t;
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 6e847e64..240bf816 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -317,6 +317,31 @@ int _alpm_trans_addtarget(pmtrans_t *trans, char *target)
return(0);
}
+static alpm_list_t *check_arch(alpm_list_t *pkgs)
+{
+ alpm_list_t *i;
+ alpm_list_t *invalid = NULL;
+
+ const char *arch = alpm_option_get_arch();
+ if(!arch) {
+ return(NULL);
+ }
+ for(i = pkgs; i; i = i->next) {
+ pmpkg_t *pkg = i->data;
+ const char *pkgarch = alpm_pkg_get_arch(pkg);
+ if(strcmp(pkgarch,arch) && strcmp(pkgarch,"any")) {
+ char *string;
+ const char *pkgname = alpm_pkg_get_name(pkg);
+ const char *pkgver = alpm_pkg_get_version(pkg);
+ size_t len = strlen(pkgname) + strlen(pkgver) + strlen(pkgarch) + 3;
+ MALLOC(string, len, RET_ERR(PM_ERR_MEMORY, invalid));
+ sprintf(string, "%s-%s-%s", pkgname, pkgver, pkgarch);
+ invalid = alpm_list_add(invalid, string);
+ }
+ }
+ return(invalid);
+}
+
int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data)
{
if(data) {
@@ -333,6 +358,14 @@ int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data)
return(0);
}
+ alpm_list_t *invalid = check_arch(trans->packages);
+ if(invalid) {
+ if(data) {
+ *data = invalid;
+ }
+ RET_ERR(PM_ERR_PKG_INVALID_ARCH, -1);
+ }
+
switch(trans->type) {
case PM_TRANS_TYPE_UPGRADE:
if(_alpm_add_prepare(trans, handle->db_local, data) == -1) {