From 3bf3fe3a71ec30582d6b87b7c1b37f25be20bc05 Mon Sep 17 00:00:00 2001 From: Tatsushi Demachi Date: Sun, 31 Jan 2016 23:02:37 +0900 Subject: [PATCH] Fix CopyOnWriteFs Stat to handle *os.PathError CopyOnWriteFs Stat function only checks its base file system's file or directory when its layer file system returns Stat error but if the layer file system type is OsFs, it returns *os.PathError not syscall.ENOENT so in this case, the base file system's file or directory is never checked. This fixes the behavior above by expanding *os.PathError and repacking the error code if the error type is *os.PathError. --- copyOnWriteFs.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/copyOnWriteFs.go b/copyOnWriteFs.go index 2f8c61b..039ce53 100644 --- a/copyOnWriteFs.go +++ b/copyOnWriteFs.go @@ -75,14 +75,17 @@ func (u *CopyOnWriteFs) Chmod(name string, mode os.FileMode) error { func (u *CopyOnWriteFs) Stat(name string) (os.FileInfo, error) { fi, err := u.layer.Stat(name) - switch err { - case nil: - return fi, nil - case syscall.ENOENT: - return u.base.Stat(name) - default: - return nil, err + if err != nil { + origErr := err + if e, ok := err.(*os.PathError); ok { + err = e.Err + } + if err == syscall.ENOENT { + return u.base.Stat(name) + } + return nil, origErr } + return fi, nil } // Renaming files present only in the base layer is not permitted