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
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-Windows
Milestone

Comments

@djdv
Copy link
Contributor

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 andybons added OS-Windows NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 21, 2018
@andybons andybons added this to the Go1.11 milestone Mar 21, 2018
@andybons
Copy link
Member

@alexbrainman

@gopherbot
Copy link

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

@alexbrainman
Copy link
Member

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

@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.
Labels
FrozenDueToAge 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

4 participants