-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: OpenFile creates incorrect file name on Windows #61408
Comments
@golang/windows |
Could you share a code sample that we can use to reproduce this issue? Thanks. |
I'm able to reproduce it using package main
import (
"log"
"os"
)
func main() {
f, err := os.OpenFile("C:/aa:393.txt", os.O_RDWR|os.O_CREATE, 0755)
if err != nil {
log.Fatal(err)
}
defer f.Close()
} From the win docs:
Weirdly enough trying any of the other reserved characters result in a proper error:
I'll try to work on a fix. |
Seems like python also allows a .\python.exe -c "open('C:/aa:393.txt', 'w').close()" # ok, results in a file named "aa"
.\python.exe -c "open('C:/aa?393.txt', 'w').close()" # bad
Traceback (most recent call last):
File "<string>", line 1, in <module>
OSError: [Errno 22] Invalid argument: 'H:/aa?393.txt' |
This kind of sounds like a Windows bug to me. Why does Windows not return an error if it can't create the file? |
It appears |
I think you are right @seankhliao, aparently that is a thing. tdil |
Why would you use Alex |
@seankhliao I think we can close this issue. The problem seems to be the use of |
windows os.OpenFile bug: if open path like this:X:/aa:393.txt the create filename will be "aa"
it should panic.
1.20.5
The text was updated successfully, but these errors were encountered: