Check for ErrNotExist in CopyOnWriteFs.Stat

Fixes #144
This commit is contained in:
Bjørn Erik Pedersen 2017-11-12 17:05:09 +01:00
parent 5660eeed30
commit 8d919cbe7e
No known key found for this signature in database
GPG Key ID: 330E6E2BD4859D8F
2 changed files with 17 additions and 1 deletions

View File

@ -80,7 +80,7 @@ func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error) {
if e, ok := err.(*os.PathError); ok { if e, ok := err.(*os.PathError); ok {
err = e.Err err = e.Err
} }
if err == syscall.ENOENT || err == syscall.ENOTDIR { if err == os.ErrNotExist || err == syscall.ENOENT || err == syscall.ENOTDIR {
return u.base.Stat(name) return u.base.Stat(name)
} }
return nil, origErr return nil, origErr

View File

@ -21,3 +21,19 @@ func TestCopyOnWrite(t *testing.T) {
} }
} }
func TestCopyOnWriteFileInMemMapBase(t *testing.T) {
base := &MemMapFs{}
layer := &MemMapFs{}
if err := WriteFile(base, "base.txt", []byte("base"), 0755); err != nil {
t.Fatalf("Failed to write file: %s", err)
}
ufs := NewCopyOnWriteFs(base, layer)
_, err := ufs.Stat("base.txt")
if err != nil {
t.Fatal(err)
}
}