mirror of
https://github.com/golang/go
synced 2024-11-23 22:20:02 -07:00
os: adjust error in Stat on windows
Current code could return a non-nil os.FileInfo even if there is an error. This is a bit incompatible with Stat on other OSes. Change-Id: I37b608da234f957bb89b82509649de78ccc70bbb Reviewed-on: https://go-review.googlesource.com/40330 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
e367ba9eae
commit
5a8eae6d47
@ -174,6 +174,45 @@ func TestStat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStatError(t *testing.T) {
|
||||||
|
defer chtmpdir(t)()
|
||||||
|
|
||||||
|
path := "no-such-file"
|
||||||
|
Remove(path) // Just in case
|
||||||
|
|
||||||
|
fi, err := Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("got nil, want error")
|
||||||
|
}
|
||||||
|
if fi != nil {
|
||||||
|
t.Errorf("got %v, want nil", fi)
|
||||||
|
}
|
||||||
|
if perr, ok := err.(*PathError); !ok {
|
||||||
|
t.Errorf("got %T, want %T", err, perr)
|
||||||
|
}
|
||||||
|
|
||||||
|
testenv.MustHaveSymlink(t)
|
||||||
|
|
||||||
|
link := "symlink"
|
||||||
|
Remove(link) // Just in case
|
||||||
|
err = Symlink(path, link)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer Remove(link)
|
||||||
|
|
||||||
|
fi, err = Stat(link)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("got nil, want error")
|
||||||
|
}
|
||||||
|
if fi != nil {
|
||||||
|
t.Errorf("got %v, want nil", fi)
|
||||||
|
}
|
||||||
|
if perr, ok := err.(*PathError); !ok {
|
||||||
|
t.Errorf("got %T, want %T", err, perr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestFstat(t *testing.T) {
|
func TestFstat(t *testing.T) {
|
||||||
path := sfdir + "/" + sfname
|
path := sfdir + "/" + sfname
|
||||||
file, err1 := Open(path)
|
file, err1 := Open(path)
|
||||||
|
@ -66,14 +66,14 @@ func Stat(name string) (FileInfo, error) {
|
|||||||
for i := 0; i < 255; i++ {
|
for i := 0; i < 255; i++ {
|
||||||
fi, err = Lstat(name)
|
fi, err = Lstat(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fi, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if fi.Mode()&ModeSymlink == 0 {
|
if fi.Mode()&ModeSymlink == 0 {
|
||||||
return fi, nil
|
return fi, nil
|
||||||
}
|
}
|
||||||
newname, err := Readlink(name)
|
newname, err := Readlink(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fi, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if isAbs(newname) {
|
if isAbs(newname) {
|
||||||
name = newname
|
name = newname
|
||||||
|
Loading…
Reference in New Issue
Block a user