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>
This commit is contained in:
parent
5951b3e600
commit
6b97962073
|
@ -1886,15 +1886,17 @@ symlink_wsl (const char *oldpath, path_conv &win32_newpath)
|
||||||
rpl->ReparseTag = IO_REPARSE_TAG_LX_SYMLINK;
|
rpl->ReparseTag = IO_REPARSE_TAG_LX_SYMLINK;
|
||||||
rpl->Reserved = 0;
|
rpl->Reserved = 0;
|
||||||
rpl->LxSymlinkReparseBuffer.FileType = 2;
|
rpl->LxSymlinkReparseBuffer.FileType = 2;
|
||||||
/* Convert cygdrive prefix to "/mnt" for WSL compatibility. */
|
/* Convert cygdrive prefix to "/mnt" for WSL compatibility, but only if
|
||||||
if (path_prefix_p (mount_table->cygdrive, oldpath,
|
cygdrive prefix is not "/", otherwise suffer random "/mnt" symlinks... */
|
||||||
mount_table->cygdrive_len, false))
|
if (mount_table->cygdrive_len > 1
|
||||||
|
&& path_prefix_p (mount_table->cygdrive, oldpath,
|
||||||
|
mount_table->cygdrive_len, false))
|
||||||
stpcpy (stpcpy (path_buf, "/mnt"),
|
stpcpy (stpcpy (path_buf, "/mnt"),
|
||||||
oldpath + mount_table->cygdrive_len - 1);
|
oldpath + mount_table->cygdrive_len - 1);
|
||||||
else
|
else
|
||||||
*stpncpy (path_buf, oldpath, max_pathlen) = '\0';
|
*stpncpy (path_buf, oldpath, max_pathlen) = '\0';
|
||||||
/* Convert target path to UTF-16 and then back to UTF-8 to make sure the
|
/* 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);
|
sys_mbstowcs (utf16, NT_MAX_PATH, path_buf);
|
||||||
len = WideCharToMultiByte (CP_UTF8, 0, utf16, -1, path_buf, max_pathlen,
|
len = WideCharToMultiByte (CP_UTF8, 0, utf16, -1, path_buf, max_pathlen,
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
|
|
Loading…
Reference in New Issue