Hi Tim,

Yes, that is an eventuality I did not consider when writing this test. A
user configured option that may override the settings intended for the
test. Maybe we should have a --no-config option to ensure that the tests
are run on the compiled defaults only.

Having a uniform environment for tests is a must. I've attached a patch
that introduces --no-config. However this is not yet complete and ready for
merging. Most importantly, if accepted, I need to change a few comments and
edit wget.texi explaining the new option.

In case both the --config and --no-config commands are issued, the one that
appears first on the command will be considered and the other ignored.


On Fri, Jan 17, 2014 at 1:51 PM, Tim Ruehsen <[email protected]> wrote:

> Hi,
>
> I just discovered that Test--spider-r.py fails here (parallel-wget branch).
>
> The reason is 'robots=off' in ~./wgetrc.
>
> But that leads the the question, how can we prevent any user (and global
> /etc/wgetrc) settings dropping in, possibly making the tests fail.
>
> An option like --no-config could solve this issue with just a few lines of
> code.
>
> What do you think ?
>
> Tim
>
>
>


-- 
Thanking You,
Darshit Shah
From 6ebf2a751635a83e6c1f8b7ce07b536bf0485e9c Mon Sep 17 00:00:00 2001
From: Darshit Shah <[email protected]>
Date: Fri, 17 Jan 2014 15:16:38 +0530
Subject: [PATCH] Introduce --no-config. The wgetrc files will not be read

In case of a conflict between --config and --no-config, the one
that appears first will be considered and the other ignored.
---
 src/ChangeLog |  8 ++++++++
 src/init.c    |  3 ++-
 src/main.c    | 15 ++++++++++++---
 src/options.h |  1 +
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 0ac1ac6..6b1b9b1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2014-01-17  Darshit Shah  <[email protected]>
+
+	* init.c (commands[]): Add --no-config
+	* options.h: Same
+	* main.c (option_data[]): Same
+	(print_help): Same
+	(main): If --no-config is set, then do not read the wgetrc files
+
 2014-01-05  Håkon Vågsether <[email protected]> (tiny change)
 
 	* http.c (http_loop): Fix checking the URL length when filename is
diff --git a/src/init.c b/src/init.c
index a64dabe..43d5ae9 100644
--- a/src/init.c
+++ b/src/init.c
@@ -160,7 +160,7 @@ static const struct {
 #ifdef ENABLE_DEBUG
   { "debug",            &opt.debug,             cmd_boolean },
 #endif
-  { "defaultpage", 	&opt.default_page,      cmd_string },
+  { "defaultpage",      &opt.default_page,      cmd_string },
   { "deleteafter",      &opt.delete_after,      cmd_boolean },
   { "dirprefix",        &opt.dir_prefix,        cmd_directory },
   { "dirstruct",        NULL,                   cmd_spec_dirstruct },
@@ -220,6 +220,7 @@ static const struct {
   { "mirror",           NULL,                   cmd_spec_mirror },
   { "netrc",            &opt.netrc,             cmd_boolean },
   { "noclobber",        &opt.noclobber,         cmd_boolean },
+  { "noconfig",         &opt.noconfig,          cmd_boolean },
   { "noparent",         &opt.no_parent,         cmd_boolean },
   { "noproxy",          &opt.no_proxy,          cmd_vector },
   { "numtries",         &opt.ntry,              cmd_number_inf },/* deprecated*/
diff --git a/src/main.c b/src/main.c
index 19d7253..2aa961d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -238,6 +238,7 @@ static struct cmdline_option option_data[] =
     { "mirror", 'm', OPT_BOOLEAN, "mirror", -1 },
     { "no", 'n', OPT__NO, NULL, required_argument },
     { "no-clobber", 0, OPT_BOOLEAN, "noclobber", -1 },
+    { "no-config", 0, OPT_BOOLEAN, "noconfig", -1},
     { "no-parent", 0, OPT_BOOLEAN, "noparent", -1 },
     { "output-document", 'O', OPT_VALUE, "outputdocument", -1 },
     { "output-file", 'o', OPT_VALUE, "logfile", -1 },
@@ -473,7 +474,9 @@ Logging and input file:\n"),
   -B,  --base=URL            resolves HTML input-file links (-i -F)\n\
                              relative to URL.\n"),
     N_("\
-       --config=FILE         Specify config file to use.\n"), 
+       --config=FILE         Specify config file to use.\n"),
+    N_("\
+       --no-config           Do not read any config file.\n"),
     "\n",
 
     N_("\
@@ -1045,6 +1048,7 @@ main (int argc, char **argv)
   longindex = -1;
   int retconf;
   bool use_userconfig = false;
+  bool noconfig = false;
 
   while ((retconf = getopt_long (argc, argv,
                                 short_options, long_options, &longindex)) != -1)
@@ -1057,7 +1061,12 @@ main (int argc, char **argv)
         {
           confval = long_options[longindex].val;
           config_opt = &option_data[confval & ~BOOLEAN_NEG_MARKER];
-          if (strcmp (config_opt->long_name, "config") == 0)
+          if (strcmp (config_opt->long_name, "no-config") == 0)
+            {
+              noconfig = true;
+              break;
+            }
+          else if (strcmp (config_opt->long_name, "config") == 0)
             {
               bool userrc_ret = true;
               userrc_ret &= run_wgetrc (optarg);
@@ -1074,7 +1083,7 @@ main (int argc, char **argv)
     }
 
   /* If the user did not specify a config, read the system wgetrc and ~/.wgetrc. */
-  if (use_userconfig == false)
+  if (noconfig == false && use_userconfig == false)
     initialize ();
 
   opterr = 0;
diff --git a/src/options.h b/src/options.h
index ad89627..e00fadc 100644
--- a/src/options.h
+++ b/src/options.h
@@ -60,6 +60,7 @@ struct options
   char *lfilename;		/* Log filename */
   char *input_filename;		/* Input filename */
   char *choose_config;		/* Specified config file */
+  bool noconfig;
   bool force_html;		/* Is the input file an HTML file? */
 
   char *default_page;           /* Alternative default page (index file) */
-- 
1.8.5.3

Reply via email to