]> sjero.net Git - wget/commitdiff
[svn] Correctly merge DOS-like absolute directories.
authorhniksic <devnull@localhost>
Tue, 16 Apr 2002 01:36:16 +0000 (18:36 -0700)
committerhniksic <devnull@localhost>
Tue, 16 Apr 2002 01:36:16 +0000 (18:36 -0700)
Published in <sxslmbomnm7.fsf@florida.arsdigita.de>.

src/ChangeLog
src/ftp.c

index 5d733d60e2c83cc2de41eb2710f3bfc5b1018c1b..ac688ba59795d90035f8f7224ab387131765977e 100644 (file)
@@ -1,3 +1,10 @@
+2002-04-16  Hrvoje Niksic  <hniksic@arsdigita.com>
+
+       * ftp.c (getftp): Treat directories that begin with <letter>: as
+       absolute.
+       (getftp): Strip trailing slashes from con->id before merging it
+       with TARGET.
+
 2002-04-16  Hrvoje Niksic  <hniksic@arsdigita.com>
 
        * http.c (gethttp): If Content-Type is not given, assume
index 6d406222a1caf901ecc4abd026b58b79c4e9eb2b..45685329586a13d7e78c3d27547db9a9ca61db5b 100644 (file)
--- a/src/ftp.c
+++ b/src/ftp.c
@@ -383,17 +383,31 @@ Error in server response, closing control connection.\n"));
 
          /* Change working directory.  To change to a non-absolute
             Unix directory, we need to prepend initial directory
-            (con->id) to it.  Absolute directories "just work".  */
+            (con->id) to it.  Absolute directories "just work".
 
-         if (*target != '/')
+            A relative directory is one that does not begin with '/'
+            and, on non-Unix OS'es, one that doesn't begin with
+            "<letter>:".  */
+
+         if (target[0] != '/'
+             && !(con->rs != ST_UNIX
+                  && ISALPHA (target[0]) && target[1] == ':'))
            {
              int idlen = strlen (con->id);
-             char *ntarget = (char *)alloca (idlen + 1 + strlen (u->dir) + 1);
-             /* idlen == 1 means con->id = "/" */
-             sprintf (ntarget, "%s%s%s", con->id, idlen == 1 ? "" : "/",
-                      target);
+             char *ntarget, *p;
+
+             /* Strip trailing slash(es) from con->id. */
+             while (idlen > 0 && con->id[idlen - 1] == '/')
+               --idlen;
+             p = ntarget = (char *)alloca (idlen + 1 + strlen (u->dir) + 1);
+             memcpy (p, con->id, idlen);
+             p += idlen;
+             *p++ = '/';
+             strcpy (p, target);
+
               DEBUGP (("Prepended initial PWD to relative path:\n"));
-              DEBUGP (("  old: '%s'\n  new: '%s'\n", target, ntarget));
+              DEBUGP (("   pwd: '%s'\n   old: '%s'\n  new: '%s'\n",
+                      con->id, target, ntarget));
              target = ntarget;
            }