Skip to content

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

Closed
@djdv

Description

@djdv

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.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions