fetch: handle GET with offset == length.
While xbps_fetch_file() creates the .part file and for whatever reason it did not finish properly to rename the file, it could request the server to restart the download with offset set to file size, resulting in HTTP 416 return code. Handle this case by checking if the server returns 416 and then checking if the returned file size matches the requested offset and just rename the file. Thanks to @beefcurtains for the test case.
This commit is contained in:
@ -1133,6 +1133,12 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
goto ouch;
|
||||
}
|
||||
|
||||
/* fill in stats */
|
||||
if (us) {
|
||||
us->size = size;
|
||||
us->atime = us->mtime = mtime;
|
||||
}
|
||||
|
||||
/* check for inconsistencies */
|
||||
if (clength != -1 && length != -1 && clength != length) {
|
||||
http_seterr(HTTP_PROTOCOL_ERROR);
|
||||
@ -1142,6 +1148,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
clength = length;
|
||||
if (clength != -1)
|
||||
length = offset + clength;
|
||||
|
||||
if (length != -1 && size != -1 && length != size) {
|
||||
http_seterr(HTTP_PROTOCOL_ERROR);
|
||||
goto ouch;
|
||||
@ -1149,12 +1156,6 @@ http_request(struct url *URL, const char *op, struct url_stat *us,
|
||||
if (size == -1)
|
||||
size = length;
|
||||
|
||||
/* fill in stats */
|
||||
if (us) {
|
||||
us->size = size;
|
||||
us->atime = us->mtime = mtime;
|
||||
}
|
||||
|
||||
/* too far? */
|
||||
if (URL->offset > 0 && offset > URL->offset) {
|
||||
http_seterr(HTTP_PROTOCOL_ERROR);
|
||||
|
Reference in New Issue
Block a user