summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbapt <bapt@FreeBSD.org>2015-05-30 21:49:18 +0000
committerbapt <bapt@FreeBSD.org>2015-05-30 21:49:18 +0000
commit0479e262548c958a2b5e8c461ee67036a00e9813 (patch)
treecf5b26d5cfb7ae88668a7266c356a573fe5a1300
parentf11dbe130eb577e045fef8823e0a06ffec3c99d5 (diff)
downloadFreeBSD-src-0479e262548c958a2b5e8c461ee67036a00e9813.zip
FreeBSD-src-0479e262548c958a2b5e8c461ee67036a00e9813.tar.gz
MFC: r281039
Allow fetching pkg(8) even if servers/proxies are not passing Content-length
-rw-r--r--usr.sbin/pkg/pkg.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/usr.sbin/pkg/pkg.c b/usr.sbin/pkg/pkg.c
index 90a215d..5ae6c19 100644
--- a/usr.sbin/pkg/pkg.c
+++ b/usr.sbin/pkg/pkg.c
@@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-#include <time.h>
#include <unistd.h>
#include <ucl.h>
@@ -177,14 +176,11 @@ fetch_to_fd(const char *url, char *path)
/* To store _https._tcp. + hostname + \0 */
int fd;
int retry, max_retry;
- off_t done, r;
- time_t now, last;
+ ssize_t r;
char buf[10240];
char zone[MAXHOSTNAMELEN + 13];
static const char *mirror_type = NULL;
- done = 0;
- last = 0;
max_retry = 3;
current = mirrors = NULL;
remote = NULL;
@@ -238,19 +234,16 @@ fetch_to_fd(const char *url, char *path)
}
}
- while (done < st.size) {
- if ((r = fread(buf, 1, sizeof(buf), remote)) < 1)
- break;
-
+ while ((r = fread(buf, 1, sizeof(buf), remote)) > 0) {
if (write(fd, buf, r) != r) {
warn("write()");
goto fetchfail;
}
+ }
- done += r;
- now = time(NULL);
- if (now > last || done == st.size)
- last = now;
+ if (r != 0) {
+ warn("An error occurred while fetching pkg(8)");
+ goto fetchfail;
}
if (ferror(remote))
OpenPOWER on IntegriCloud