From ad60f22743183e807d70f2a28125f739e442987c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B8=CC=86=20=D0=9F?=
 =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=BE=D0=B2?= <alexey.pawlow@gmail.com>
Date: Sun, 14 Apr 2019 22:13:51 +0300
Subject: [PATCH 10/N] Special case for converting root directory to have
 training slash

---
 winsup/cygwin/path.cc | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 70c9793..a9bf8ec 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -703,6 +703,12 @@ path_conv::check (const char *src, unsigned opt,
 	      need_directory = 1;
 	      *--tail = '\0';
 	    }
+	  /* Special case for "/" must set need_directory, without removing
+	     trailing slash */
+	  else if (tail == path_copy + 1 && isslash (tail[-1]))
+	    {
+	      need_directory = 1;
+	    }
 	  path_end = tail;
 
 	  /* Scan path_copy from right to left looking either for a symlink
@@ -1225,16 +1231,17 @@ path_conv::check (const char *src, unsigned opt,
 		cfree (wide_path);
 	      wide_path = NULL;
 	    }
-	  if (need_directory)
+	}
+
+      if (need_directory)
+	{
+	  size_t n = strlen (this->path);
+	  /* Do not add trailing \ to UNC device names like \\.\a: */
+	  if (this->path[n - 1] != '\\' &&
+	      (strncmp (this->path, "\\\\.\\", 4) != 0))
 	    {
-	      size_t n = strlen (this->path);
-	      /* Do not add trailing \ to UNC device names like \\.\a: */
-	      if (this->path[n - 1] != '\\' &&
-		  (strncmp (this->path, "\\\\.\\", 4) != 0))
-		{
-		  this->modifiable_path ()[n] = '\\';
-		  this->modifiable_path ()[n + 1] = '\0';
-		}
+	      this->modifiable_path ()[n] = '\\';
+	      this->modifiable_path ()[n + 1] = '\0';
 	    }
 	}
 
-- 
2.31.1

