Commit 5a8eae6d authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Brad Fitzpatrick

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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent e367ba9e
......@@ -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) {
path := sfdir + "/" + sfname
file, err1 := Open(path)
......
......@@ -66,14 +66,14 @@ func Stat(name string) (FileInfo, error) {
for i := 0; i < 255; i++ {
fi, err = Lstat(name)
if err != nil {
return fi, err
return nil, err
}
if fi.Mode()&ModeSymlink == 0 {
return fi, nil
}
newname, err := Readlink(name)
if err != nil {
return fi, err
return nil, err
}
if isAbs(newname) {
name = newname
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment