>From 80c1b02a08c20d946f0dfd8848c27250edfde34a Mon Sep 17 00:00:00 2001 From: Matthew White Date: Thu, 4 Aug 2016 11:35:42 +0200 Subject: [PATCH] Bugfix: Continue download when retrying with the next metalink:url * src/metalink.c (retrieve_from_metalink): If output_stream isn't NULL, continue download with the next mres->url Bug: * src/metalink.c (retrieve_from_metalink): If output_stream isn't NULL, restart download with the next mres->url Keep the download progress while iterating metalink:url. In such scenario, closing output_stream means to lose the download progress. --- src/metalink.c | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/src/metalink.c b/src/metalink.c index 1799e3a..2e296f9 100644 --- a/src/metalink.c +++ b/src/metalink.c @@ -119,24 +119,6 @@ retrieve_from_metalink (const metalink_t* metalink) retr_err = METALINK_RETR_ERROR; - /* If output_stream is not NULL, then we have failed on - previous resource and are retrying. Thus, rename/remove - the file. */ - if (output_stream) - { - fclose (output_stream); - output_stream = NULL; - badhash_or_remove (filename); - xfree (filename); - } - else if (filename) - { - /* Rename/remove the file downloaded previously before - downloading it again. */ - badhash_or_remove (filename); - xfree (filename); - } - /* Parse our resource URL. */ iri = iri_new (); set_uri_encoding (iri, opt.locale, true); @@ -156,17 +138,29 @@ retrieve_from_metalink (const metalink_t* metalink) /* Avoid recursive Metalink from HTTP headers. */ bool _metalink_http = opt.metalink_over_http; - /* Assure proper local file name regardless of the URL - of particular Metalink resource. - To do that we create the local file here and put - it as output_stream. We restore the original configuration - after we are finished with the file. */ - if (opt.always_rest) - /* continue previous download */ - output_stream = fopen (mfile->name, "ab"); + /* If output_stream is not NULL, then we have failed on + previous resource and are retrying. Thus, continue + with the next resource. Do not close output_stream + while iterating over the resources, or the download + progress will be lost. */ + if (output_stream) + { + DEBUGP (("Previous resource failed, continue with next resource.\n")); + } else - /* create a file with an unique name */ - output_stream = unique_create (mfile->name, true, &filename); + { + /* Assure proper local file name regardless of the URL + of particular Metalink resource. + To do that we create the local file here and put + it as output_stream. We restore the original configuration + after we are finished with the file. */ + if (opt.always_rest) + /* continue previous download */ + output_stream = fopen (mfile->name, "ab"); + else + /* create a file with an unique name */ + output_stream = unique_create (mfile->name, true, &filename); + } output_stream_regular = true; -- 2.7.3