public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: symlinks: fix WSL symlink creation if cygdrive prefix is /
Date: Tue, 21 Apr 2020 09:18:18 +0000 (GMT)	[thread overview]
Message-ID: <20200421091818.EEE12384B0C1@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=6b97962073097adb7efe6ac04265df6a8596af21

commit 6b97962073097adb7efe6ac04265df6a8596af21
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Tue Apr 21 10:31:53 2020 +0200

    Cygwin: symlinks: fix WSL symlink creation if cygdrive prefix is /
    
    If the cygdrive prefix is /, then the following happens right now:
    
      $ ln -s /tmp/foo .
      $ ls -l foo
      lrwxrwxrwx 1 user group 12 Apr 15 23:44 foo -> /mnt/tmp/foo
    
    Fix this by skipping cygdrive prefix conversion to WSL drive
    prefix "/mnt", if the cygdrive prefix is just "/".  There's no
    satisfying way to do the right thing all the time in this case
    anyway.  For a description and the alternatives, see
    https://cygwin.com/pipermail/cygwin-developers/2020-April/011859.html
    
    Also, fix a typo in a comment.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/path.cc | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index f2b5cdbf1..36aa8278f 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -1886,15 +1886,17 @@ symlink_wsl (const char *oldpath, path_conv &win32_newpath)
   rpl->ReparseTag = IO_REPARSE_TAG_LX_SYMLINK;
   rpl->Reserved = 0;
   rpl->LxSymlinkReparseBuffer.FileType = 2;
-  /* Convert cygdrive prefix to "/mnt" for WSL compatibility. */
-  if (path_prefix_p (mount_table->cygdrive, oldpath,
-		     mount_table->cygdrive_len, false))
+  /* Convert cygdrive prefix to "/mnt" for WSL compatibility, but only if
+     cygdrive prefix is not "/", otherwise suffer random "/mnt" symlinks... */
+  if (mount_table->cygdrive_len > 1
+      && path_prefix_p (mount_table->cygdrive, oldpath,
+			mount_table->cygdrive_len, false))
     stpcpy (stpcpy (path_buf, "/mnt"),
 	    oldpath + mount_table->cygdrive_len - 1);
   else
     *stpncpy (path_buf, oldpath, max_pathlen) = '\0';
   /* Convert target path to UTF-16 and then back to UTF-8 to make sure the
-     WSL symlink is in UTF-8, independet of the current Cygwin codeset. */
+     WSL symlink is in UTF-8, independent of the current Cygwin codeset. */
   sys_mbstowcs (utf16, NT_MAX_PATH, path_buf);
   len = WideCharToMultiByte (CP_UTF8, 0, utf16, -1, path_buf, max_pathlen,
 			     NULL, NULL);


                 reply	other threads:[~2020-04-21  9:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200421091818.EEE12384B0C1@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).