go: os: MkdirAll returns error with 'NUL' on Windows
What version of Go are you using (go version)?
go1.10 windows/amd64, go version devel +b63b0f2b75 Tue Mar 27 08:16:50 2018 +0000 windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env)?
GOOS=windows GOARCH=amd64
What did you do?
Tried to use os.MkdirAll on “NUL”: os.MkdirAll("NUL", 0777)
What did you expect to see?
no error returned, as is the case with: os.Mkdir("NUL", 0777).
What did you see instead?
An os.PathError: The system cannot find the path specified.
Additional
Similar to https://github.com/golang/go/issues/24482
https://golang.org/src/os/path.go?s=705:716#L24
Is the problem area, since NUL is not considered a directory, MkDirAll returns a PathError.
In the Windows command interpreter md NUL and md intermediate\paths\NUL create no paths and return no errors.
However md NUL\path\beyond will return an error.
Attn: @alexbrainman
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 23 (22 by maintainers)
Commits related to this issue
- os: return an error when the argument of Mkdir on Windows is os.DevNull Test added. Fixes #24556 Change-Id: I4d1cd4513142edeea1a983fbfde46c2fccecab2a Reviewed-on: https://go-review.googlesource.com... — committed to tomocy/go by iwdgo 5 years ago
- os: return an error when the argument of Mkdir on Windows is os.DevNull Test added. Fixes #24556 Change-Id: I4d1cd4513142edeea1a983fbfde46c2fccecab2a Reviewed-on: https://go-review.googlesource.com... — committed to t4n6a1ka/go by iwdgo 5 years ago
It is not the
Windows command interpreter, it is Windows CreateDirectory API returns success.https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createdirectoryw
I built this little test
and it outputs this on Linux
and this on Windows
Err:0x3 is ERROR_PATH_NOT_FOUND. Perhaps os.Mkdir(os.DevNull) should also return ERROR_PATH_NOT_FOUND. ERROR_PATH_NOT_FOUND is even mentioned in https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-createdirectoryw
I do not see downsides of changing os.Mkdir(os.DevNull) to return ERROR_PATH_NOT_FOUND.
I will do this change unless others object.
Alex