7

I know ln -s in msys2 does not work as expected. But some people report the result is a copy, while others say it is a hard link:

I would like to know if the behavior of ln -s varies in different versions of msys2. Is there a document saying ln -s will always create a copy or a hard link in future msys2 versions?

1
  • I think the poster in the first link writes "hard link" by mistake and they still meant a copy. Commented May 5, 2020 at 16:50

3 Answers 3

16

I could not find the official documentation but I just did a few tests. If you have a file named target and you run ln -s target link, the type of file that link is depends on the MSYS environment variable.

  • If MSYS is not set, then link is just a copy of stuff.
  • If MSYS is winsymlinks, it creates a Windows shortcut.
  • If MSYS is winsymlinks:nativestrict, it creates a more real type of symlink, but this seems to fail with an "Operation not permitted" error if you are not running your MSYS2 shell as administrator.

enter image description here

The MSYS2 Posix emulation comes from Cygwin, so Cygwin's documentation might be somewhat useful:

https://cygwin.com/cygwin-ug-net/using.html#pathnames-symlinks

Sign up to request clarification or add additional context in comments.

2 Comments

A good source for MSYS2: msys2.org/wiki/How-does-MSYS2-differ-from-Cygwin """Replacement of symlinks with copying, so that Windows programs don't trip up on these files. MSYS2 also supports creating native NTFS symlinks, but these are limited in other ways."""
winsymlinks:nativestrict should succeed for non-admins if "Developer Mode" is enabled in the Windows Settings app.
1

export MSYS=winsymlinks:native works for me, but nativestrict doesn't work

Comments

0

This should really be a comment to David Grayson's answer, but that would require "reputation," which I don't have (or care to get).

It is possible to use "real" symbolic links under Windows without privilege elevation, but for some strange reason, Microsoft requires administrator privileges to create symbolic links by default. To allow any user to create symbolic links without that privilege elevation, one must use the Local Group Policy Editor, i.e. type

gpedit.msc

in a command line, and then navigate to

"Create symboliclinks":
Computer Configuration ->
    Windows Settings ->
        Security Settings ->
            Local Policies ->
                User Rights Assignments ->
                    Create symbolic links <Username>

Entering the user's login name as Username. The Windows command mklink can then be used without special privileges, also cygwin (setting the CYGWIN environment variable to winsymlinks:nativestrict) and msys2 (setting the MSYS environment variable to winsymlinks:nativestrict as described by David) will then be able to handle "real" symbolic links without elevated privileges.

1 Comment

At some point Windows 10 gained a 'Developer Mode' option in the Settings app. Among other things, this enables "real" symlinks for non-admins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.