mirror of
https://github.com/golang/go
synced 2024-10-04 15:09:59 +00:00
os: convert poll.ErrFileClosed to ErrClosed for Stat
Fixes #66665 Change-Id: I3e3b7433d245daa997d7d502c2ef8978af6664fb Reviewed-on: https://go-review.googlesource.com/c/go/+/576119 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
885fdfc082
commit
968e1ce1e4
|
@ -5,6 +5,7 @@
|
|||
package os_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"internal/testenv"
|
||||
"io/fs"
|
||||
"os"
|
||||
|
@ -337,3 +338,26 @@ func TestStatConsole(t *testing.T) {
|
|||
testStatAndLstat(t, `\\.\`+name, params)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClosedStat(t *testing.T) {
|
||||
// Historically we do not seem to match ErrClosed on non-Unix systems.
|
||||
switch runtime.GOOS {
|
||||
case "windows", "plan9":
|
||||
t.Skipf("skipping on %s", runtime.GOOS)
|
||||
}
|
||||
|
||||
t.Parallel()
|
||||
f, err := os.Open("testdata/hello")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := f.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, err = f.Stat()
|
||||
if err == nil {
|
||||
t.Error("Stat succeeded on closed File")
|
||||
} else if !errors.Is(err, os.ErrClosed) {
|
||||
t.Errorf("error from Stat on closed file did not match ErrClosed: %q, type %T", err, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func (f *File) Stat() (FileInfo, error) {
|
|||
var fs fileStat
|
||||
err := f.pfd.Fstat(&fs.sys)
|
||||
if err != nil {
|
||||
return nil, &PathError{Op: "stat", Path: f.name, Err: err}
|
||||
return nil, f.wrapErr("stat", err)
|
||||
}
|
||||
fillFileStatFromSys(&fs, f.name)
|
||||
return &fs, nil
|
||||
|
|
Loading…
Reference in a new issue