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.
>From 50a26f70321ac075636bad1a31c4500f22309781 Mon Sep 17 00:00:00 2001
From: Matthew White <[email protected]>
Date: Thu, 28 Jul 2016 17:10:46 +0200
Subject: [PATCH] Support metalink:file elements with a "path/file" format

Use the directory information contained in a metalink:file element in
the same way the option --directory-prefix will.

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

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

This 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: Treat metalink:file as directory prefix
---
 src/metalink.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/metalink.c b/src/metalink.c
index 6b278be..623f32d 100644
--- a/src/metalink.c
+++ b/src/metalink.c
@@ -154,6 +154,15 @@ retrieve_from_metalink (const metalink_t* metalink)
               output_stream = unique_create (mfile->name, true, &filename);
               output_stream_regular = true;
 
+              /* When filename is set, wget behaves as if the option
+                 --directory-prefix was used (see RFC5854), and
+                 creates the proper "path/file" directory tree.  */
+              if (filename == NULL && mfile->name)
+                {
+                  filename = malloc(strlen(mfile->name) + 1);
+                  strcpy(filename, mfile->name);
+                }
+
               /* Store the real file name for displaying in messages.  */
               opt.output_document = filename;
 
-- 
2.7.3

Reply via email to