-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: enable paths with junction inside windows #5245
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b857efd
Add junctions workaround.
blaubaer 6ba695e
Merge branch 'master' into windows-junctions
blaubaer 5ba1af5
Apply suggestion
blaubaer b8c5ffa
Merge branch 'master' into windows-junctions
blaubaer 39204c7
Apply suggestion
blaubaer dfa826f
Apply suggestion
blaubaer 03b658f
review: decrease cyclomatic complexity
ldez 5cc16fd
review
ldez 0b6f2ce
review: simplification
ldez 4f52a4c
Merge branch 'master' into windows-junctions
blaubaer effed5d
review
ldez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !windows | ||
|
||
package fsutils | ||
|
||
import "path/filepath" | ||
|
||
func evalSymlinks(path string) (string, error) { | ||
return filepath.EvalSymlinks(path) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//go:build windows | ||
|
||
package fsutils | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
func evalSymlinks(path string) (string, error) { | ||
resolved, err := filepath.EvalSymlinks(path) | ||
if err != nil { | ||
// This is a workaround for the behavior of filepath.EvalSymlinks, which fails with | ||
// syscall.ENOTDIR if the specified path contains a junction on Windows. Junctions | ||
// can occur, for example, when a volume is mounted as a subdirectory inside another | ||
// drive. This can usually happen when using the Dev Drives feature and replacing | ||
// existing directories. See: https://github.com/golang/go/issues/40180 | ||
// | ||
// Since syscall.ENOTDIR is only returned when calling filepath.EvalSymlinks on | ||
// Windows if part of the presented path is a junction and nothing before was a | ||
// symlink, we simply treat this as NOT symlink, because a symlink over the junction | ||
// makes no sense at all. | ||
if err == syscall.ENOTDIR { | ||
if _, sErr := os.Stat(path); sErr == nil { | ||
// If exists, we make the path absolute, to be sure... | ||
if abs, aErr := filepath.Abs(path); aErr == nil { | ||
return abs, nil | ||
} | ||
} | ||
} | ||
return "", err | ||
} | ||
return resolved, nil | ||
} | ||
blaubaer marked this conversation as resolved.
Show resolved
Hide resolved
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.