Skip to content

Commit 78d4560

Browse files
fhsbradfitz
authored andcommitted
cmd/go/internal/lockedfile, os: fix O_CREATE flag on Plan 9
os.OpenFile was assuming that a failed syscall.Open means the file does not exist and it tries to create it. However, syscall.Open may have failed for some other reason, such as failing to lock a os.ModeExclusive file. We change os.OpenFile to only create the file if the error indicates that the file doesn't exist. Remove skip of TestTransform test, which was failing because sometimes syscall.Open would fail due to the file being locked, but the syscall.Create would succeed because the file is no longer locked. The create was truncating the file. Fixes #35471 Change-Id: I06583b5f8ac33dc90a51cc4fb64f2d8d9c0c2113 Reviewed-on: https://go-review.googlesource.com/c/go/+/206299 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
1 parent 29cfb4d commit 78d4560

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

src/cmd/go/internal/lockedfile/transform_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ package lockedfile_test
1010
import (
1111
"bytes"
1212
"encoding/binary"
13-
"internal/testenv"
1413
"math/rand"
1514
"path/filepath"
16-
"runtime"
1715
"testing"
1816
"time"
1917

@@ -37,10 +35,6 @@ func roundDownToPowerOf2(x int) int {
3735
}
3836

3937
func TestTransform(t *testing.T) {
40-
if runtime.GOOS == "plan9" {
41-
testenv.SkipFlaky(t, 35471)
42-
}
43-
4438
dir, remove := mustTempDir(t)
4539
defer remove()
4640
path := filepath.Join(dir, "blob.bin")

src/os/file_plan9.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
111111
fd, e = syscall.Create(name, flag, syscallMode(perm))
112112
} else {
113113
fd, e = syscall.Open(name, flag)
114-
if e != nil && create {
114+
if IsNotExist(e) && create {
115115
var e1 error
116116
fd, e1 = syscall.Create(name, flag, syscallMode(perm))
117117
if e1 == nil {

0 commit comments

Comments
 (0)