Cyker
Cyker

Reputation: 10964

Symlink in msys2: Copy or hard link?

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?

Upvotes: 4

Views: 3643

Answers (3)

neversetsun
neversetsun

Reputation: 31

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

Upvotes: 1

user147058
user147058

Reputation: 11

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.

Upvotes: 0

David Grayson
David Grayson

Reputation: 87486

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

Upvotes: 12

Related Questions