From 8d919cbe7e2627e417f3e45c3c0e489a5b7e2536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 12 Nov 2017 17:05:09 +0100 Subject: [PATCH] Check for ErrNotExist in CopyOnWriteFs.Stat Fixes #144 --- copyOnWriteFs.go | 2 +- copyOnWriteFs_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/copyOnWriteFs.go b/copyOnWriteFs.go index ed692ae..f2ebcd2 100644 --- a/copyOnWriteFs.go +++ b/copyOnWriteFs.go @@ -80,7 +80,7 @@ func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error) { if e, ok := err.(*os.PathError); ok { 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 nil, origErr diff --git a/copyOnWriteFs_test.go b/copyOnWriteFs_test.go index 2a00fab..c6f2c6d 100644 --- a/copyOnWriteFs_test.go +++ b/copyOnWriteFs_test.go @@ -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) + } +}