took the greyhound

This commit is contained in:
Mark Bates 2019-09-01 16:27:31 -04:00
parent 6463dbba07
commit 7381a1124f
2 changed files with 30 additions and 4 deletions

View File

@ -185,16 +185,29 @@ func (s *FileSystem) Test_Stat(t *testing.T) {
for _, tt := range table {
t.Run(tt.in, func(st *testing.T) {
r := require.New(st)
pt, err := s.Parse(tt.in)
r.NoError(err)
r.NoError(s.RemoveAll(pt.String()))
if tt.err {
_, err := s.Stat(tt.in)
r.Error(err)
return
}
pt, err := s.Parse(tt.in)
isDir := filepath.Ext(pt.Name) == ""
if isDir {
r.NoError(s.MkdirAll(pt.Name, 0755))
info, err := s.Stat(tt.in)
r.NoError(err)
r.Equal(pt.Name, info.Name())
return
}
f, err := s.Create(tt.in)
r.NoError(err)

View File

@ -119,11 +119,24 @@ func (f *FS) ReadFile(s string) ([]byte, error) {
}
func (f *FS) Stat(name string) (os.FileInfo, error) {
name, err := f.Abs(name)
pt, err := f.Parse(name)
if err != nil {
return nil, err
}
return os.Stat(name)
abs, err := f.AbsPath(pt)
if err != nil {
return nil, err
}
info, err := os.Stat(abs)
if err != nil {
return nil, err
}
info = fs.WithName(pt.Name, fs.NewFileInfo(info))
return info, nil
}
func (f *FS) Walk(p string, wf filepath.WalkFunc) error {