Remove libdownload support and fix libfetch one.
Aaron said to consider libdownload a dead project so libdownload support was removed to more easily fix libfetch one (otherwise many ifdef needed). There was no direct replacement for ferror to detect an error while downloading. So instead, I added a check at the end to see if the file was fully downloaded, which is just a small chunk of code taken from here: http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/net/libfetch/files/fetch.c?only_with_tag=MAIN Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
4ec846f5ac
commit
8017b0bb8e
3 changed files with 23 additions and 34 deletions
15
configure.ac
15
configure.ac
|
@ -93,9 +93,9 @@ AC_ARG_WITH(buildscript,
|
||||||
AS_HELP_STRING([--with-buildscript=name], [set the build script name used by makepkg]),
|
AS_HELP_STRING([--with-buildscript=name], [set the build script name used by makepkg]),
|
||||||
[BUILDSCRIPT=$withval], [BUILDSCRIPT=PKGBUILD])
|
[BUILDSCRIPT=$withval], [BUILDSCRIPT=PKGBUILD])
|
||||||
|
|
||||||
# Help line for libdownload/libfetch
|
# Help line for libfetch
|
||||||
AC_ARG_ENABLE(internal-download,
|
AC_ARG_ENABLE(internal-download,
|
||||||
AS_HELP_STRING([--disable-internal-download], [do not build with libdownload/libfetch support]),
|
AS_HELP_STRING([--disable-internal-download], [do not build with libfetch support]),
|
||||||
[internaldownload=$enableval], [internaldownload=yes])
|
[internaldownload=$enableval], [internaldownload=yes])
|
||||||
|
|
||||||
# Help line for documentation
|
# Help line for documentation
|
||||||
|
@ -136,17 +136,14 @@ AM_GNU_GETTEXT_VERSION(0.13.1)
|
||||||
AC_CHECK_LIB([archive], [archive_read_data], ,
|
AC_CHECK_LIB([archive], [archive_read_data], ,
|
||||||
AC_MSG_ERROR([libarchive is needed to compile pacman!]))
|
AC_MSG_ERROR([libarchive is needed to compile pacman!]))
|
||||||
|
|
||||||
# Enable or disable usage of libdownload/libfetch
|
# Enable or disable usage of libfetch
|
||||||
# - this is a nested check- first see if we need a library, if we do then
|
AC_MSG_CHECKING(whether to link with libfetch)
|
||||||
# check for libdownload first, then fallback to libfetch, then die
|
|
||||||
AC_MSG_CHECKING(whether to link with download library)
|
|
||||||
if test "x$internaldownload" = "xyes" ; then
|
if test "x$internaldownload" = "xyes" ; then
|
||||||
AC_MSG_RESULT(yes)
|
AC_MSG_RESULT(yes)
|
||||||
AC_DEFINE([INTERNAL_DOWNLOAD], , [Use internal download library])
|
AC_DEFINE([INTERNAL_DOWNLOAD], , [Use internal download library])
|
||||||
# Check for a download library if it was actually requested
|
# Check for a download library if it was actually requested
|
||||||
AC_CHECK_LIB([download], [downloadParseURL], ,
|
AC_CHECK_LIB([fetch], [fetchParseURL], ,
|
||||||
AC_CHECK_LIB([fetch], [fetchParseURL], ,
|
AC_MSG_ERROR([libfetch is needed to compile with internal download support]) )
|
||||||
AC_MSG_ERROR([libdownload or libfetch are needed to compile with internal download support])) )
|
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -34,15 +34,7 @@
|
||||||
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LIBDOWNLOAD)
|
#if defined(INTERNAL_DOWNLOAD)
|
||||||
#include <download.h>
|
|
||||||
#define fetchFreeURL downloadFreeURL
|
|
||||||
#define fetchLastErrCode downloadLastErrCode
|
|
||||||
#define fetchLastErrString downloadLastErrString
|
|
||||||
#define fetchParseURL downloadParseURL
|
|
||||||
#define fetchTimeout downloadTimeout
|
|
||||||
#define fetchXGet downloadXGet
|
|
||||||
#elif defined(HAVE_LIBFETCH)
|
|
||||||
#include <fetch.h>
|
#include <fetch.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -109,7 +101,8 @@ static struct url *url_for_string(const char *url)
|
||||||
|
|
||||||
static int download_internal(const char *url, const char *localpath,
|
static int download_internal(const char *url, const char *localpath,
|
||||||
time_t mtimeold, time_t *mtimenew) {
|
time_t mtimeold, time_t *mtimenew) {
|
||||||
FILE *dlf, *localf = NULL;
|
fetchIO *dlf = NULL;
|
||||||
|
FILE *localf = NULL;
|
||||||
struct url_stat ust;
|
struct url_stat ust;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int chk_resume = 0, ret = 0;
|
int chk_resume = 0, ret = 0;
|
||||||
|
@ -214,16 +207,8 @@ static int download_internal(const char *url, const char *localpath,
|
||||||
handle->dlcb(filename, 0, ust.size);
|
handle->dlcb(filename, 0, ust.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
while((nread = fread(buffer, 1, PM_DLBUF_LEN, dlf)) > 0) {
|
while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
|
||||||
size_t nwritten = 0;
|
size_t nwritten = 0;
|
||||||
if(ferror(dlf)) {
|
|
||||||
pm_errno = PM_ERR_LIBFETCH;
|
|
||||||
_alpm_log(PM_LOG_ERROR, _("error downloading '%s': %s\n"),
|
|
||||||
filename, fetchLastErrString);
|
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
while(nwritten < nread) {
|
while(nwritten < nread) {
|
||||||
nwritten += fwrite(buffer, 1, (nread - nwritten), localf);
|
nwritten += fwrite(buffer, 1, (nread - nwritten), localf);
|
||||||
if(ferror(localf)) {
|
if(ferror(localf)) {
|
||||||
|
@ -239,12 +224,22 @@ static int download_internal(const char *url, const char *localpath,
|
||||||
handle->dlcb(filename, dl_thisfile, ust.size);
|
handle->dlcb(filename, dl_thisfile, ust.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* did the transfer complete normally? */
|
||||||
|
if (ust.size != -1 && dl_thisfile < ust.size) {
|
||||||
|
pm_errno = PM_ERR_LIBFETCH;
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
|
||||||
|
filename, (intmax_t)dl_thisfile, (intmax_t)ust.size);
|
||||||
|
ret = -1;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
/* probably safer to close the file descriptors now before renaming the file,
|
/* probably safer to close the file descriptors now before renaming the file,
|
||||||
* for example to make sure the buffers are flushed.
|
* for example to make sure the buffers are flushed.
|
||||||
*/
|
*/
|
||||||
fclose(localf);
|
fclose(localf);
|
||||||
localf = NULL;
|
localf = NULL;
|
||||||
fclose(dlf);
|
fetchIO_close(dlf);
|
||||||
dlf = NULL;
|
dlf = NULL;
|
||||||
|
|
||||||
rename(tempfile, destfile);
|
rename(tempfile, destfile);
|
||||||
|
@ -260,7 +255,7 @@ cleanup:
|
||||||
fclose(localf);
|
fclose(localf);
|
||||||
}
|
}
|
||||||
if(dlf != NULL) {
|
if(dlf != NULL) {
|
||||||
fclose(dlf);
|
fetchIO_close(dlf);
|
||||||
}
|
}
|
||||||
fetchFreeURL(fileurl);
|
fetchFreeURL(fileurl);
|
||||||
return(ret);
|
return(ret);
|
||||||
|
|
|
@ -30,10 +30,7 @@
|
||||||
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
#include <sys/param.h> /* MAXHOSTNAMELEN */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_LIBDOWNLOAD)
|
#if defined(INTERNAL_DOWNLOAD)
|
||||||
#include <download.h> /* downloadLastErrString */
|
|
||||||
#define fetchLastErrString downloadLastErrString
|
|
||||||
#elif defined(HAVE_LIBFETCH)
|
|
||||||
#include <fetch.h> /* fetchLastErrString */
|
#include <fetch.h> /* fetchLastErrString */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue