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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-06-20 10:01:17 +00:00
parent 381a90a597
commit 75cfeeadcf

View File

@@ -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);