diff --git a/fs/fstest/suite.go b/fs/fstest/suite.go index e1a5793..b405ecb 100644 --- a/fs/fstest/suite.go +++ b/fs/fstest/suite.go @@ -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) - r.NoError(err) + 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) diff --git a/fs/hdfs/hdfs.go b/fs/hdfs/hdfs.go index 1bcc889..fc92489 100644 --- a/fs/hdfs/hdfs.go +++ b/fs/hdfs/hdfs.go @@ -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 {