summaryrefslogtreecommitdiffstats
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
-rw-r--r--lib/libalpm/util.c45
-rw-r--r--lib/libalpm/util.h1
8 files changed, 62 insertions, 92 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) {
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 082c095b..f78d193a 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -196,51 +196,6 @@ char *_alpm_strtrim(char *str)
return(str);
}
-/* Helper function for _alpm_strreplace */
-static void _strnadd(char **str, const char *append, unsigned int count)
-{
- if(*str) {
- *str = realloc(*str, strlen(*str) + count + 1);
- } else {
- *str = calloc(count + 1, sizeof(char));
- }
-
- strncat(*str, append, count);
-}
-
-/* Replace all occurances of 'needle' with 'replace' in 'str', returning
- * a new string (must be free'd) */
-char *_alpm_strreplace(const char *str, const char *needle, const char *replace)
-{
- const char *p, *q;
- p = q = str;
-
- char *newstr = NULL;
- unsigned int needlesz = strlen(needle),
- replacesz = strlen(replace);
-
- while (1) {
- q = strstr(p, needle);
- if(!q) { /* not found */
- if(*p) {
- /* add the rest of 'p' */
- _strnadd(&newstr, p, strlen(p));
- }
- break;
- } else { /* found match */
- if(q > p){
- /* add chars between this occurance and last occurance, if any */
- _strnadd(&newstr, p, q - p);
- }
- _strnadd(&newstr, replace, replacesz);
- p = q + needlesz;
- }
- }
-
- return newstr;
-}
-
-
/* Create a lock file */
int _alpm_lckmk()
{
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 4bc8b92f..ccf169d3 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -60,7 +60,6 @@ int _alpm_makepath(const char *path);
int _alpm_makepath_mode(const char *path, mode_t mode);
int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtrim(char *str);
-char *_alpm_strreplace(const char *str, const char *needle, const char *replace);
int _alpm_lckmk();
int _alpm_lckrm();
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);