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: Create file issue in windows when filename contains ":"(colon) #8935

Closed
defia opened this issue Oct 14, 2014 · 4 comments
Closed

os: Create file issue in windows when filename contains ":"(colon) #8935

defia opened this issue Oct 14, 2014 · 4 comments
Milestone

Comments

@defia
Copy link

@defia defia commented Oct 14, 2014

What does 'go version' print?
go1.3.3 windows/386

What steps reproduce the problem?
If possible, include a link to a program on play.golang.org.

1.in windows
2.f,err:=os.Create("a:b.txt")
3.f.Write([]byte("123"))

What happened?
a new file named "a" created
but has no content
that's because windows do not support filename that contains ":"
also there's no error occured (err==nil)

What should have happened instead?
os.Create() should returns a error


Please provide any additional information below.
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 14, 2014

Comment 1:

Labels changed: added repo-main, release-go1.5, os-windows.

@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Oct 15, 2014

Comment 2:

I cannot reproduce your problem:
C:\go\path\src\issue8935>dir a:
The system cannot find the path specified.
C:\go\path\src\issue8935>go version
go version devel +f8a253b426f1 Thu Oct 16 09:13:50 2014 +1100 windows/386
C:\go\path\src\issue8935>type main.go
package main
import (
        "fmt"
        "log"
        "os"
)
func main() {
        f, err := os.Create("a:b.txt")
        if err != nil {
                log.Fatal(err)
        }
        defer f.Close()
        fmt.Printf("Hello\n")
}
C:\go\path\src\issue8935>go run main.go
2014/10/16 10:31:10 open a:b.txt: The system cannot find the path specified.
exit status 1
Please, provide more details for me to reproduce your problem THank you.
Alex

Status changed to WaitingForReply.

@defia
Copy link
Author

@defia defia commented Oct 16, 2014

Comment 3:

my mistake
it should be:
os.Create("ab:c")
to reproduce the issue
the length of characters before colon should be at least 2
@alexbrainman
Copy link
Member

@alexbrainman alexbrainman commented Oct 16, 2014

Comment 4:

We use CreateFile Windows API to create files. And that is what happens when you request
to create file named ab:c. The API succeeds, and you get ab file created in your current
directory:
C:\go\path\src\issue8935>dir ab
 Volume in drive C has no label.
 Volume Serial Number is XXXX-XXXX
 Directory of C:\go\path\src\issue8935
File Not Found
C:\go\path\src\issue8935>go version
go version devel +f8a253b426f1 Thu Oct 16 09:13:50 2014 +1100 windows/386
C:\go\path\src\issue8935>type main.go
package main
import (
        "fmt"
        "log"
        "os"
)
func main() {
        f, err := os.Create("ab:c")
        if err != nil {
                log.Fatal(err)
        }
        defer f.Close()
        fmt.Printf("Hello\n")
}
C:\go\path\src\issue8935>go run main.go
Hello
C:\go\path\src\issue8935>dir ab
 Volume in drive C has no label.
 Volume Serial Number is XXXX-XXXX
 Directory of C:\go\path\src\issue8935
16/10/2014  04:11 PM                 0 ab
               1 File(s)              0 bytes
               0 Dir(s)  116,078,178,304 bytes free
While I agree with you (I would expect the API to fail in this instance), I don't see
another alternative, but to go with CreateFile behaviour.
Perhaps you have better argument, but I am closing this issue for now.
Alex

Status changed to WorkingAsIntended.

@bradfitz bradfitz modified the milestone: Go1.5 Dec 16, 2014
@bradfitz bradfitz removed the release-go1.5 label Dec 16, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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
5 participants
You can’t perform that action at this time.