Skip to content

Instantly share code, notes, and snippets.

@karlding
Created March 24, 2018 04:39
Show Gist options
  • Save karlding/7868aac0c54fe94b7ba0a2061e0a4939 to your computer and use it in GitHub Desktop.
Save karlding/7868aac0c54fe94b7ba0a2061e0a4939 to your computer and use it in GitHub Desktop.
making cygwin use native symlinks
@oglueck
Copy link

oglueck commented Jan 30, 2020

Beware though that directory symlinks to symlinks do NOT work correctly:
mkdir adir
ln -s adir 1
ln -s 1 2
Now 2 is a .symlink file and not a native symlink! Even nativestrict does NOT fail here. You get silent corruption.

@mattblovell
Copy link

mattblovell commented Jun 11, 2020

Now 2 is a .symlink file and not a native symlink! Even nativestrict does NOT fail here. You get silent corruption.

Perhaps there is something I'm not observing, but your example seems like it works fine:

mlovell@COL-U513277L001:~/test
% export CYGWIN=winsymlinks:nativestrict

mlovell@COL-U513277L001:~/test
% mkdir adir

mlovell@COL-U513277L001:~/test
% ln -s adir 1

mlovell@COL-U513277L001:~/test
% ln -s 1 2

mlovell@COL-U513277L001:~/test
% ll
total 0
lrwxrwxrwx  1 mlovell Domain Users 4 Jun 11 13:09 1 -> adir
lrwxrwxrwx  1 mlovell Domain Users 1 Jun 11 13:09 2 -> 1
drwxr-xr-x+ 1 mlovell Domain Users 0 Jun 11 13:09 adir

mlovell@COL-U513277L001:~/test
% touch adir/test_file

mlovell@COL-U513277L001:~/test
% ll 2
lrwxrwxrwx 1 mlovell Domain Users 1 Jun 11 13:09 2 -> 1
mlovell@COL-U513277L001:~/test
% cd 2

mlovell@COL-U513277L001:~/test/2
% ll
total 0
-rw-r--r-- 1 mlovell Domain Users 0 Jun 11 13:09 test_file

Could you clarify what's broken?

EDIT: Just wanted to clarify that the above commands were run in a cygwin shell with administrator privileges. Trying the nativestrict setting in a non-privileged shell just gets one an error:

ln: failed to create symbolic link '1': Operation not permitted

@oglueck
Copy link

oglueck commented Jun 14, 2020

Creating symbolic links is a privileged operation in Windows (sic!). That means you need to give that permission to the user. If the user has admin rights, then you need to run "as administrator". To add the permission to a unprivileged user:
Start the "Local Security Policy" app (Run "secpol.msc")
Under Security Settings/Local Policies/User Rights Assignment, select "Create symbolic links"
Right-click: Properties
Add Users or Group
enter the usernames, then click "Check Names"
OK

@oglueck
Copy link

oglueck commented Jun 14, 2020

You can only observe the problem in Windows Filesystem. Within Cygwin all works fine.
Look at the screenshot of Windows Explorer.

@Slach
Copy link

Slach commented Sep 19, 2020

one advanced options to allow mklink and ln -sf works on windows 10 home + UAC
described here
https://www.joshkel.com/2018/01/18/symlinks-in-windows/

Enable developer mode: Go under Settings, under Update & Security, under For developers, and set “Use developer features” to “Developer mode.” This is how you enable the Windows 10 Creators Update option of allowing users to create symlinks without UAC elevation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment