diff --git a/.gitignore b/.gitignore index 9115a58..6f31e5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.fstest *.log .DS_Store doc diff --git a/fs/fstest/fstest.go b/fs/fstest/fstest.go index 342d371..1898958 100644 --- a/fs/fstest/fstest.go +++ b/fs/fstest/fstest.go @@ -1,15 +1,13 @@ package fstest import ( - "path" - "github.com/markbates/pkger/fs" ) func Files(fx fs.FileSystem) (TestFiles, error) { tf := TestFiles{} for _, f := range fileList { - pt, err := Path(fx, f) + pt, err := fx.Parse(f) if err != nil { return tf, err } @@ -22,15 +20,6 @@ func Files(fx fs.FileSystem) (TestFiles, error) { return tf, nil } -func Path(fx fs.FileSystem, p string) (fs.Path, error) { - pt, err := fx.Parse(p) - if err != nil { - return pt, err - } - pt.Name = path.Join("/.fstest", pt.Name) - return pt, nil -} - var fileList = []string{ "/main.go", "/go.mod", diff --git a/fs/fstest/suite.go b/fs/fstest/suite.go index d243048..071cfbc 100644 --- a/fs/fstest/suite.go +++ b/fs/fstest/suite.go @@ -3,6 +3,7 @@ package fstest import ( "fmt" "os" + "path/filepath" "reflect" "strings" "testing" @@ -63,25 +64,26 @@ func (s *FileSystem) sub(t *testing.T, m reflect.Method) { } func (s *FileSystem) Clean() error { - pt, err := Path(s, "/") + pt, err := s.Parse("/") if err != nil { return err } - if err := s.RemoveAll(pt.Name); err != nil { - return err - } - - if _, err := s.Stat(pt.Name); err == nil { - return fmt.Errorf("expected %q to be, you know, not there any more", pt) - } + _ = pt + // if err := s.RemoveAll(pt.Name); err != nil { + // return err + // } + // + // if _, err := s.Stat(pt.Name); err == nil { + // return fmt.Errorf("expected %q to be, you know, not there any more", pt) + // } return nil } func (s *FileSystem) Test_Create(t *testing.T) { r := require.New(t) - pt, err := Path(s, "i/want/candy.song") + pt, err := s.Parse("/i/want/candy.song") r.NoError(err) f, err := s.Create(pt.Name) @@ -94,6 +96,7 @@ func (s *FileSystem) Test_Create(t *testing.T) { r.Equal(pt.Name, fi.Name()) r.Equal(os.FileMode(0644), fi.Mode()) r.NotZero(fi.ModTime()) + r.NoError(s.RemoveAll(pt.String())) } func (s *FileSystem) Test_Current(t *testing.T) { @@ -136,6 +139,7 @@ func (s *FileSystem) Test_Parse(t *testing.T) { exp fs.Path }{ {in: "/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, + {in: filepath.Join(cur.Dir, "foo.go"), exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, {in: ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, {in: ip + ":/foo.go", exp: fs.Path{Pkg: ip, Name: "/foo.go"}}, {in: ip, exp: fs.Path{Pkg: ip, Name: "/"}}, @@ -188,9 +192,7 @@ func (s *FileSystem) Test_Stat(t *testing.T) { return } - pt, err := Path(s, tt.in) - fmt.Println(">>>TODO fs/fstest/suite.go:189: tt.in ", tt.in) - fmt.Println(">>>TODO fs/fstest/suite.go:189: pt ", pt) + pt, err := s.Parse(tt.in) r.NoError(err) // r.Fail(pt.String()) diff --git a/fs/hdfs/hdfs.go b/fs/hdfs/hdfs.go index 1beaa01..e9c41f4 100644 --- a/fs/hdfs/hdfs.go +++ b/fs/hdfs/hdfs.go @@ -134,7 +134,12 @@ func (f *FS) Walk(p string, wf filepath.WalkFunc) error { } func (f *FS) locate(p string) (string, error) { - return f.current.FilePath(p), nil + pt, err := f.Parse(p) + if err != nil { + return p, err + } + p = f.current.FilePath(pt.Name) + return p, nil } func (fx *FS) Remove(name string) error { diff --git a/internal/maps/paths.go b/internal/maps/paths.go index 9f64b50..aee61f8 100644 --- a/internal/maps/paths.go +++ b/internal/maps/paths.go @@ -179,6 +179,7 @@ func (m *Paths) build(p, pkg, name string) (fs.Path, error) { if !strings.HasPrefix(pt.Name, "/") { pt.Name = "/" + pt.Name } + pt.Name = strings.TrimPrefix(pt.Name, m.Current.Dir) m.Store(p, pt) return pt, nil }