Skip to content

Commit 7f8502b

Browse files
committed
Fix incorrect path conversion (trailing slash)
The problem with the original approach is not that it is completely bogus. After all, when you pass the option --prefix=/tmp/ to Git, you do want to end up with a trailing slash. The real problem with the original approach is that it simply changed path_conv, completely oblivious and careless about other users of path_conv. That was really wrong, of course, and cost us time, sweat and tears. The appropriate approach is to *not* affect other users, but instead introduce a flag that we use in *our* caller, so that everybody gets what they want: - emulation of inodes on FAT by calculating the hash on the normalized path: works. - MSYS2's conversion of "POSIX" paths to Windows paths: works. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7c8e2ea commit 7f8502b

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

winsup/cygwin/msys2_path_conv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ void posix_to_win32_path(const char* from, const char* to, char** dst, const cha
685685
strncpy(one_path, from, to-from);
686686
one_path[to-from] = '\0';
687687

688-
path_conv conv (one_path, 0);
688+
path_conv conv (one_path, PC_KEEP_FINAL_SLASH);
689689
if (conv.error)
690690
{
691691
set_errno(conv.error);

winsup/cygwin/path.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,22 @@ path_conv::check (const char *src, unsigned opt,
12371237
cfree (wide_path);
12381238
wide_path = NULL;
12391239
}
1240+
1241+
if (need_directory)
1242+
{
1243+
size_t n = strlen (this->path);
1244+
/* Do not add trailing \ to UNC device names like \\.\a: */
1245+
if (this->path[n - 1] != '\\' &&
1246+
(strncmp (this->path, "\\\\.\\", 4) != 0))
1247+
{
1248+
this->modifiable_path ()[n] = '\\';
1249+
this->modifiable_path ()[n + 1] = '\0';
1250+
}
1251+
need_directory = 0;
1252+
}
12401253
}
12411254

1242-
if (need_directory)
1255+
if ((opt & PC_KEEP_FINAL_SLASH) && need_directory)
12431256
{
12441257
size_t n = strlen (this->path);
12451258
/* Do not add trailing \ to UNC device names like \\.\a: */
@@ -1249,6 +1262,7 @@ path_conv::check (const char *src, unsigned opt,
12491262
this->modifiable_path ()[n] = '\\';
12501263
this->modifiable_path ()[n + 1] = '\0';
12511264
}
1265+
need_directory = 0;
12521266
}
12531267

12541268
if (opt & PC_OPEN)

winsup/cygwin/path.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ enum pathconv_arg
5858
PC_SYM_NOFOLLOW_PROCFD = _BIT (11),
5959
PC_KEEP_HANDLE = _BIT (12),
6060
PC_NO_ACCESS_CHECK = _BIT (13),
61+
PC_KEEP_FINAL_SLASH = _BIT (14),
6162
PC_DONT_USE = _BIT (31) /* conversion to signed happens. */
6263
};
6364

0 commit comments

Comments
 (0)