From 62fa30fdd7821508b1bdee0f86698b0f8c3234e9 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Tue, 8 Nov 2022 16:24:20 +0100
Subject: [PATCH 14/N] When converting to a Unix path, avoid double trailing
 slashes

When calling `cygpath -u C:/msys64/` in an MSYS2 setup that was
installed into `C:/msys64/`, the result should be `/`, not `//`.

Let's ensure that we do not append another trailing slash if the
converted path already ends in a slash.

This fixes https://github.com/msys2/msys2-runtime/issues/112

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 winsup/cygwin/mount.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index eff9803..bd6ec2a 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -1018,6 +1018,9 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
 	nextchar = 1;
 
       int addslash = nextchar > 0 ? 1 : 0;
+      /* avoid appending a slash if the result already has a trailing slash */
+      if (append_slash && mi.posix_pathlen && mi.posix_path[mi.posix_pathlen-1] == '/')
+	append_slash = addslash = 0;
       if ((mi.posix_pathlen + (pathbuflen - mi.native_pathlen) + addslash) >= NT_MAX_PATH)
 	return ENAMETOOLONG;
       strcpy (posix_path, mi.posix_path);
