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

os: Windows: MkdirAll fails with valid path that starts with \\? (e.g. \\?\D:\test) #22230

Closed
sandreas opened this issue Oct 12, 2017 · 5 comments
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@sandreas
Copy link

sandreas commented Oct 12, 2017

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

1.9

Does this issue reproduce with the latest release?

yes

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\xxx\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
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

What did you do?

precondition: Directory D:\test does not exist

dir := "\\\\?\\D:\\test"
err = os.MkdirAll(dir, 0777) // results in error
err = os.Mkdir(dir, 0777) // works

https://play.golang.org/p/Z2ONpbvDyV

What did you expect to see?

os.Mkdir and os.MkdirAll will create the directory

What did you see instead?

os.MkdirAll fails with an error

@sandreas sandreas changed the title Windows: Mkdirall fails with valid path that starts with \\? (e.g. \\?\D:\test) Windows: os.MkdirAll fails with valid path that starts with \\? (e.g. \\?\D:\test) Oct 12, 2017
@ianlancetaylor ianlancetaylor changed the title Windows: os.MkdirAll fails with valid path that starts with \\? (e.g. \\?\D:\test) os: Windows: MkdirAll fails with valid path that starts with \\? (e.g. \\?\D:\test) Oct 12, 2017
@ianlancetaylor ianlancetaylor added help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows labels Oct 12, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Oct 12, 2017
@ianlancetaylor
Copy link
Contributor

CC @alexbrainman

@alexbrainman
Copy link
Member

Mkdir just calls correspondent Windows API, so it succeeds with whatever path it is given. But MkdirAll recursively calls itself for its parameters parent directory. It finds parent directory by looking for path delimiter in the file path and taking whatever is on the left. When file path is \\?\D:\test, it obviously finds empty path at the end. We could fix MkdirAll by removing \\?\ prefix on Windows. But I suspect MkdirAll is also broken for network shares, like \\server\share\a\b\c. Do we want to fix \\?\ (it will be easy), or do we want to fix both?

I also noticed that path/filepath does not handle \\?\ at all. Do we want to try and fix that? It is bit confusing some code works with \\?\ and some don't. Should we say we support long paths everywhere and will try and fix whatever breaks?

Alex

@ncw
Copy link
Contributor

ncw commented Oct 20, 2017

An rclone user has noticed this in rclone/rclone#1754

However it seemed to work for me in Windows 7 so maybe this is a specific Windows 10 problem?

@alexbrainman
Copy link
Member

However it seemed to work for me in Windows 7 so maybe this is a specific Windows 10 problem?

I replied on rclone/rclone#1754 . Perhaps that answers your question.

Alex

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Unplanned Dec 6, 2017
@gopherbot
Copy link

Change https://golang.org/cl/86295 mentions this issue: os: Windows: MkdirAll should work with extended-length form path

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Projects
None yet
Development

No branches or pull requests

5 participants