diff options
Diffstat (limited to 'libgo/go/os/file_unix.go')
-rw-r--r-- | libgo/go/os/file_unix.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/libgo/go/os/file_unix.go b/libgo/go/os/file_unix.go index 750771fa47a..2fc63188e48 100644 --- a/libgo/go/os/file_unix.go +++ b/libgo/go/os/file_unix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build aix darwin dragonfly freebsd hurd js,wasm linux nacl netbsd openbsd solaris +// +build aix darwin dragonfly freebsd hurd js,wasm linux netbsd openbsd solaris package os @@ -27,13 +27,17 @@ func rename(oldname, newname string) error { // At this point we've determined the newname is bad. // But just in case oldname is also bad, prioritize returning // the oldname error because that's what we did historically. - if _, err := Lstat(oldname); err != nil { + // However, if the old name and new name are not the same, yet + // they refer to the same file, it implies a case-only + // rename on a case-insensitive filesystem, which is ok. + if ofi, err := Lstat(oldname); err != nil { if pe, ok := err.(*PathError); ok { err = pe.Err } return &LinkError{"rename", oldname, newname, err} + } else if newname == oldname || !SameFile(fi, ofi) { + return &LinkError{"rename", oldname, newname, syscall.EEXIST} } - return &LinkError{"rename", oldname, newname, syscall.EEXIST} } err = syscall.Rename(oldname, newname) if err != nil { @@ -253,13 +257,12 @@ func (file *file) close() error { if i < 0 && errno != 0 { err = &PathError{"closedir", file.name, errno} } - } else { - if e := file.pfd.Close(); e != nil { - if e == poll.ErrFileClosing { - e = ErrClosed - } - err = &PathError{"close", file.name, e} + } + if e := file.pfd.Close(); e != nil { + if e == poll.ErrFileClosing { + e = ErrClosed } + err = &PathError{"close", file.name, e} } // no need for a finalizer anymore @@ -305,6 +308,7 @@ func (f *File) pwrite(b []byte, off int64) (n int, err error) { // 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() ret, err = f.pfd.Seek(offset, whence) runtime.KeepAlive(f) return ret, err |