Skip to content

Commit ab50e3c

Browse files
committed
Merge branch 'fixes-for-msys2'
We deviated a bit too much from MSYS2's patches, by amending them... Let's put our fixes on top, maybe the MSYS2 maintainer will be in a more collaborative and communicative mood and we might get them integrated, at long last. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 55c1cca + 48a9806 commit ab50e3c

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
@@ -1211,9 +1211,22 @@ path_conv::check (const char *src, unsigned opt,
12111211
cfree (wide_path);
12121212
wide_path = NULL;
12131213
}
1214+
1215+
if (need_directory)
1216+
{
1217+
size_t n = strlen (this->path);
1218+
/* Do not add trailing \ to UNC device names like \\.\a: */
1219+
if (this->path[n - 1] != '\\' &&
1220+
(strncmp (this->path, "\\\\.\\", 4) != 0))
1221+
{
1222+
this->modifiable_path ()[n] = '\\';
1223+
this->modifiable_path ()[n + 1] = '\0';
1224+
}
1225+
need_directory = 0;
1226+
}
12141227
}
12151228

1216-
if (need_directory)
1229+
if ((opt & PC_KEEP_FINAL_SLASH) && need_directory)
12171230
{
12181231
size_t n = strlen (this->path);
12191232
/* Do not add trailing \ to UNC device names like \\.\a: */
@@ -1223,6 +1236,7 @@ path_conv::check (const char *src, unsigned opt,
12231236
this->modifiable_path ()[n] = '\\';
12241237
this->modifiable_path ()[n + 1] = '\0';
12251238
}
1239+
need_directory = 0;
12261240
}
12271241

12281242
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)