-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Open
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.OS-Windows
Milestone
Description
Windows makes a distinction between symlinks to a file and to a directory. A file link pointing to a directory cannot be traversed, nor can a directory link pointing to a file.
filepath.EvalSymlinks doesn't pay any attention to the type of links, however, and will resolve links that Windows will not. It probably should behave consistently with the rest of the OS.
Possible testcases (currently failing):
func TestWindowsEvalSymlinksDirectoryLinkToFile(t *testing.T) {
dir := tempDirCanonical(t)
if err := os.WriteFile(dir+"/target", nil, 0666); err != nil {
t.Fatal(err)
}
mustExec(t, "cmd", "/c", "mklink", "/D", dir+`\symlink`, dir+`\target`)
if _, err := filepath.EvalSymlinks(dir + `\symlink`); err == nil {
t.Errorf("EvalSymlinks(symlink) succeeded; want error (directory link to file target)")
}
if _, err := os.ReadFile(dir + `\symlink`); err == nil {
t.Errorf("ReadFile(symlink) succeeded; want error (directory link to file target)")
}
}
func TestWindowsEvalSymlinksFileLinkToDirectory(t *testing.T) {
dir := tempDirCanonical(t)
if err := os.Mkdir(dir+"/target", 0777); err != nil {
t.Fatal(err)
}
mustExec(t, "cmd", "/c", "mklink", dir+`\symlink`, dir+`\target`)
if _, err := filepath.EvalSymlinks(dir + `\symlink`); err == nil {
t.Errorf("EvalSymlinks(filelink) succeeded; want error (file link to directory target)")
}
if _, err := os.ReadDir(dir + `\symlink`); err == nil {
t.Errorf("ReadDir(symlink) succeeded; want error (file link to directory target)")
}
}
func mustExec(t *testing.T, cmd string, args ...string) {
output, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
t.Fatalf("command failed: %q\n%v", cmd, string(output))
}
}Metadata
Metadata
Assignees
Labels
BugReportIssues describing a possible bug in the Go implementation.Issues describing a possible bug in the Go implementation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.OS-Windows