From 7953158bced6a48f08c5f49800c4c99c9fb5c4b2 Mon Sep 17 00:00:00 2001 From: hniksic Date: Mon, 15 Apr 2002 18:36:16 -0700 Subject: [PATCH] [svn] Correctly merge DOS-like absolute directories. Published in . --- src/ChangeLog | 7 +++++++ src/ftp.c | 28 +++++++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 5d733d60..ac688ba5 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2002-04-16 Hrvoje Niksic + + * ftp.c (getftp): Treat directories that begin with : as + absolute. + (getftp): Strip trailing slashes from con->id before merging it + with TARGET. + 2002-04-16 Hrvoje Niksic * http.c (gethttp): If Content-Type is not given, assume diff --git a/src/ftp.c b/src/ftp.c index 6d406222..45685329 100644 --- 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 + ":". */ + + 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; } -- 2.39.2