On Sat, 30 Jul 2016 21:23:56 +0200
Matthew White <[email protected]> wrote:

> Hello!
> 
> I noticed that wget doesn't use the metalink:file element as the RFC5854 
> suggests.
> 
> https://tools.ietf.org/html/rfc5854#section-4.1.2.1
> 
> The RFC5854 specifies that the metalink:file could have a "path/file" format. 
> In this case wget should create the "path" tree and save the file as 
> "path/file", but it doesn't. Instead wget saves the file in the working 
> directory.
> 
> e.g. <file name="dirA/dirB/file.gz">
> 
> With this patch wget conforms to the RFC5854.
> 
> I made this patch working on the following branch:
> master (latest 20cac2c5ab3d63aacfba35fb10878a2d490e2377)
> git://git.savannah.gnu.org/wget.git
> 
> Let me know if this helps.

Hi,

After the suggestions of Tim, I fixed the patch (nice! fix the fix...). So, 
scratch the previous patch and use this one instead.

The function concat_strings() replaces the combination of malloc(), strlen(), 
and strcpy(). (Thanks Tim.)

The description now follows the style of the other patches. (Thanks again Tim!)

You may consider this patch a Bugfix:
* src/utils.c (unique_create, fopen_excl): cannot create a directory tree like 
"path/file".

The problem is that fopen_excl() doesn't create non-existing directories. What 
do you suggest?

Can we make this patch obsolete?

-- 
Matthew White <[email protected]>
>From 9c4b04e906771b698048da5f4a44b6f6bae9acdd Mon Sep 17 00:00:00 2001
From: Matthew White <[email protected]>
Date: Thu, 28 Jul 2016 17:10:46 +0200
Subject: [PATCH] Bugfix: create/download/verify Metalink's files with a
 "path/file" format

* src/metalink.c (retrieve_from_metalink): Set filename to mfile->name
  to create/download/verify files with a "path/file" format

Bug:
* src/utils.c (unique_create, fopen_excl): cannot create "path/file"
* src/metalink.c (retrieve_from_metalink): when filename is NULL,
  "path/file" is downloaded as "file", and it cannot be verified

The directory information contained in a metalink:file element shall
be used in the same way the option --directory-prefix will.

  <file name="dirA/dirB/file.gz">

  --directory-prefix="dirA/dirB/file.gz"

This patch conforms to the RFC5854 specification:
  The Metalink Download Description Format
  4.1.2.1.  The "name" Attribute
  https://tools.ietf.org/html/rfc5854#section-4.1.2.1
---
 src/metalink.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/metalink.c b/src/metalink.c
index 9f34b32..545b0cb 100644
--- a/src/metalink.c
+++ b/src/metalink.c
@@ -156,6 +156,13 @@ retrieve_from_metalink (const metalink_t* metalink)
               output_stream = unique_create (mfile->name, true, &filename);
               output_stream_regular = true;
 
+              /* Bug: utils.h (unique_create): cannot create a
+                 "path/file" tree.  Bugfix: If filename is set to
+                 "path/file", a tree is created in the same way as
+                 --directory-prefix does (see RFC5854).  */
+              if (filename == NULL && mfile->name)
+                filename = concat_strings (mfile->name, (char *)0);
+
               /* Store the real file name for displaying in messages.  */
               opt.output_document = filename;
 
-- 
2.7.3

Reply via email to