From c83a77c1b525ac6ac7a7311bc7e96aa3e6ab4db9 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 5 Jan 2012 12:26:57 +0100 Subject: [PATCH] Fixed issue 19 "xbps-src cannot fetch source with unknown Content-Length". --- NEWS | 5 +++++ bin/xbps-bin/fetch_cb.c | 18 ++++++++++++++---- include/xbps_api.h | 2 +- lib/download.c | 7 +++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 995da8a1..c1609493 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ xbps-0.12.0 (???): + * It's now possible to fetch files thru xbps_fetch_file() from HTTP + servers that don't set the Content-Length header. This fixes issue 19: + "xbps-src cannot fetch source with unknown Content-Length" reported + by ojab. + * Renamed some options in xbps.conf to not have dashes, such as: fetch-timeout-connection -> FetchTimeoutConnection fetch-cache-connections-host -> FetchCacheConnections diff --git a/bin/xbps-bin/fetch_cb.c b/bin/xbps-bin/fetch_cb.c index 5ea42dd2..a1047b43 100644 --- a/bin/xbps-bin/fetch_cb.c +++ b/bin/xbps-bin/fetch_cb.c @@ -68,6 +68,9 @@ stat_eta(const struct xbps_fetch_cb_data *xfpd, void *cbdata) long elapsed, eta; off_t received, expected; + if (xfpd->file_size == -1) + return "unknown"; + elapsed = xfer->last.tv_sec - xfer->start.tv_sec; received = xfpd->file_dloaded - xfpd->file_offset; expected = xfpd->file_size - xfpd->file_dloaded; @@ -126,17 +129,24 @@ stat_display(const struct xbps_fetch_cb_data *xfpd, void *cbdata) struct xferstat *xfer = cbdata; struct timeval now; char totsize[8], recvsize[8]; + int percentage; get_time(&now); if (now.tv_sec <= xfer->last.tv_sec) return; xfer->last = now; - (void)xbps_humanize_number(totsize, (int64_t)xfpd->file_size); + if (xfpd->file_size == -1) { + percentage = 0; + snprintf(totsize, 3, "0B"); + } else { + percentage = (int)((double)(100.0 * + (double)xfpd->file_dloaded) / (double)xfpd->file_size); + (void)xbps_humanize_number(totsize, (int64_t)xfpd->file_size); + } (void)xbps_humanize_number(recvsize, (int64_t)xfpd->file_dloaded); fprintf(stderr,"\r%s: %s [%d%% of %s]", xfpd->file_name, recvsize, - (int)((double)(100.0 * - (double)xfpd->file_dloaded) / (double)xfpd->file_size), totsize); + percentage, totsize); fprintf(stderr," %s", stat_bps(xfpd, xfer)); fprintf(stderr," ETA: %s", stat_eta(xfpd, xfer)); fprintf(stderr,"\033[K"); @@ -157,7 +167,7 @@ fetch_file_progress_cb(const struct xbps_fetch_cb_data *xfpd, void *cbdata) stat_display(xfpd, xfer); } else if (xfpd->cb_end) { /* end transfer stats */ - (void)xbps_humanize_number(size, (int64_t)xfpd->file_size); + (void)xbps_humanize_number(size, (int64_t)xfpd->file_dloaded); fprintf(stderr,"\rDownloaded %s for %s [avg rate: %s]", size, xfpd->file_name, stat_bps(xfpd, xfer)); fprintf(stderr,"\033[K\n"); diff --git a/include/xbps_api.h b/include/xbps_api.h index 8640c482..f84a1ad4 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.3" -#define XBPS_API_VERSION "20120104-1" +#define XBPS_API_VERSION "20120105" #define XBPS_VERSION "0.12" /** diff --git a/lib/download.c b/lib/download.c index 1a4dbd24..ae78b895 100644 --- a/lib/download.c +++ b/lib/download.c @@ -226,10 +226,9 @@ xbps_fetch_file(const char *uri, goto out; } if (url_st.size == -1) { - xbps_dbg_printf("Remote file size is unknown!\n"); - errno = EINVAL; - rv = -1; - goto out; + xbps_dbg_printf("Remote file size is unknown, resume " + "not possible...\n"); + restart = false; } else if (st.st_size > url_st.size) { /* * Remove local file if bigger than remote, and refetch the