Allow fetching pkg(8) even if servers/proxies are not passing Content-length

This commit is contained in:
Baptiste Daroussin 2015-04-03 17:35:30 +00:00
parent 5d291f76e6
commit cc36fe4926
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=281039

View file

@ -47,7 +47,6 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <ucl.h> #include <ucl.h>
@ -177,14 +176,11 @@ fetch_to_fd(const char *url, char *path)
/* To store _https._tcp. + hostname + \0 */ /* To store _https._tcp. + hostname + \0 */
int fd; int fd;
int retry, max_retry; int retry, max_retry;
off_t done, r; ssize_t r;
time_t now, last;
char buf[10240]; char buf[10240];
char zone[MAXHOSTNAMELEN + 13]; char zone[MAXHOSTNAMELEN + 13];
static const char *mirror_type = NULL; static const char *mirror_type = NULL;
done = 0;
last = 0;
max_retry = 3; max_retry = 3;
current = mirrors = NULL; current = mirrors = NULL;
remote = NULL; remote = NULL;
@ -238,19 +234,16 @@ fetch_to_fd(const char *url, char *path)
} }
} }
while (done < st.size) { while ((r = fread(buf, 1, sizeof(buf), remote)) > 0) {
if ((r = fread(buf, 1, sizeof(buf), remote)) < 1)
break;
if (write(fd, buf, r) != r) { if (write(fd, buf, r) != r) {
warn("write()"); warn("write()");
goto fetchfail; goto fetchfail;
} }
}
done += r; if (r != 0) {
now = time(NULL); warn("An error occurred while fetching pkg(8)");
if (now > last || done == st.size) goto fetchfail;
last = now;
} }
if (ferror(remote)) if (ferror(remote))