Skip to content

Commit 1bfa869

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 1907824 commit 1bfa869

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
@@ -624,7 +624,7 @@ void posix_to_win32_path(const char* from, const char* to, char** dst, const cha
624624
strncpy(one_path, from, to-from);
625625
one_path[to-from] = '\0';
626626

627-
path_conv conv (one_path, 0);
627+
path_conv conv (one_path, PC_KEEP_FINAL_SLASH);
628628
if (conv.error)
629629
{
630630
set_errno(conv.error);

winsup/cygwin/path.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,22 @@ path_conv::check (const char *src, unsigned opt,
12541254
cfree (wide_path);
12551255
wide_path = NULL;
12561256
}
1257+
1258+
if (need_directory)
1259+
{
1260+
size_t n = strlen (this->path);
1261+
/* Do not add trailing \ to UNC device names like \\.\a: */
1262+
if (this->path[n - 1] != '\\' &&
1263+
(strncmp (this->path, "\\\\.\\", 4) != 0))
1264+
{
1265+
this->modifiable_path ()[n] = '\\';
1266+
this->modifiable_path ()[n + 1] = '\0';
1267+
}
1268+
need_directory = 0;
1269+
}
12571270
}
12581271

1259-
if (need_directory)
1272+
if ((opt & PC_KEEP_FINAL_SLASH) && need_directory)
12601273
{
12611274
size_t n = strlen (this->path);
12621275
/* Do not add trailing \ to UNC device names like \\.\a: */
@@ -1266,6 +1279,7 @@ path_conv::check (const char *src, unsigned opt,
12661279
this->modifiable_path ()[n] = '\\';
12671280
this->modifiable_path ()[n + 1] = '\0';
12681281
}
1282+
need_directory = 0;
12691283
}
12701284

12711285
if (opt & PC_OPEN)

winsup/cygwin/path.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum pathconv_arg
5959
PC_KEEP_HANDLE = _BIT (12), /* keep handle for later stat calls */
6060
PC_NO_ACCESS_CHECK = _BIT (13), /* helper flag for error check */
6161
PC_SYM_NOFOLLOW_DIR = _BIT (14), /* don't follow a trailing slash */
62+
PC_KEEP_FINAL_SLASH = _BIT (15), /* do not remove a trailing slash */
6263
PC_DONT_USE = _BIT (31) /* conversion to signed happens. */
6364
};
6465

0 commit comments

Comments
 (0)