Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate Symbolic/Hard link permission issues on Windows #1574

Closed
quintesse opened this issue Feb 21, 2023 · 3 comments · Fixed by #1575
Closed

Investigate Symbolic/Hard link permission issues on Windows #1574

quintesse opened this issue Feb 21, 2023 · 3 comments · Fixed by #1575
Labels
bug Something isn't working

Comments

@quintesse
Copy link
Contributor

Setting up WIndows to be able to use symbolic and hard links can be somewhat of a challenge.

We should be able to give the user straightforward instruction on what to do.
Right now our documentation is sorely lacking in that aspect.

@quintesse quintesse added the bug Something isn't working label Feb 21, 2023
@quintesse
Copy link
Contributor Author

Looking at how Scoop (https://scoop.sh) does this I see this code in their scripts:

function Get-WindowsDeveloperModeStatus {
    $DevModRegistryPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
    if (!(Test-Path -Path $DevModRegistryPath) -or (Get-ItemProperty -Path `
        $DevModRegistryPath -Name AllowDevelopmentWithoutDevLicense -ErrorAction `
        SilentlyContinue).AllowDevelopmentWithoutDevLicense -ne 1) {
        warn "Windows Developer Mode is not enabled. Operations relevant to symlinks may fail without proper rights."
        Write-Host "  You may read more about the symlinks support here:"
        Write-Host "  https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/"
        return $false
    }
}

They link to this article: https://blogs.windows.com/windowsdeveloper/2016/12/02/symlinks-windows-10/

Which explains that the creation of links without admin rights is something that was added to Windows 10, but for that you need to switch to "Developer Mode".

We could at least add a similar warning to our jbang.ps script.

@quintesse
Copy link
Contributor Author

And searching for issues with Java and sym/hard links on Windows I found this:

https://bugs.openjdk.org/browse/JDK-8218418

Which makes internal changes to Java allowing it to create sym/hard links without needing elevated privileges.
Thing is this was only added to Java 13 and later. I checked if it was backported to earlier Java versions but that doesn't seem to be the case.

@quintesse
Copy link
Contributor Author

Tested if what I found was true and it seems indeed that from Java 13 onwards there is no issue with permissions and Jbang can create Symbolic Links with no issue. Older version fail if one doesn't use the Windows Policy Editor to give specific users the rights to create Symbolic Links.

Btw, creating Hard Links was never a problem.... but on Windows you can't create Hard Links to folders!

So my idea is now to:

  1. add an extra test to jbang.ps1 to see if "Developer Mode" is turned on, and tell users what to do if it isn't
  2. add a Java version test to Util.createLink(), if Java >= 13 just do what we do now
  3. if Java < 13 we try to create the link but if it doesn't work display a message about either using Java 13+ or a link to an explanation on how to change the Policy settings.
  4. Don't try to create Hard Links to folders on Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant