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

fix: enable paths with junction inside windows #5245

Merged
merged 11 commits into from
Dec 26, 2024

Conversation

blaubaer
Copy link
Contributor

This is a workaround for the behavior of filepath.EvalSymlinks which errors with syscall.ENOTDIR if the provided path does include a Junction on Windows. Junctions can happen if a volume is mounted inside another drive as a subdirectory, for example. This can be usually happen if used with the feature Dev Drives and this replaces existing directories.

See original issue golang/go#40180. This issue is currently unresolved, and the ticket is leaning towards leaving this to the interpretation of the evaluating code rather than handling it within filepath.EvalSymlinks itself.

As syscall.ENOTDIR is only returned when calling filepath.EvalSymlinks on Windows if a part of the presented path is a Junction and nothing before was a symlink, we simply treat this as NOT symlink, because a symlink above the Junction does not make sense at all.

Copy link

boring-cyborg bot commented Dec 23, 2024

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented Dec 23, 2024

CLA assistant check
All committers have signed the CLA.

@ldez ldez added the platform: windows Issue that is related to Windows label Dec 23, 2024
@blaubaer blaubaer marked this pull request as draft December 23, 2024 13:05
@ldez ldez self-requested a review December 23, 2024 13:17
@blaubaer blaubaer marked this pull request as ready for review December 23, 2024 13:23
@blaubaer
Copy link
Contributor Author

@ldez I really tried to add tests at first. Because of the required complexity of the system requirements, like having a junction that needs to be created by the test itself and so, I tried to make the impact as simple as possible instead and tested it on my own machine instead.

@ldez ldez added feedback required Requires additional feedback and removed feedback required Requires additional feedback labels Dec 23, 2024
@ldez
Copy link
Member

ldez commented Dec 24, 2024

Have to try if winsymlink=1 + go1.23 changes the behavior?

@ldez ldez added the feedback required Requires additional feedback label Dec 24, 2024
@blaubaer
Copy link
Contributor Author

blaubaer commented Dec 24, 2024

winsymlink=0 works on go1.23, because from go1.23 on this behavior defaults to winsymlink=1 and in previous versions versions to winsymlink=0. With winsymlink=1 the actual behavior started to get problematic (see official documentation).

Potentially it might be also possible to drop godebug winsymlink=0 into the go.mod, but to have a debug statement in a product for release feels not right. :-)

@ldez
Copy link
Member

ldez commented Dec 26, 2024

Can you show me the error log you have?

This is to document the topic.

pkg/fsutils/fsutils_windows.go Outdated Show resolved Hide resolved
pkg/fsutils/fsutils_windows.go Outdated Show resolved Hide resolved
@blaubaer
Copy link
Contributor Author

blaubaer commented Dec 26, 2024

@ldez

Can you show me the error log you have?

This is to document the topic.

Sure. In this example I've mounted my Dev Drive under C:\development this means this is the Junction point. I've run golangci-lint run inside the folder C:\development\github.com\blaubaer\golangci-lint and get the following result without this PR applied:

level=warning msg="[config_reader] Can't pretty print config file path: can't get working directory: can't eval symlinks on wd C:\\development\\github.com\\blaubaer\\golangci-lint: The system cannot find the path specified."
panic: Can't get working dir: can't eval symlinks on wd C:\development\github.com\blaubaer\golangci-lint: The system cannot find the path specified.

goroutine 1 [running]:
github.com/golangci/golangci-lint/pkg/result/processors.NewPathShortener()
	C:/development/github.com/blaubaer/golangci-lint/pkg/result/processors/path_shortener.go:20 +0xa9
github.com/golangci/golangci-lint/pkg/lint.NewRunner({0x1975dc0, 0xc00111db00}, 0xc00033ac08, {0x24d44e0, 0x0, 0x0}, 0xc00125ea80, 0xc00127d380, 0xc00125eaa0, 0xc00122e280, ...)
	C:/development/github.com/blaubaer/golangci-lint/pkg/lint/runner.go:93 +0xa1c
github.com/golangci/golangci-lint/pkg/commands.(*runCommand).runAnalysis(0xc001084ea0, {0x196da70, 0xc0012b3ce0}, {0x24d44e0, 0x0, 0x0})
	C:/development/github.com/blaubaer/golangci-lint/pkg/commands/run.go:385 +0x1b2
github.com/golangci/golangci-lint/pkg/commands.(*runCommand).runAndPrint(0xc001084ea0, {0x196da70, 0xc0012b3ce0}, {0x24d44e0, 0x0, 0x0})
	C:/development/github.com/blaubaer/golangci-lint/pkg/commands/run.go:348 +0x26d
github.com/golangci/golangci-lint/pkg/commands.(*runCommand).execute(0xc001084ea0, 0xc000c13a90?, {0x24d44e0, 0x0, 0x0})
	C:/development/github.com/blaubaer/golangci-lint/pkg/commands/run.go:254 +0x1f3
github.com/spf13/cobra.(*Command).execute(0xc0010aa608, {0x24d44e0, 0x0, 0x0})
	C:/Users/gregor.noczinski/go/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0xa91
github.com/spf13/cobra.(*Command).ExecuteC(0xc0010aa008)
	C:/Users/gregor.noczinski/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x3ff
github.com/spf13/cobra.(*Command).Execute(...)
	C:/Users/gregor.noczinski/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041
github.com/golangci/golangci-lint/pkg/commands.(*rootCommand).Execute(0xc0010a3a70)
	C:/development/github.com/blaubaer/golangci-lint/pkg/commands/root.go:83 +0x3d
github.com/golangci/golangci-lint/pkg/commands.Execute({{0x1959a50, 0x8}, {0x19e444f, 0x7}, {0xc0004b0f00, 0x47}, {0x19e872f, 0x14}})
	C:/development/github.com/blaubaer/golangci-lint/pkg/commands/root.go:17 +0x5a
main.main()
	C:/development/github.com/blaubaer/golangci-lint/cmd/golangci-lint/main.go:25 +0xc5

With this PR applied:

<empty> 😉

BTW: I works also without this PR if I mount it at a dedicated drive like at drive F:. Running then inside F:\github.com\blaubaer\golangci-lint, works too, but is not desired.

@ldez ldez removed the feedback required Requires additional feedback label Dec 26, 2024
@ldez ldez added the bug Something isn't working label Dec 26, 2024
@ldez ldez added this to the next milestone Dec 26, 2024
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ldez ldez merged commit 7806463 into golangci:master Dec 26, 2024
15 checks passed
@blaubaer blaubaer deleted the windows-junctions branch December 26, 2024 22:46
@ldez ldez modified the milestones: next, v1.63 Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform: windows Issue that is related to Windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants