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

Symlink creation can fail on Windows #338

Open
3 tasks
balintf opened this issue Oct 25, 2022 · 0 comments
Open
3 tasks

Symlink creation can fail on Windows #338

balintf opened this issue Oct 25, 2022 · 0 comments

Comments

@balintf
Copy link

balintf commented Oct 25, 2022

Symlink creation on Windows is a realtively obscure feature and was limited to privileged processes (Run As Administrator) until a few years ago. Creating unpriviliged symlinks is supported since Windows 10 (1703, v10.0.14972), but only if the user also has Developer Mode enabled.

When the user runs go test -v without the required privileges the following error is displayed:

PS C:\work\open\mob> go test -run TestGitRootDirWithSymbolicLink -v
=== RUN   TestGitRootDirWithSymbolicLink
    mob_test.go:1621: Creating testbed in temporary directory C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001
    mob_test.go:1621:   git --bare init
    mob_test.go:1621:   git symbolic-ref HEAD refs/heads/master
    mob_test.go:1621:   git config receive.advertisePushOptions true
    mob_test.go:1621:   git clone --origin origin file://C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/remote .
    mob_test.go:1621:   git config --local user.name local
    mob_test.go:1621:   git config --local user.email local@example.com
    mob_test.go:1621:   git checkout -b master
    mob_test.go:1621:   git add .
    mob_test.go:1621:   git commit -m "initial import"
    mob_test.go:1621:   git push --set-upstream --all origin
    mob_test.go:1621:   git clone --origin origin file://C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/remote .
    mob_test.go:1621:   git config --local user.name localother
    mob_test.go:1621:   git config --local user.email localother@example.com
    mob_test.go:1621:   git clone --origin origin file://C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/remote .
    mob_test.go:1621:   git config --local user.name alice
    mob_test.go:1621:   git config --local user.email alice@example.com
    mob_test.go:1621:   git clone --origin origin file://C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/remote .
    mob_test.go:1621:   git config --local user.name bob
    mob_test.go:1621:   git config --local user.email bob@example.com
    mob_test.go:1621:   git clone --origin origin file://C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/remote .
    mob_test.go:1621:   git config --local user.name local-symlink
    mob_test.go:1621:   git config --local user.email local-symlink@example.com
    mob_test.go:1621: ERROR Could not create smylink from C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/local-symlink.git to C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/local-symlink/.git
    mob_test.go:1621: ERROR symlink C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001\local-symlink.git C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001\local-symlink\.git: A required privilege is not held by the client.
    mob_test.go:1621:
        ===== cd C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/local
    mob_test.go:1621: 
        ===== cd C:\Users\BALINT~1.FAR\AppData\Local\Temp\TestGitRootDirWithSymbolicLink2285704395\001/local-symlink
    mob_test.go:1621: ERROR expecting the current working directory to be a git repository.
exit status 1
FAIL    github.com/remotemobprogramming/mob/v4  4.586s

To fix this I propose the following steps:

  • Add a note in the README.md and/or CONTRIBUTING.md for Windows 10 users to enable Developer Mode
  • Detect the symlink creation failure and display a more helpful error message about turning on Developer Mode or running tests from an elevated console
  • Add a detection mechanism for symlink creation, and skip tests that require symlinks (currently only TestGitRootDirWithSymbolicLink if I'm correct). This would make the second step unnecessary.

The go internal/testenv package already has a method for detecting symlink creation on Windows https://pkg.go.dev/internal/testenv#MustHaveSymlink, we should create something similar for an elegant way of handling this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant