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.Open("test.txt", os.O_APPEND | os.O_CREATE, 777) recreate file every time.. #1655

Closed
gopherbot opened this issue Apr 2, 2011 · 4 comments

Comments

@gopherbot
Copy link
Contributor

by tg8866:

1 package main
  2 
  3 import (
  4     "fmt"
  5     "os"
  6 )
  7 
  8 func main() {
  9     file, err := os.Open("test.txt", os.O_APPEND | os.O_CREATE, 777)
 10     defer file.Close()
 11     if err != nil { panic(err) }
 12     n, err := file.Write([]byte("hello world\n"))
 13     if err != nil { panic(err) }
 14     fmt.Print(n)
 15 }

each time I run the exe, I don't not append string to the end ,but just recreate a file..

os: windows arch 386 go: 2011-3-7.1
@peterGo
Copy link
Contributor

peterGo commented Apr 2, 2011

Comment 1:

Apply this patch to add a test case.
diff -r 82050f8e7881 src/pkg/os/os_test.go
--- a/src/pkg/os/os_test.go Fri Apr 01 20:52:38 2011 -0400
+++ b/src/pkg/os/os_test.go Fri Apr 01 22:14:19 2011 -0400
@@ -873,6 +873,10 @@
    if s != "new|append" {
        t.Fatalf("writeFile: have %q want %q", s, "new|append")
    }
+   s = writeFile(t, f, O_CREAT|O_APPEND|O_RDWR, "|append")
+   if s != "new|append|append" {
+       t.Fatalf("writeFile: have %q want %q", s, "new|append|append")
+   }
 }
 
 func TestStatDirWithTrailingSlash(t *testing.T) {
On Windows, the test fails.
--- FAIL: os_test.TestAppend (0.00 seconds)
        writeFile: have "|append" want "new|append|append"

@alexbrainman
Copy link
Member

Comment 2:

Thank you for the report.
Alex

Labels changed: added os-windows, packagebug.

Owner changed to @alexbrainman.

Status changed to Accepted.

@peterGo
Copy link
Contributor

peterGo commented Apr 21, 2011

Comment 3:

I've attached a revised version of your patch to include Russ's test case.

Attachments:

  1. appendalex.diff (1225 bytes)

@alexbrainman
Copy link
Member

Comment 4:

This issue was closed by revision 59c18b0.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 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
Development

No branches or pull requests

3 participants