diff options
author | Xavier Chantry <shiningxc@gmail.com> | 2009-08-19 17:58:03 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2009-09-06 15:51:25 -0500 |
commit | 5b27e78ba015a48baf2d3c8687fdf3084781f9c9 (patch) | |
tree | 8e9d5e4201dcebc700ccf914057d038e596ec057 /lib | |
parent | 594621cbeb2f27ce8d36e652c4fdd9a9d4385ec3 (diff) |
Check package arch before installing
This implements FS#15622
Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.h | 1 | ||||
-rw-r--r-- | lib/libalpm/error.c | 2 | ||||
-rw-r--r-- | lib/libalpm/trans.c | 33 |
3 files changed, 36 insertions, 0 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index b81b3f83..1a83f725 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -510,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/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/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) { |