Re: [Bug-wget] [PATCH 08/25] Implement Metalink/XML --directory-prefix option in Metalink module

2016-09-12 Thread Matthew White
On Sun, 11 Sep 2016 22:32:13 +0200
Giuseppe Scrivano  wrote:

> > +  /* The directory prefix for opt.metalink_over_http is handled by
> > + src/url.c (url_file_name), do not add it a second time.  */
> > +  if (!metalink->origin && opt.dir_prefix && strlen (opt.dir_prefix))
> > +filename = aprintf("%s/%s", opt.dir_prefix, mfile->name);
> 
> please leave a space between aprintf and '('.

Thanks, fixed here and in other patches.

Posting after final decisions are taken about open topics in this series of 
patches.

> 
> Giuseppe

Regards,
Matthew

-- 
Matthew White 


pgpdKnFluEGuy.pgp
Description: PGP signature


Re: [Bug-wget] [PATCH 08/25] Implement Metalink/XML --directory-prefix option in Metalink module

2016-09-11 Thread Giuseppe Scrivano
> +  /* The directory prefix for opt.metalink_over_http is handled by
> + src/url.c (url_file_name), do not add it a second time.  */
> +  if (!metalink->origin && opt.dir_prefix && strlen (opt.dir_prefix))
> +filename = aprintf("%s/%s", opt.dir_prefix, mfile->name);

please leave a space between aprintf and '('.

Giuseppe



[Bug-wget] [PATCH 08/25] Implement Metalink/XML --directory-prefix option in Metalink module

2016-09-10 Thread Matthew White
[Coverity Scan is ok, make syntax-check is ok, make check-valgrind is ok, 
contrib/check-hard is ok]

This implements the use of the option --directory-prefix in the Metalink module.

The following description is verbatim from the patch:
-
When --directory-prefix= is used, set the top of the retrieval
tree to prefix. The default is . (the current directory). Metalink/XML
and Metalink/HTTP files will be downloaded under prefix.
-

Regards,
Matthew

-- 
Matthew White 
>From 43840eac31697a06e15924976d25b91c697942f6 Mon Sep 17 00:00:00 2001
From: Matthew White 
Date: Wed, 17 Aug 2016 04:45:06 +0200
Subject: [PATCH 08/25] Implement Metalink/XML --directory-prefix option in
 Metalink module

* src/metalink.c (retrieve_from_metalink): Add opt.dir_prefix as
  prefix to the metalink:file name mfile->name
* doc/metalink.txt: Update document. Explain --directory-prefix

When --directory-prefix= is used, set the top of the retrieval
tree to prefix. The default is . (the current directory). Metalink/XML
and Metalink/HTTP files will be downloaded under prefix.
---
 doc/metalink.txt |  8 ++--
 src/metalink.c   | 61 
 2 files changed, 37 insertions(+), 32 deletions(-)

diff --git a/doc/metalink.txt b/doc/metalink.txt
index 904ef2e..94a07ba 100644
--- a/doc/metalink.txt
+++ b/doc/metalink.txt
@@ -157,9 +157,5 @@ References:
 '-P prefix'
 '--directory-prefix=prefix'
 
-Do not apply to Metalink/XML files (aka --input-metalink=).
-
-Apply to Metalink/HTTP downloads.
-
-The directory prefix is the directory where all other files and
-subdirectories will be saved to, see wget(1).
+Set the top of the retrieval tree to prefix for both Metalink/XML
+and Metalink/HTTP downloads, see wget(1).
diff --git a/src/metalink.c b/src/metalink.c
index 13d0e6a..e34b410 100644
--- a/src/metalink.c
+++ b/src/metalink.c
@@ -87,6 +87,7 @@ retrieve_from_metalink (const metalink_t* metalink)
   metalink_file_t *mfile = *mfile_ptr;
   metalink_resource_t **mres_ptr;
   char *filename = NULL;
+  char *destname = NULL;
   bool hash_ok = false;
 
   uerr_t retr_err = METALINK_MISSING_RESOURCE;
@@ -100,6 +101,13 @@ retrieve_from_metalink (const metalink_t* metalink)
 
   output_stream = NULL;
 
+  /* The directory prefix for opt.metalink_over_http is handled by
+ src/url.c (url_file_name), do not add it a second time.  */
+  if (!metalink->origin && opt.dir_prefix && strlen (opt.dir_prefix))
+filename = aprintf("%s/%s", opt.dir_prefix, mfile->name);
+  else
+filename = xstrdup (mfile->name);
+
   DEBUGP (("Processing metalink file %s...\n", quote (mfile->name)));
 
   /* Resources are sorted by priority.  */
@@ -133,12 +141,12 @@ retrieve_from_metalink (const metalink_t* metalink)
 
   fclose (output_stream);
   output_stream = NULL;
-  badhash_or_remove (filename);
-  xfree (filename);
+  badhash_or_remove (destname);
+  xfree (destname);
 }
-  else if (!output_stream && filename)
+  else if (!output_stream && destname)
 {
-  xfree (filename);
+  xfree (destname);
 }
 
   retr_err = METALINK_RETR_ERROR;
@@ -180,10 +188,10 @@ retrieve_from_metalink (const metalink_t* metalink)
  after we are finished with the file.  */
   if (opt.always_rest)
 /* continue previous download */
-output_stream = fopen (mfile->name, "ab");
+output_stream = fopen (filename, "ab");
   else
 /* create a file with an unique name */
-output_stream = unique_create (mfile->name, true, );
+output_stream = unique_create (filename, true, );
 }
 
   output_stream_regular = true;
@@ -203,29 +211,29 @@ retrieve_from_metalink (const metalink_t* metalink)
 * src/http.c (open_output_stream): If output_stream is
   NULL, create the opt.output_document "path/file"
   */
-  if (!filename)
-filename = xstrdup (mfile->name);
+  if (!destname)
+destname = xstrdup (filename);
 
   /* Store the real file name for displaying in messages,
  and for proper RFC5854 "path/file" handling.  */
-  opt.output_document = filename;
+  opt.output_document = destname;
 
   opt.metalink_over_http = false;
-  DEBUGP (("Storing to %s\n", filename));
+  DEBUGP (("Storing to %s\n", destname));
   retr_err = retrieve_url (url, mres->url, NULL, NULL,
NULL, NULL, opt.recursive, iri, false);