diff options
Diffstat (limited to 'lib/libalpm/dload.c')
-rw-r--r-- | lib/libalpm/dload.c | 53 |
1 files changed, 15 insertions, 38 deletions
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 10be5e9d..8b3226bd 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 const char *gethost(struct url *fileurl) { const char *host = _("disk"); @@ -120,17 +96,20 @@ static int download_internal(const char *url, const char *localpath, ssize_t 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); @@ -171,7 +150,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); @@ -220,14 +199,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; |