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: Stat returns error with 'nul' on Windows #24482

Closed
djdv opened this issue Mar 21, 2018 · 3 comments
Closed

os: Stat returns error with 'nul' on Windows #24482

djdv opened this issue Mar 21, 2018 · 3 comments

Comments

@djdv
Copy link

@djdv djdv commented Mar 21, 2018

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

go version go1.10 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.Stat on "nul": os.Stat("nul")

What did you expect to see?

A valid FileInfo with no error, as is the case with: os.Stat("NUL").

What did you see instead?

An os.PathError error.

Additional

Other os operations, such as os.Create, succeed with either "nul" or "NUL".
Windows will discard any data written to any variation of the filename "NUL", not just uppercase.
os/stat_windows.go checks against OS.DevNull which is a constant "NUL".

if name == DevNull {
		return &devNullStat, nil
}

Something like this (with or without the short-circuit) would resolve this.

if len(name) == len(DevNul) && strings.ToUpper(name) == DevNull {
		return &devNullStat, nil
}

However, I don't know if introducing the strings dependency into the Windows os pkg is reasonable.
If it is I can submit a PR for this. The only other thing I can think of is duplicating the functionality of ToUpper into /os/internal/ to handle this.

@andybons

This comment has been minimized.

Copy link
Member

@andybons andybons commented Mar 21, 2018

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Mar 25, 2018

Change https://golang.org/cl/102457 mentions this issue: os: treat "nul" as DevNull file on windows

@alexbrainman

This comment has been minimized.

Copy link
Member

@alexbrainman alexbrainman commented Mar 25, 2018

I agree, we should make os.Stat work with "nul".

However, I don't know if introducing the strings dependency into the Windows os pkg is reasonable.
If it is I can submit a PR for this. The only other thing I can think of is duplicating the functionality of ToUpper into /os/internal/ to handle this.

We can just write small new function that we need. See https://go-review.googlesource.com/#/c/go/+/102457

Alex

@djdv djdv mentioned this issue Mar 25, 2018
7 of 9 tasks complete
@gopherbot gopherbot closed this in 48c4eee Mar 25, 2018
@golang golang locked and limited conversation to collaborators Mar 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.