Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/dload.c
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/dload.c
parent9c7ebe68724791f06cdde2febdf91f0472f18407 (diff)
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/dload.c')
-rw-r--r--lib/libalpm/dload.c72
1 files changed, 45 insertions, 27 deletions
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);
}