aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2019-01-29 16:34:27 -0800
committerIan Lance Taylor <iant@golang.org>2019-01-30 01:07:50 +0000
commiteb72a30f8732037596f0a1ab75c6219a40d4cf7d (patch)
treeb2b31292eb7a406af15286d1d6017c54b65577e4
parentf1d662f34788f4a5f087581d0951cdf4e0f6e708 (diff)
downloadgo-eb72a30f8732037596f0a1ab75c6219a40d4cf7d.tar.gz
go-eb72a30f8732037596f0a1ab75c6219a40d4cf7d.zip
os: make openFdAt act like openFileNolog
- add EINTR loop on Darwin - return PathError on error - call newFile rather than NewFile This tries to minimize the possibility of any future changes. It would be nice to put openFdAt in the same file as openFileNolog, but build tags forbid. Updates #29983 Change-Id: I866002416d6473fbfd80ff6ef09b2bc4607f2934 Reviewed-on: https://go-review.googlesource.com/c/160181 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
-rw-r--r--src/os/file_unix.go1
-rw-r--r--src/os/removeall_at.go31
2 files changed, 27 insertions, 5 deletions
diff --git a/src/os/file_unix.go b/src/os/file_unix.go
index 7d68a7659f..2615df9d5b 100644
--- a/src/os/file_unix.go
+++ b/src/os/file_unix.go
@@ -186,6 +186,7 @@ func epipecheck(file *File, e error) {
const DevNull = "/dev/null"
// openFileNolog is the Unix implementation of OpenFile.
+// Changes here should be reflected in openFdAt, if relevant.
func openFileNolog(name string, flag int, perm FileMode) (*File, error) {
setSticky := false
if !supportsCreateWithStickyBit && flag&O_CREATE != 0 && perm&ModeSticky != 0 {
diff --git a/src/os/removeall_at.go b/src/os/removeall_at.go
index f0fed6dc33..faee1287f1 100644
--- a/src/os/removeall_at.go
+++ b/src/os/removeall_at.go
@@ -9,6 +9,7 @@ package os
import (
"internal/syscall/unix"
"io"
+ "runtime"
"syscall"
)
@@ -128,11 +129,31 @@ func removeAllFrom(parent *File, path string) error {
return unlinkError
}
-func openFdAt(fd int, path string) (*File, error) {
- fd, err := unix.Openat(fd, path, O_RDONLY, 0)
- if err != nil {
- return nil, err
+// openFdAt opens path relative to the directory in fd.
+// Other than that this should act like openFileNolog.
+// This acts like openFileNolog rather than OpenFile because
+// we are going to (try to) remove the file.
+// The contents of this file are not relevant for test caching.
+func openFdAt(dirfd int, name string) (*File, error) {
+ var r int
+ for {
+ var e error
+ r, e = unix.Openat(dirfd, name, O_RDONLY, 0)
+ if e == nil {
+ break
+ }
+
+ // See comment in openFileNolog.
+ if runtime.GOOS == "darwin" && e == syscall.EINTR {
+ continue
+ }
+
+ return nil, &PathError{"openat", name, e}
+ }
+
+ if !supportsCloseOnExec {
+ syscall.CloseOnExec(r)
}
- return NewFile(uintptr(fd), path), nil
+ return newFile(uintptr(r), name, kindOpenFile), nil
}