Commit 46017769 authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Alex Brainman

os: fix race condition between (*os.File).Stat and os.Chdir on windows

Fixes #13752

Change-Id: I53cfc4ecae90c35b6f1074f3be08489c408a6464
Reviewed-on: https://go-review.googlesource.com/18181Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
parent 8d5ff2e1
......@@ -150,3 +150,32 @@ func TestBadNetPathError(t *testing.T) {
t.Fatal("os.IsNotExist(syscall.Errno(53)) is false, but want true")
}
}
func TestStatDir(t *testing.T) {
defer chtmpdir(t)()
f, err := os.Open(".")
if err != nil {
t.Fatal(err)
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
t.Fatal(err)
}
err = os.Chdir("..")
if err != nil {
t.Fatal(err)
}
fi2, err := f.Stat()
if err != nil {
t.Fatal(err)
}
if !os.SameFile(fi, fi2) {
t.Fatal("race condition occured")
}
}
......@@ -20,7 +20,7 @@ func (file *File) Stat() (FileInfo, error) {
}
if file.isdir() {
// I don't know any better way to do that for directory
return Stat(file.name)
return Stat(file.dirinfo.path)
}
if file.name == DevNull {
return &devNullStat, nil
......
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