Fixed issue 19 "xbps-src cannot fetch source with unknown Content-Length".

This commit is contained in:
Juan RP 2012-01-05 12:26:57 +01:00
parent 7d631c5d11
commit c83a77c1b5
4 changed files with 23 additions and 9 deletions

5
NEWS
View File

@ -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

View File

@ -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");

View File

@ -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"
/**

View File

@ -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