From d62a369af8b39fcf91bb88ac94dbeb54d81f7c92 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 9 Mar 2019 16:15:51 +0000 Subject: [PATCH] PSCP, PSFTP: don't duplicate slashes in dir_file_cat. Now if a pathname ends with a slash already, we detect that (using the shiny new ptrlen_endswith), and don't bother putting another one in. No functional change, but this should improve the occasional error message, e.g. 'pscp remote:some.filename /' will now say it can't create /some.filename instead of //some.filename. --- unix/uxsftp.c | 5 ++++- windows/winsftp.c | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/unix/uxsftp.c b/unix/uxsftp.c index 0afd2a13..1c48e0d5 100644 --- a/unix/uxsftp.c +++ b/unix/uxsftp.c @@ -436,7 +436,10 @@ bool create_directory(const char *name) char *dir_file_cat(const char *dir, const char *file) { - return dupcat(dir, "/", file, NULL); + ptrlen dir_pl = ptrlen_from_asciz(dir); + return dupcat( + dir, ptrlen_endswith(dir_pl, PTRLEN_LITERAL("/"), NULL) ? "" : "/", + file, NULL); } /* diff --git a/windows/winsftp.c b/windows/winsftp.c index 45d38d57..adea38c8 100644 --- a/windows/winsftp.c +++ b/windows/winsftp.c @@ -451,7 +451,11 @@ bool create_directory(const char *name) char *dir_file_cat(const char *dir, const char *file) { - return dupcat(dir, "\\", file, NULL); + ptrlen dir_pl = ptrlen_from_asciz(dir); + return dupcat( + dir, (ptrlen_endswith(dir_pl, PTRLEN_LITERAL("\\"), NULL) || + ptrlen_endswith(dir_pl, PTRLEN_LITERAL("/"), NULL)) ? "" : "\\", + file, NULL); } /* ----------------------------------------------------------------------