|
|
ec4f2a |
From 614d7874bfa82cb19b328278590af0f99e1ec682 Mon Sep 17 00:00:00 2001
|
|
|
ec4f2a |
From: Jonathan Dieter <jdieter@gmail.com>
|
|
|
ec4f2a |
Date: Fri, 14 Jun 2019 23:13:30 +0100
|
|
|
ec4f2a |
Subject: [PATCH] Handle webservers that don't support ranges when downloading zck
|
|
|
ec4f2a |
|
|
|
ec4f2a |
Make sure we fall back to downloading full zchunk file if a webserver
|
|
|
ec4f2a |
doesn't support ranges.
|
|
|
ec4f2a |
|
|
|
ec4f2a |
Signed-off-by: Jonathan Dieter <jdieter@gmail.com>
|
|
|
ec4f2a |
---
|
|
|
ec4f2a |
librepo/downloader.c | 37 ++++++++++++++++++++++++++-----------
|
|
|
ec4f2a |
librepo/downloadtarget.c | 1 +
|
|
|
ec4f2a |
librepo/downloadtarget.h | 4 ++++
|
|
|
ec4f2a |
3 files changed, 31 insertions(+), 11 deletions(-)
|
|
|
ec4f2a |
|
|
|
ec4f2a |
diff --git a/librepo/downloader.c b/librepo/downloader.c
|
|
|
ec4f2a |
index 6189681..53161f7 100644
|
|
|
ec4f2a |
--- a/librepo/downloader.c
|
|
|
ec4f2a |
+++ b/librepo/downloader.c
|
|
|
ec4f2a |
@@ -473,7 +473,7 @@ lr_headercb(void *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
ec4f2a |
}
|
|
|
ec4f2a |
|
|
|
ec4f2a |
#ifdef WITH_ZCHUNK
|
|
|
ec4f2a |
- if(lrtarget->target->is_zchunk)
|
|
|
ec4f2a |
+ if(lrtarget->target->is_zchunk && lrtarget->mirror->max_ranges > 0)
|
|
|
ec4f2a |
return lr_zckheadercb(ptr, size, nmemb, userdata);
|
|
|
ec4f2a |
#endif /* WITH_ZCHUNK */
|
|
|
ec4f2a |
|
|
|
ec4f2a |
@@ -586,7 +586,7 @@ lr_writecb(char *ptr, size_t size, size_t nmemb, void *userdata)
|
|
|
ec4f2a |
size_t cur_written;
|
|
|
ec4f2a |
LrTarget *target = (LrTarget *) userdata;
|
|
|
ec4f2a |
#ifdef WITH_ZCHUNK
|
|
|
ec4f2a |
- if(target->target->is_zchunk)
|
|
|
ec4f2a |
+ if(target->target->is_zchunk && target->mirror->max_ranges > 0)
|
|
|
ec4f2a |
return lr_zck_writecb(ptr, size, nmemb, userdata);
|
|
|
ec4f2a |
#endif /* WITH_ZCHUNK */
|
|
|
ec4f2a |
|
|
|
ec4f2a |
@@ -1240,6 +1240,12 @@ check_zck(LrTarget *target, GError **err)
|
|
|
ec4f2a |
assert(!err || *err == NULL);
|
|
|
ec4f2a |
assert(target && target->f && target->target);
|
|
|
ec4f2a |
|
|
|
ec4f2a |
+ if(target->mirror->max_ranges == 0) {
|
|
|
ec4f2a |
+ target->zck_state = LR_ZCK_DL_BODY;
|
|
|
ec4f2a |
+ target->target->expectedsize = target->target->origsize;
|
|
|
ec4f2a |
+ return TRUE;
|
|
|
ec4f2a |
+ }
|
|
|
ec4f2a |
+
|
|
|
ec4f2a |
if(target->target->zck_dl == NULL) {
|
|
|
ec4f2a |
target->target->zck_dl = zck_dl_init(NULL);
|
|
|
ec4f2a |
if(target->target->zck_dl == NULL) {
|
|
|
ec4f2a |
@@ -2166,25 +2172,34 @@ check_transfer_statuses(LrDownload *dd, GError **err)
|
|
|
ec4f2a |
if (target->target->is_zchunk) {
|
|
|
ec4f2a |
zckCtx *zck = NULL;
|
|
|
ec4f2a |
if (target->zck_state == LR_ZCK_DL_HEADER) {
|
|
|
ec4f2a |
- if(!lr_zck_valid_header(target->target, target->target->path,
|
|
|
ec4f2a |
+ if(target->mirror->max_ranges > 0 &&
|
|
|
ec4f2a |
+ !lr_zck_valid_header(target->target, target->target->path,
|
|
|
ec4f2a |
fd, &transfer_err))
|
|
|
ec4f2a |
goto transfer_error;
|
|
|
ec4f2a |
} else if(target->zck_state == LR_ZCK_DL_BODY) {
|
|
|
ec4f2a |
- zckCtx *zck = zck_dl_get_zck(target->target->zck_dl);
|
|
|
ec4f2a |
- if(zck == NULL) {
|
|
|
ec4f2a |
- g_set_error(&transfer_err, LR_DOWNLOADER_ERROR, LRE_ZCK,
|
|
|
ec4f2a |
- "Unable to get zchunk file from download context");
|
|
|
ec4f2a |
- goto transfer_error;
|
|
|
ec4f2a |
+ if(target->mirror->max_ranges > 0) {
|
|
|
ec4f2a |
+ zckCtx *zck = zck_dl_get_zck(target->target->zck_dl);
|
|
|
ec4f2a |
+ if(zck == NULL) {
|
|
|
ec4f2a |
+ g_set_error(&transfer_err, LR_DOWNLOADER_ERROR, LRE_ZCK,
|
|
|
ec4f2a |
+ "Unable to get zchunk file from download context");
|
|
|
ec4f2a |
+ goto transfer_error;
|
|
|
ec4f2a |
+ }
|
|
|
ec4f2a |
+ if(zck_failed_chunks(zck) == 0 && zck_missing_chunks(zck) == 0)
|
|
|
ec4f2a |
+ target->zck_state = LR_ZCK_DL_FINISHED;
|
|
|
ec4f2a |
+ } else {
|
|
|
ec4f2a |
+ if(target->range_fail) {
|
|
|
ec4f2a |
+ target->range_fail = FALSE;
|
|
|
ec4f2a |
+ } else {
|
|
|
ec4f2a |
+ target->zck_state = LR_ZCK_DL_FINISHED;
|
|
|
ec4f2a |
+ }
|
|
|
ec4f2a |
}
|
|
|
ec4f2a |
- if(zck_failed_chunks(zck) == 0 && zck_missing_chunks(zck) == 0)
|
|
|
ec4f2a |
- target->zck_state = LR_ZCK_DL_FINISHED;
|
|
|
ec4f2a |
}
|
|
|
ec4f2a |
if(target->zck_state == LR_ZCK_DL_FINISHED) {
|
|
|
ec4f2a |
zck = lr_zck_init_read(target->target, target->target->path, fd,
|
|
|
ec4f2a |
&transfer_err);
|
|
|
ec4f2a |
if(!zck)
|
|
|
ec4f2a |
goto transfer_error;
|
|
|
ec4f2a |
- if(!zck_validate_checksums(zck)) {
|
|
|
ec4f2a |
+ if(zck_validate_checksums(zck) < 1) {
|
|
|
ec4f2a |
zck_free(&zck;;
|
|
|
ec4f2a |
g_set_error(&transfer_err, LR_DOWNLOADER_ERROR, LRE_BADCHECKSUM,
|
|
|
ec4f2a |
"At least one of the zchunk checksums doesn't match in %s",
|
|
|
ec4f2a |
diff --git a/librepo/downloadtarget.c b/librepo/downloadtarget.c
|
|
|
ec4f2a |
index d20aa44..40c10f3 100644
|
|
|
ec4f2a |
--- a/librepo/downloadtarget.c
|
|
|
ec4f2a |
+++ b/librepo/downloadtarget.c
|
|
|
ec4f2a |
@@ -100,6 +100,7 @@ lr_downloadtarget_new(LrHandle *handle,
|
|
|
ec4f2a |
target->fn = lr_string_chunk_insert(target->chunk, fn);
|
|
|
ec4f2a |
target->checksums = possiblechecksums;
|
|
|
ec4f2a |
target->expectedsize = expectedsize;
|
|
|
ec4f2a |
+ target->origsize = expectedsize;
|
|
|
ec4f2a |
target->resume = resume;
|
|
|
ec4f2a |
target->progresscb = progresscb;
|
|
|
ec4f2a |
target->cbdata = cbdata;
|
|
|
ec4f2a |
diff --git a/librepo/downloadtarget.h b/librepo/downloadtarget.h
|
|
|
ec4f2a |
index f4c1f26..c935219 100644
|
|
|
ec4f2a |
--- a/librepo/downloadtarget.h
|
|
|
ec4f2a |
+++ b/librepo/downloadtarget.h
|
|
|
ec4f2a |
@@ -88,6 +88,10 @@ typedef struct {
|
|
|
ec4f2a |
gint64 expectedsize; /*!<
|
|
|
ec4f2a |
Expected size of the target */
|
|
|
ec4f2a |
|
|
|
ec4f2a |
+ gint64 origsize; /*!<
|
|
|
ec4f2a |
+ Original expected size of the target. Sometimes expectedsize will
|
|
|
ec4f2a |
+ change, especially if zchunk is in use, but this will never change */
|
|
|
ec4f2a |
+
|
|
|
ec4f2a |
gboolean resume; /*!<
|
|
|
ec4f2a |
Resume:
|
|
|
ec4f2a |
0 - no resume, download whole file,
|
|
|
ec4f2a |
--
|
|
|
ec4f2a |
libgit2 0.28.2
|
|
|
ec4f2a |
|