]> sjero.net Git - wget/commitdiff
[svn] Make -P work on Windows.
authorhniksic <devnull@localhost>
Thu, 17 Jan 2002 01:03:33 +0000 (17:03 -0800)
committerhniksic <devnull@localhost>
Thu, 17 Jan 2002 01:03:33 +0000 (17:03 -0800)
Submitted by Ian Abbott in <3C447E8F.13424.16ED42@localhost>.

src/ChangeLog
src/init.c
src/utils.c

index 712d8c73ae58198133a4390ce9f7f71cd2424877..1f40548ac62b3fbf3e2ced75c3b8d022e14bbff5 100644 (file)
@@ -1,3 +1,15 @@
+2002-01-15  Ian Abbott  <abbotti@mev.co.uk>
+
+       * init.c (cmd_file): Change `\' to `/' for Windows (yes, really!)
+       (cmd_directory): New function. Like cmd_file(), but strips
+       trailing directory separators.
+       (commands): Change action for "dirprefix" from `cmd_file' to
+       `cmd_directory'.
+
+       * utils.c (make_directory): Allow intermediate `mkdir' calls to
+       fail, as not all path components that do not exist should be
+       directory components, especially under Windows.
+
 2002-01-17  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * netrc.c (parse_netrc): Skip leading whitespace before testing
index 4a49da4a8baf8f8def825fe86626e9ee5c2cf50e..033307752e628f3338e2acfe7e72666f0360766b 100644 (file)
@@ -79,6 +79,7 @@ CMD_DECLARE (cmd_number);
 CMD_DECLARE (cmd_number_inf);
 CMD_DECLARE (cmd_string);
 CMD_DECLARE (cmd_file);
+CMD_DECLARE (cmd_directory);
 CMD_DECLARE (cmd_time);
 CMD_DECLARE (cmd_vector);
 
@@ -117,7 +118,7 @@ static struct {
   { "debug",           &opt.debug,             cmd_boolean },
 #endif
   { "deleteafter",     &opt.delete_after,      cmd_boolean },
-  { "dirprefix",       &opt.dir_prefix,        cmd_file },
+  { "dirprefix",       &opt.dir_prefix,        cmd_directory },
   { "dirstruct",       NULL,                   cmd_spec_dirstruct },
   { "domains",         &opt.domains,           cmd_vector },
   { "dotbytes",                &opt.dot_bytes,         cmd_bytes },
@@ -674,7 +675,11 @@ cmd_file (const char *com, const char *val, void *closure)
 
   /* #### If VAL is empty, perhaps should set *CLOSURE to NULL.  */
 
-  if (!enable_tilde_expansion || !(*val == '~' && *(val + 1) == '/'))
+  if (!enable_tilde_expansion || !(*val == '~' && (*(val + 1) == '/'
+#ifdef WINDOWS
+         || *(val + 1) == '\\'
+#endif
+         )))
     {
     noexpand:
       *pstring = xstrdup (val);
@@ -688,12 +693,21 @@ cmd_file (const char *com, const char *val, void *closure)
        goto noexpand;
 
       homelen = strlen (home);
-      while (homelen && home[homelen - 1] == '/')
+      while (homelen && (home[homelen - 1] == '/'
+#ifdef WINDOWS
+           || home[homelen - 1] == '\\'
+#endif
+           ))
        home[--homelen] = '\0';
 
       /* Skip the leading "~/". */
+#ifdef WINDOWS
+      for (++val; *val == '/' || *val == '\\'; val++)
+       ;
+#else
       for (++val; *val == '/'; val++)
        ;
+#endif
 
       result = xmalloc (homelen + 1 + strlen (val));
       memcpy (result, home, homelen);
@@ -702,6 +716,35 @@ cmd_file (const char *com, const char *val, void *closure)
 
       *pstring = result;
     }
+#ifdef WINDOWS
+  /* Convert "\" to "/". */
+  {
+    char *s;
+    for (s = *pstring; *s; s++)
+      if (*s == '\\')
+       *s = '/';
+  }
+#endif
+  return 1;
+}
+
+/* Like cmd_file, but strips trailing '/' characters.  */
+static int
+cmd_directory (const char *com, const char *val, void *closure)
+{
+  char *s, *t;
+
+  /* Call cmd_file() for tilde expansion and separator
+     canonicalization (backslash -> slash under Windows).  These
+     things should perhaps be in a separate function.  */
+  if (!cmd_file (com, val, closure))
+    return 0;
+
+  s = *(char **)closure;
+  t = s + strlen (s);
+  while (t > s && *--t == '/')
+    *t = '\0';
+
   return 1;
 }
 
index 69f0bdc0090b20e832c5cca9ebf3cc55854314e8..3f04edafbb8f70b153a6486518c56d0d66d3a586 100644 (file)
@@ -579,6 +579,7 @@ make_directory (const char *directory)
 {
   int quit = 0;
   int i;
+  int ret = 0;
   char *dir;
 
   /* Make a copy of dir, to be able to write to it.  Otherwise, the
@@ -594,18 +595,19 @@ make_directory (const char *directory)
       if (!dir[i])
        quit = 1;
       dir[i] = '\0';
-      /* Check whether the directory already exists.  */
+      /* Check whether the directory already exists.  Allow creation of
+        of intermediate directories to fail, as the initial path components
+        are not necessarily directories!  */
       if (!file_exists_p (dir))
-       {
-         if (mkdir (dir, 0777) < 0)
-           return -1;
-       }
+       ret = mkdir (dir, 0777);
+      else
+       ret = 0;
       if (quit)
        break;
       else
        dir[i] = '/';
     }
-  return 0;
+  return ret;
 }
 
 /* Merge BASE with FILE.  BASE can be a directory or a file name, FILE