Skip to content

path/filepath: EvalSymlinks doesn't work for Windows long filenames #40966

Closed
@sethkoehler

Description

@sethkoehler

What version of Go are you using (go version)?

$ go version
go version go1.15 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=                                                                                                  
set GOARCH=amd64                                                                                                  
set GOBIN=                                                                                                        
set GOCACHE=C:\Users\sethkoehler\AppData\Local\go-build                                                           
set GOENV=C:\Users\sethkoehler\AppData\Roaming\go\env                                                             
set GOEXE=.exe                                                                                                    
set GOFLAGS=                                                                                                      
set GOHOSTARCH=amd64                                                                                              
set GOHOSTOS=windows                                                                                              
set GOINSECURE=                                                                                                   
set GOMODCACHE=C:\Users\sethkoehler\go\pkg\mod                                                                    
set GONOPROXY=                                                                                                    
set GONOSUMDB=                                                                                                    
set GOOS=windows                                                                                                  
set GOPATH=C:\Users\sethkoehler\go                                                                                
set GOPRIVATE=                                                                                                    
set GOPROXY=https://proxy.golang.org,direct                                                                       
set GOROOT=c:\go                                                                                                  
set GOSUMDB=sum.golang.org                                                                                        
set GOTMPDIR=                                                                                                     
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64                                                                        
set GCCGO=gccgo                                                                                                   
set AR=ar                                                                                                         
set CC=gcc                                                                                                        
set CXX=g++                                                                                                       
set CGO_ENABLED=1                                                                                                 
set GOMOD=                                                                                                        
set CGO_CFLAGS=-g -O2                                                                                             
set CGO_CPPFLAGS=                                                                                                 
set CGO_CXXFLAGS=-g -O2                                                                                           
set CGO_FFLAGS=-g -O2                                                                                             
set CGO_LDFLAGS=-g -O2                                                                                            
set PKG_CONFIG=pkg-config                                                                                         
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\SETHKO~1\AppData\Local\Temp\go-build584735666=/tmp/go-build -gno-record-gcc-switches

What did you do?

Ran filepath.EvalSymlinks on filename of the form C:\abc...\abc.txt where this filepath was ~300 chars (anything over 259 should work). Did this with and without the \\?\ prefix.

What did you expect to see?

The symlink resolved (which does happen with os.Readlink).

What did you see instead?

"The system cannot find the path specified."

Reproducer

I believe the issue is simply that toNorm needs to implicitly add a \\?\ prefix to a long path (>= 260 chars including drive letter).

I've attached a standalone file where I copied the relevant parts of the filepath library (you can just run it as a standard go test). Notice that on lines 48-64, where we do what EvalSymlinks does internally for Windows, that walkSymlinks does not keep the \\?\ portion on the filename, even if a path is passed in with this prefix (which makes that workaround useless for EvalSymlinks :( ).

Also notice that the separated walkSymlinks and toNorm calls part of the test passes (but then the subsequent call to EvalSymlinks does not), because I add the \\?\ prefix back when calling toNorm (so it can handle long paths just fine it appears if using the prefix).

Note that the only relevant parts of this file are up to line 90 (the rest is standard library copied from Go): evalsymlinks_test.go.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windows

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions