Skip to content

Commit

Permalink
os: correct bad PathError message from FileOpen with O_CREATE on Plan 9
Browse files Browse the repository at this point in the history
On Plan 9, FileOpen with flag O_CREATE & ~O_TRUNC is done in two
steps.  First, syscall.Open is attempted, to avoid truncation when opening
an existing file.  If that fails because the file doesn't exist,
syscall.Create is used to create a new file.  If the Create fails,
for example because we are racing with another process to create a
ModeExclusive file, the PathError returned from FileOpen should reflect
the result of the Create, not the "does not exist" error from the initial
Open attempt.

Fixes #38540

Change-Id: I90c95a301de417ecdf79cd52748591edb1dbf528
Reviewed-on: https://go-review.googlesource.com/c/go/+/229099
Run-TryBot: David du Colombier <0intro@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David du Colombier <0intro@gmail.com>
  • Loading branch information
Richard Miller authored and 0intro committed Apr 21, 2020
1 parent 876c1fe commit 664d270
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/os/file_plan9.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,9 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
} else {
fd, e = syscall.Open(name, flag)
if IsNotExist(e) && create {
var e1 error
fd, e1 = syscall.Create(name, flag, syscallMode(perm))
if e1 == nil {
e = nil
fd, e = syscall.Create(name, flag, syscallMode(perm))
if e != nil {
return nil, &PathError{"create", name, e}
}
}
}
Expand Down

0 comments on commit 664d270

Please sign in to comment.