diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-07-27 22:27:54 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-08-01 11:21:40 -0700 |
commit | f75af8c1464e948b5e166cf5ab09ebf0d82fc253 (patch) | |
tree | 3ba3299859b504bdeb477727471216bd094a0191 /libgo/go/os/file_unix.go | |
parent | 75a23e59031fe673fc3b2e60fd1fe5f4c70ecb85 (diff) | |
download | gcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.zip gcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.tar.gz gcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.tar.bz2 |
libgo: update to go1.15rc1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/245157
Diffstat (limited to 'libgo/go/os/file_unix.go')
-rw-r--r-- | libgo/go/os/file_unix.go | 75 |
1 files changed, 18 insertions, 57 deletions
diff --git a/libgo/go/os/file_unix.go b/libgo/go/os/file_unix.go index 2fc6318..aed7713 100644 --- a/libgo/go/os/file_unix.go +++ b/libgo/go/os/file_unix.go @@ -177,6 +177,15 @@ type dirInfo struct { dir *syscall.DIR // from opendir } +func (d *dirInfo) close() { + if d.dir != nil { + syscall.Entersyscall() + libc_closedir(d.dir) + syscall.Exitsyscall() + d.dir = nil + } +} + // epipecheck raises SIGPIPE if we get an EPIPE error on standard // output or standard error. See the SIGPIPE docs in os/signal, and // issue 11845. @@ -208,10 +217,8 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) { break } - // On OS X, sigaction(2) doesn't guarantee that SA_RESTART will cause - // open(2) to be restarted for regular files. This is easy to reproduce on - // fuse file systems (see https://golang.org/issue/11180). - if runtime.GOOS == "darwin" && e == syscall.EINTR { + // We have to check EINTR here, per issues 11180 and 39237. + if e == syscall.EINTR { continue } @@ -232,31 +239,13 @@ func openFileNolog(name string, flag int, perm FileMode) (*File, error) { return newFile(uintptr(r), name, kindOpenFile), nil } -// Close closes the File, rendering it unusable for I/O. -// On files that support SetDeadline, any pending I/O operations will -// be canceled and return immediately with an error. -// Close will return an error if it has already been called. -func (f *File) Close() error { - if f == nil { - return ErrInvalid - } - return f.file.close() -} - func (file *file) close() error { if file == nil { return syscall.EINVAL } var err error if file.dirinfo != nil { - syscall.Entersyscall() - i := libc_closedir(file.dirinfo.dir) - errno := syscall.GetErrno() - syscall.Exitsyscall() - file.dirinfo = nil - if i < 0 && errno != 0 { - err = &PathError{"closedir", file.name, errno} - } + file.dirinfo.close() } if e := file.pfd.Close(); e != nil { if e == poll.ErrFileClosing { @@ -270,45 +259,17 @@ func (file *file) close() error { return err } -// read reads up to len(b) bytes from the File. -// It returns the number of bytes read and an error, if any. -func (f *File) read(b []byte) (n int, err error) { - n, err = f.pfd.Read(b) - runtime.KeepAlive(f) - return n, err -} - -// pread reads len(b) bytes from the File starting at byte offset off. -// It returns the number of bytes read and the error, if any. -// EOF is signaled by a zero count with err set to nil. -func (f *File) pread(b []byte, off int64) (n int, err error) { - n, err = f.pfd.Pread(b, off) - runtime.KeepAlive(f) - return n, err -} - -// write writes len(b) bytes to the File. -// It returns the number of bytes written and an error, if any. -func (f *File) write(b []byte) (n int, err error) { - n, err = f.pfd.Write(b) - runtime.KeepAlive(f) - return n, err -} - -// pwrite writes len(b) bytes to the File starting at byte offset off. -// It returns the number of bytes written and an error, if any. -func (f *File) pwrite(b []byte, off int64) (n int, err error) { - n, err = f.pfd.Pwrite(b, off) - runtime.KeepAlive(f) - return n, err -} - // seek sets the offset for the next Read or Write on file to offset, interpreted // according to whence: 0 means relative to the origin of the file, 1 means // relative to the current offset, and 2 means relative to the end. // It returns the new offset and an error, if any. func (f *File) seek(offset int64, whence int) (ret int64, err error) { - f.seekInvalidate() + if f.dirinfo != nil { + // Free cached dirinfo, so we allocate a new one if we + // access this file as a directory again. See #35767 and #37161. + f.dirinfo.close() + f.dirinfo = nil + } ret, err = f.pfd.Seek(offset, whence) runtime.KeepAlive(f) return ret, err |