diff --git a/fs.go b/fs.go index a9efccd..d0f7fc8 100644 --- a/fs.go +++ b/fs.go @@ -200,3 +200,12 @@ func CapabilityCheck(fs Basic, capabilities Capability) bool { fsCaps := Capabilities(fs) return fsCaps&capabilities == capabilities } + +// Stat returns the os.FileInfo structure describing file. +func Stat(f File) (os.FileInfo, error) { + fi, ok := f.(interface{ Stat() (os.FileInfo, error) }) + if !ok { + return nil, ErrNotSupported + } + return fi.Stat() +} diff --git a/helper/chroot/chroot.go b/helper/chroot/chroot.go index 8b44e78..8321914 100644 --- a/helper/chroot/chroot.go +++ b/helper/chroot/chroot.go @@ -222,6 +222,15 @@ func (fs *ChrootHelper) Capabilities() billy.Capability { return billy.Capabilities(fs.underlying) } +type fileInfo struct { + os.FileInfo + name string +} + +func (fi *fileInfo) Name() string { + return fi.name +} + type file struct { billy.File name string @@ -240,3 +249,12 @@ func newFile(fs billy.Filesystem, f billy.File, filename string) billy.File { func (f *file) Name() string { return f.name } + +func (f *file) Stat() (os.FileInfo, error) { + fi, err := billy.Stat(f.File) + if err != nil { + return fi, err + } + name := f.Name() + return &fileInfo{fi, name}, nil +}