summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-04-06 21:00:11 -0500
committerDan McGee <dan@archlinux.org>2008-04-06 21:00:11 -0500
commita708c6eadc107475015eb2fbe2c7ec5d00bc0099 (patch)
treeaea2f624e4eb92554b041f355862c44662cfb10e /lib/libalpm
parent9c7ebe68724791f06cdde2febdf91f0472f18407 (diff)
downloadpacman-a708c6eadc107475015eb2fbe2c7ec5d00bc0099.tar.xz
Allow disabling of internal (libdownload) code
Add a new --disable-internal-download flag to configure allowing the internal download code to be skipped. This will be helpful on platforms that currently don't support either libdownload or libfetch (such as Cygwin) and for just compiling a lighter weight pacman binary. This was made really easy by our recent refactoring of the download code into separate internal and external functions, as well as some error code cleanup. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm.h6
-rw-r--r--lib/libalpm/dload.c72
-rw-r--r--lib/libalpm/error.c12
3 files changed, 56 insertions, 34 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index bd641b3b..a7ea0630 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -468,12 +468,10 @@ enum _pmerrno_t {
PM_ERR_RETRIEVE,
PM_ERR_PKG_HOLD,
PM_ERR_INVALID_REGEX,
- /* Downloading */
- PM_ERR_CONNECT_FAILED,
- PM_ERR_FORK_FAILED,
/* External library errors */
PM_ERR_LIBARCHIVE,
- PM_ERR_LIBDOWNLOAD
+ PM_ERR_LIBDOWNLOAD,
+ PM_ERR_EXTERNAL_DOWNLOAD
};
extern enum _pmerrno_t pm_errno;
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index ceaf2743..0977eea0 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -24,7 +24,9 @@
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#if defined(INTERNAL_DOWNLOAD)
#include <download.h> /* libdownload */
+#endif
/* libalpm */
#include "dload.h"
@@ -34,30 +36,6 @@
#include "util.h"
#include "handle.h"
-/* Build a 'struct url' from an url. */
-static struct url *url_for_string(const char *url)
-{
- struct url *ret = NULL;
- ret = downloadParseURL(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 char *get_filename(const char *url) {
char *filename = strrchr(url, '/');
if(filename != NULL) {
@@ -86,6 +64,31 @@ static char *get_tempfile(const char *path, const char *filename) {
return(tempfile);
}
+#if defined(INTERNAL_DOWNLOAD)
+/* Build a 'struct url' from an url. */
+static struct url *url_for_string(const char *url)
+{
+ struct url *ret = NULL;
+ ret = downloadParseURL(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) {
FILE *dlf, *localf = NULL;
@@ -230,6 +233,7 @@ cleanup:
downloadFreeURL(fileurl);
return(ret);
}
+#endif
static int download_external(const char *url, const char *localpath,
time_t mtimeold, time_t *mtimenew) {
@@ -242,9 +246,13 @@ static int download_external(const char *url, const char *localpath,
char cwd[PATH_MAX];
char *destfile, *tempfile, *filename;
+ if(!handle->xfercommand) {
+ RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+ }
+
filename = get_filename(url);
if(!filename) {
- return(-1);
+ RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
}
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
@@ -275,7 +283,7 @@ static int download_external(const char *url, const char *localpath,
getcwd(cwd, PATH_MAX);
if(chdir(localpath)) {
_alpm_log(PM_LOG_WARNING, _("could not chdir to %s\n"), localpath);
- pm_errno = PM_ERR_CONNECT_FAILED;
+ pm_errno = PM_ERR_EXTERNAL_DOWNLOAD;
ret = -1;
goto cleanup;
}
@@ -285,7 +293,7 @@ static int download_external(const char *url, const char *localpath,
if(retval == -1) {
_alpm_log(PM_LOG_WARNING, _("running XferCommand: fork failed!\n"));
- pm_errno = PM_ERR_FORK_FAILED;
+ pm_errno = PM_ERR_EXTERNAL_DOWNLOAD;
ret = -1;
} else if(retval != 0) {
/* download failed */
@@ -331,8 +339,18 @@ static int download(const char *url, const char *localpath,
return(ret ? -1 : 0);
}
+ /* We have a few things to take into account here.
+ * 1. If we have both internal/external available, choose based on
+ * whether xfercommand is populated.
+ * 2. If we only have external available, we should first check
+ * if a command was provided before we drop into download_external.
+ */
if(handle->xfercommand == NULL) {
+#if defined(INTERNAL_DOWNLOAD)
ret = download_internal(url, localpath, mtimeold, mtimenew);
+#else
+ RET_ERR(PM_ERR_EXTERNAL_DOWNLOAD, -1);
+#endif
} else {
ret = download_external(url, localpath, mtimeold, mtimenew);
}
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 49eca544..30e9cf86 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -19,7 +19,9 @@
#include "config.h"
+#if defined(INTERNAL_DOWNLOAD)
#include <download.h> /* downloadLastErrString */
+#endif
/* libalpm */
#include "util.h"
@@ -132,9 +134,6 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("not confirmed");
case PM_ERR_INVALID_REGEX:
return _("invalid regular expression");
- /* Downloading */
- case PM_ERR_CONNECT_FAILED:
- return _("connection to remote host failed");
/* Errors from external libraries- our own wrapper error */
case PM_ERR_LIBARCHIVE:
/* it would be nice to use archive_error_string() here, but that
@@ -142,7 +141,14 @@ const char SYMEXPORT *alpm_strerror(int err)
* error string instead. */
return _("libarchive error");
case PM_ERR_LIBDOWNLOAD:
+#if defined(INTERNAL_DOWNLOAD)
return downloadLastErrString;
+#else
+ /* obviously shouldn't get here... */
+ return _("libdownload error");
+#endif
+ case PM_ERR_EXTERNAL_DOWNLOAD:
+ return _("error invoking external downloader");
/* Unknown error! */
default:
return _("unexpected error");