From 75cfeeadcf709998ce671033917e395dc2d5846c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 20 Jun 2015 10:01:17 +0000 Subject: [PATCH] squash! mingw: keep trailing slashes when switching directories Actually, we should always keep the trailing slashes as both users of `normalize_ntpath()` require them: `_wchdir()` wants the slash in particular when changing the directory to a drive root, and `readlink()`'s semantics require a trailing slash for symbolic links pointing to directories. This fixes https://github.com/git-for-windows/git/issues/210 Signed-off-by: Johannes Schindelin --- compat/mingw.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/compat/mingw.c b/compat/mingw.c index 64ab1bd381b740..228e7cc8f992d7 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -316,7 +316,7 @@ static void process_phantom_symlinks(void) } /* Normalizes NT paths as returned by some low-level APIs. */ -static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes) +static wchar_t *normalize_ntpath(wchar_t *wbuf) { int i; /* fix absolute path prefixes */ @@ -337,10 +337,6 @@ static wchar_t *normalize_ntpath(wchar_t *wbuf, int strip_trailing_slashes) for (i = 0; wbuf[i]; i++) if (wbuf[i] == '\\') wbuf[i] = '/'; - /* remove potential trailing slashes */ - if (strip_trailing_slashes) - while (i && wbuf[i - 1] == '/') - wbuf[--i] = 0; return wbuf; } @@ -622,7 +618,7 @@ int mingw_chdir(const char *dirname) CloseHandle(hnd); } - result = _wchdir(normalize_ntpath(wdirname, 0)); + result = _wchdir(normalize_ntpath(wdirname)); current_directory_len = GetCurrentDirectoryW(0, NULL); return result; } @@ -2291,7 +2287,7 @@ int readlink(const char *path, char *buf, size_t bufsiz) * so convert to a (hopefully large enough) temporary buffer, then memcpy * the requested number of bytes (including '\0' for robustness). */ - if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf, 1), MAX_LONG_PATH)) < 0) + if ((len = xwcstoutf(tmpbuf, normalize_ntpath(wbuf), MAX_LONG_PATH)) < 0) return -1; memcpy(buf, tmpbuf, min(bufsiz, len + 1)); return min(bufsiz, len);