diff --git a/.vscode/settings.json b/.vscode/settings.json index b031fd5..f0483af 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -79,6 +79,7 @@ "Mutables", "nakedret", "navi", + "nefilim", "nicksnyder", "nolint", "nolintlint", diff --git a/director-resume_test.go b/director-resume_test.go index f34278b..a47fdba 100644 --- a/director-resume_test.go +++ b/director-resume_test.go @@ -11,13 +11,13 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/cycle" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -70,7 +70,7 @@ var _ = Describe("Director(Resume)", Ordered, func() { Using: tv.Using{ Subscription: tv.SubscribeFiles, Handler: noOpHandler, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return emptyFS }, }, diff --git a/director.go b/director.go index 267cfbe..531488a 100644 --- a/director.go +++ b/director.go @@ -1,6 +1,7 @@ package tv import ( + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/internal/feat/filter" "github.com/snivilised/traverse/internal/feat/hiber" "github.com/snivilised/traverse/internal/feat/nanny" @@ -10,7 +11,6 @@ import ( "github.com/snivilised/traverse/internal/opts" "github.com/snivilised/traverse/internal/third/lo" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -78,17 +78,17 @@ func features(o *pref.Options, using *pref.Using, mediator types.Mediator, func Prime(using *pref.Using, settings ...pref.Option) *Builders { return &Builders{ using: using, - traverseFS: pref.CreateTraverseFS(func(root string) lfs.TraverseFS { + traverseFS: pref.CreateTraverseFS(func(root string) nef.TraverseFS { if using.GetTraverseFS != nil { return using.GetTraverseFS(root) } - return lfs.NewTraverseFS(lfs.At{ + return nef.NewTraverseFS(nef.At{ Root: root, Overwrite: noOverwrite, }) }), - extent: extension(func(tsys lfs.TraverseFS) extent { + extent: extension(func(tsys nef.TraverseFS) extent { return &primeExtent{ baseExtent: baseExtent{ fileSys: fileSystems{ @@ -129,17 +129,17 @@ func Prime(using *pref.Using, settings ...pref.Option) *Builders { func Resume(was *Was, settings ...pref.Option) *Builders { return &Builders{ using: &was.Using, - traverseFS: pref.CreateTraverseFS(func(root string) lfs.TraverseFS { + traverseFS: pref.CreateTraverseFS(func(root string) nef.TraverseFS { if was.Using.GetTraverseFS != nil { return was.Using.GetTraverseFS(root) } - return lfs.NewTraverseFS(lfs.At{ + return nef.NewTraverseFS(nef.At{ Root: root, Overwrite: noOverwrite, }) }), - extent: extension(func(tsys lfs.TraverseFS) extent { + extent: extension(func(tsys nef.TraverseFS) extent { return &resumeExtent{ baseExtent: baseExtent{ fileSys: fileSystems{ diff --git a/extent.go b/extent.go index 12ba91f..d633f73 100644 --- a/extent.go +++ b/extent.go @@ -1,11 +1,11 @@ package tv import ( + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/internal/feat/resume" "github.com/snivilised/traverse/internal/kernel" "github.com/snivilised/traverse/internal/opts" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -14,19 +14,19 @@ type extent interface { was() *pref.Was plugin(*kernel.Artefacts) types.Plugin options(...pref.Option) (*pref.Options, *opts.Binder, error) - traverseFS() lfs.TraverseFS + traverseFS() nef.TraverseFS complete() bool } type fileSystems struct { - tsys lfs.TraverseFS + tsys nef.TraverseFS } type baseExtent struct { fileSys fileSystems } -func (ex *baseExtent) traverseFS() lfs.TraverseFS { +func (ex *baseExtent) traverseFS() nef.TraverseFS { return ex.fileSys.tsys } diff --git a/go.mod b/go.mod index 8272df5..db43eb0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23.0 require ( github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 - golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa + golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c ) require ( @@ -18,10 +18,11 @@ require ( github.com/pkg/errors v0.9.1 github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/snivilised/li18ngo v0.1.4 + github.com/snivilised/nefilim v0.1.1 github.com/snivilised/pants v0.1.2 - golang.org/x/net v0.28.0 // indirect - golang.org/x/sys v0.24.0 // indirect + golang.org/x/net v0.30.0 // indirect + golang.org/x/sys v0.26.0 // indirect golang.org/x/text v0.19.0 // indirect - golang.org/x/tools v0.24.0 // indirect + golang.org/x/tools v0.26.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 2d59e0e..d49ec0f 100644 --- a/go.sum +++ b/go.sum @@ -30,20 +30,22 @@ github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/snivilised/li18ngo v0.1.4 h1:y6EECoVFpmkud2yDEeBnMnebPmSvdrEZ/LAq1PoPctE= github.com/snivilised/li18ngo v0.1.4/go.mod h1:Or3qUhpR6AM1X51i82RtyCvORWy2/hrxY9lg1i1gFTE= +github.com/snivilised/nefilim v0.1.1 h1:uMhLSfj5prGr2bahwzSM50rpd22fiiv0ZDLSzxYWsgg= +github.com/snivilised/nefilim v0.1.1/go.mod h1:+4/hKxgfvE8eNjLMJC+3ropEZSQuiR/NqfPtIuw7ZMw= github.com/snivilised/pants v0.1.2 h1:6Abj02gV5rFYyKfCsmeEiOi1pLdRyITKUY5oDoRgYuU= github.com/snivilised/pants v0.1.2/go.mod h1:BOZa24yLxVjjnTCFWQeCzUWL8eK4TLtXtkz3pMdEFQM= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI= -golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c h1:7dEasQXItcW1xKJ2+gg5VOiBnqWrJc+rq0DPKyvvdbY= +golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c/go.mod h1:NQtJDoLvd6faHhE7m4T/1IY708gDefGGjR/iUW8yQQ8= +golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= +golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= -golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= +golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ= +golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0= google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal-traverse-defs.go b/internal-traverse-defs.go index 4d62e17..5c02a1d 100644 --- a/internal-traverse-defs.go +++ b/internal-traverse-defs.go @@ -3,9 +3,9 @@ package tv import ( "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/internal/opts" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -57,12 +57,12 @@ func (fn filesystem) build(path string) fs.FS { } type extentBuilder interface { - build(tsys lfs.TraverseFS) extent + build(tsys nef.TraverseFS) extent } -type extension func(tsys lfs.TraverseFS) extent +type extension func(tsys nef.TraverseFS) extent -func (fn extension) build(tsys lfs.TraverseFS) extent { +func (fn extension) build(tsys nef.TraverseFS) extent { return fn(tsys) } diff --git a/internal/feat/filter/scheme-sampler.go b/internal/feat/filter/scheme-sampler.go index 1df4e34..86d0b67 100644 --- a/internal/feat/filter/scheme-sampler.go +++ b/internal/feat/filter/scheme-sampler.go @@ -3,12 +3,12 @@ package filter import ( "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/filtering" "github.com/snivilised/traverse/internal/third/lo" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" ) type samplerScheme struct { @@ -43,7 +43,7 @@ func (s *samplerScheme) next(node *core.Node, ) (bool, error) { if node.Extension.Scope.IsRoot() { matching := s.filter.Matching( - []fs.DirEntry{lfs.FromFileInfo(node.Info)}, + []fs.DirEntry{nef.FromFileInfo(node.Info)}, ) result := len(matching) > 0 diff --git a/internal/feat/hiber/hibernate_test.go b/internal/feat/hiber/hibernate_test.go index f4960ff..b7534d8 100644 --- a/internal/feat/hiber/hibernate_test.go +++ b/internal/feat/hiber/hibernate_test.go @@ -10,13 +10,13 @@ import ( "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" ) var _ = Describe("feature", Ordered, func() { @@ -57,7 +57,7 @@ var _ = Describe("feature", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -151,7 +151,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: client, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/feat/hiber/with-filter_test.go b/internal/feat/hiber/with-filter_test.go index 982b1ec..0072c3e 100644 --- a/internal/feat/hiber/with-filter_test.go +++ b/internal/feat/hiber/with-filter_test.go @@ -9,13 +9,13 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -50,7 +50,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: entry.Callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/feat/sampling/controller.go b/internal/feat/sampling/controller.go index 71efffb..f1d4e3f 100644 --- a/internal/feat/sampling/controller.go +++ b/internal/feat/sampling/controller.go @@ -3,11 +3,11 @@ package sampling import ( "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/third/lo" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -27,7 +27,7 @@ func (p *controller) Next(_ *core.Node, _ types.Inspection) (bool, error) { func (p *controller) sample(result []fs.DirEntry, _ error, _ fs.ReadDirFS, _ string, ) ([]fs.DirEntry, error) { - files, folders := lfs.Separate(result) + files, folders := nef.Separate(result) return union(&readResult{ files: files, diff --git a/internal/feat/sampling/navigator-sample_test.go b/internal/feat/sampling/navigator-sample_test.go index 9e7b906..ff4ceeb 100644 --- a/internal/feat/sampling/navigator-sample_test.go +++ b/internal/feat/sampling/navigator-sample_test.go @@ -8,13 +8,13 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -56,7 +56,7 @@ var _ = Describe("feature", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -124,7 +124,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-custom_test.go b/internal/filtering/filter-custom_test.go index 76bc335..6008bb3 100644 --- a/internal/filtering/filter-custom_test.go +++ b/internal/filtering/filter-custom_test.go @@ -8,13 +8,13 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -74,7 +74,7 @@ var _ = Describe("NavigatorFilterCustom", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-extended-glob_test.go b/internal/filtering/filter-extended-glob_test.go index 64b92d3..56f8f9f 100644 --- a/internal/filtering/filter-extended-glob_test.go +++ b/internal/filtering/filter-extended-glob_test.go @@ -8,13 +8,13 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -63,7 +63,7 @@ var _ = Describe("filtering", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -135,7 +135,7 @@ var _ = Describe("filtering", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-glob_test.go b/internal/filtering/filter-glob_test.go index a8b6af8..c160152 100644 --- a/internal/filtering/filter-glob_test.go +++ b/internal/filtering/filter-glob_test.go @@ -9,13 +9,13 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -64,7 +64,7 @@ var _ = Describe("NavigatorFilterGlob", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -136,7 +136,7 @@ var _ = Describe("NavigatorFilterGlob", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-hybrid_test.go b/internal/filtering/filter-hybrid_test.go index 7c8b7da..62a4872 100644 --- a/internal/filtering/filter-hybrid_test.go +++ b/internal/filtering/filter-hybrid_test.go @@ -9,12 +9,12 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -85,7 +85,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-poly_test.go b/internal/filtering/filter-poly_test.go index e943813..afa1d1f 100644 --- a/internal/filtering/filter-poly_test.go +++ b/internal/filtering/filter-poly_test.go @@ -9,13 +9,13 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -76,7 +76,7 @@ var _ = Describe("feature", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -147,7 +147,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/filter-regex_test.go b/internal/filtering/filter-regex_test.go index c06e7b5..372c61c 100644 --- a/internal/filtering/filter-regex_test.go +++ b/internal/filtering/filter-regex_test.go @@ -8,13 +8,13 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -64,7 +64,7 @@ var _ = Describe("feature", Ordered, func() { ) return nil }, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, @@ -136,7 +136,7 @@ var _ = Describe("feature", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/filtering/sample.go b/internal/filtering/sample.go index c2b2815..af0fe35 100644 --- a/internal/filtering/sample.go +++ b/internal/filtering/sample.go @@ -3,10 +3,10 @@ package filtering import ( "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -80,12 +80,12 @@ func NewSample(def *core.SampleFilterDef, } func (f *Sample) files(entries []fs.DirEntry) (wanted, others []fs.DirEntry) { - wanted, others = lfs.Separate(entries) + wanted, others = nef.Separate(entries) return wanted, others } func (f *Sample) folders(entries []fs.DirEntry) (wanted, others []fs.DirEntry) { - others, wanted = lfs.Separate(entries) + others, wanted = nef.Separate(entries) return wanted, others } diff --git a/internal/kernel/contents.go b/internal/kernel/contents.go index 6d7bfcc..3cdbf4e 100644 --- a/internal/kernel/contents.go +++ b/internal/kernel/contents.go @@ -3,10 +3,10 @@ package kernel import ( "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" "github.com/snivilised/traverse/tapable" ) @@ -20,7 +20,7 @@ func newContents(behaviour *pref.SortBehaviour, hook: hook, } - contents.files, contents.folders = lfs.Separate(entries) + contents.files, contents.folders = nef.Separate(entries) return &contents } diff --git a/internal/kernel/navigator-folders-with-files_test.go b/internal/kernel/navigator-folders-with-files_test.go index 4298940..98e6d80 100644 --- a/internal/kernel/navigator-folders-with-files_test.go +++ b/internal/kernel/navigator-folders-with-files_test.go @@ -9,11 +9,11 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" ) @@ -62,7 +62,7 @@ var _ = Describe("NavigatorFoldersWithFiles", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: once, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/kernel/navigator-simple_test.go b/internal/kernel/navigator-simple_test.go index f2e1c33..648d206 100644 --- a/internal/kernel/navigator-simple_test.go +++ b/internal/kernel/navigator-simple_test.go @@ -9,12 +9,12 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/services" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" ) @@ -72,7 +72,7 @@ var _ = Describe("NavigatorUniversal", Ordered, func() { Root: path, Subscription: entry.Subscription, Handler: callback, - GetTraverseFS: func(_ string) lfs.TraverseFS { + GetTraverseFS: func(_ string) nef.TraverseFS { return FS }, }, diff --git a/internal/laboratory/directory-tree-builder.go b/internal/laboratory/directory-tree-builder.go index 8950070..8bd01cb 100644 --- a/internal/laboratory/directory-tree-builder.go +++ b/internal/laboratory/directory-tree-builder.go @@ -10,9 +10,9 @@ import ( "strings" "testing/fstest" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/collections" "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/lfs" ) const ( @@ -57,7 +57,7 @@ func Provision(provider *IOProvider, verbose bool, portions ...string) (root str func ensure(root string, provider *IOProvider, verbose bool) error { repo := Repo("") index := Path(repo, "test/data/musico-index.xml") - parent, _ := lfs.SplitParent(root) + parent, _ := nef.SplitParent(root) builder := directoryTreeBuilder{ root: TrimRoot(root), stack: collections.NewStackWith([]string{parent}), diff --git a/internal/persist/convert-json_test.go b/internal/persist/convert-json_test.go index 353f755..7df0528 100644 --- a/internal/persist/convert-json_test.go +++ b/internal/persist/convert-json_test.go @@ -7,16 +7,16 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/opts" "github.com/snivilised/traverse/internal/persist" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) var _ = Describe("Convert Options via JSON", Ordered, func() { var ( - FS lfs.TraverseFS + FS nef.TraverseFS ) BeforeAll(func() { diff --git a/internal/persist/marshaler-filters_test.go b/internal/persist/marshaler-filters_test.go index 370d4de..73a12d4 100644 --- a/internal/persist/marshaler-filters_test.go +++ b/internal/persist/marshaler-filters_test.go @@ -9,12 +9,12 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/opts/json" "github.com/snivilised/traverse/internal/persist" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -135,7 +135,7 @@ func createJSONSampleFilterDefFromCoreWithPoly(def *core.SampleFilterDef, var _ = Describe("Marshaler", Ordered, func() { var ( - FS lfs.TraverseFS + FS nef.TraverseFS readPath string // ๐Ÿ‘ NODE: diff --git a/internal/persist/marshaler-local-fs_test.go b/internal/persist/marshaler-local-fs_test.go index 35e0dd7..a9ef713 100644 --- a/internal/persist/marshaler-local-fs_test.go +++ b/internal/persist/marshaler-local-fs_test.go @@ -7,12 +7,12 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/opts" "github.com/snivilised/traverse/internal/persist" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -49,7 +49,7 @@ var _ = Describe("Marshaler", Ordered, func() { ) Expect(err).To(Succeed()) - writerFS := lfs.NewWriteFileFS(lfs.At{ + writerFS := nef.NewWriteFileFS(nef.At{ Root: testPath, Overwrite: NoOverwrite, }) @@ -86,7 +86,7 @@ var _ = Describe("Marshaler", Ordered, func() { Depth: 3, }) */ - // readerFS := lfs.NewReadFileFS("/some-path") + // readerFS := nef.NewReadFileFS("/some-path") // state, err := persist.Unmarshal(&types.RestoreState{ // Path: "some-restore-path", // Resume: enums.ResumeStrategySpawn, diff --git a/internal/persist/marshaler.go b/internal/persist/marshaler.go index b8dbb0c..58f5bb9 100644 --- a/internal/persist/marshaler.go +++ b/internal/persist/marshaler.go @@ -4,9 +4,9 @@ import ( ejson "encoding/json" "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/internal/opts/json" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -24,7 +24,7 @@ type ( Active *types.ActiveState Path string Perm fs.FileMode - FS lfs.WriteFileFS + FS nef.WriteFileFS } MarshalResult struct { diff --git a/internal/persist/marshaler_test.go b/internal/persist/marshaler_test.go index 5f8e58a..9d05401 100644 --- a/internal/persist/marshaler_test.go +++ b/internal/persist/marshaler_test.go @@ -10,6 +10,7 @@ import ( . "github.com/onsi/gomega" //nolint:revive // ok "github.com/snivilised/li18ngo" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" lab "github.com/snivilised/traverse/internal/laboratory" @@ -18,7 +19,6 @@ import ( "github.com/snivilised/traverse/internal/persist" "github.com/snivilised/traverse/internal/third/lo" "github.com/snivilised/traverse/internal/types" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" "github.com/snivilised/traverse/pref" ) @@ -38,7 +38,7 @@ func check[T any](entry *checkerTE, err error) error { } } -func marshal(entry *marshalTE, tfs lfs.TraverseFS) *tampered { +func marshal(entry *marshalTE, tfs nef.TraverseFS) *tampered { // success: o, _, err := opts.Get( pref.IfOptionF(entry.option != nil, func() pref.Option { @@ -86,7 +86,7 @@ func marshal(entry *marshalTE, tfs lfs.TraverseFS) *tampered { } } -func unmarshal(entry *marshalTE, tfs lfs.TraverseFS, restorePath string, t *tampered) { +func unmarshal(entry *marshalTE, tfs nef.TraverseFS, restorePath string, t *tampered) { // success: request := &persist.UnmarshalRequest{ Restore: &types.RestoreState{ @@ -124,7 +124,7 @@ func createJSONSamplingOptions(so *pref.SamplingOptions) *json.SamplingOptions { var _ = Describe("Marshaler", Ordered, func() { var ( - FS lfs.TraverseFS + FS nef.TraverseFS sourceNodeFilterDef *core.FilterDef jsonNodeFilterDef json.FilterDef diff --git a/internal/types/definitions.go b/internal/types/definitions.go index 8532b80..f54d60e 100644 --- a/internal/types/definitions.go +++ b/internal/types/definitions.go @@ -4,12 +4,12 @@ import ( "context" "io/fs" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/cycle" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/measure" "github.com/snivilised/traverse/internal/opts" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -66,7 +66,7 @@ type ( // Resources are dependencies required for navigation Resources struct { - FS lfs.FileSystems + FS nef.FileSystems Supervisor *measure.Supervisor Binder *opts.Binder } @@ -130,7 +130,7 @@ type ( // RestoreState RestoreState struct { Path string - FS lfs.ReadFileFS + FS nef.ReadFileFS Resume enums.ResumeStrategy } ) diff --git a/lfs/ensure-path-at.go b/lfs/ensure-path-at.go deleted file mode 100644 index 5235f7d..0000000 --- a/lfs/ensure-path-at.go +++ /dev/null @@ -1,48 +0,0 @@ -package lfs - -import ( - "os" - "path/filepath" - "strings" -) - -// EnsurePathAt ensures that the specified path exists (including any non -// existing intermediate directories). Given a path and a default filename, -// the specified path is created in the following manner: -// - If the path denotes a file (path does not end is a directory separator), then -// the parent folder is created if it doesn't exist on the file-system provided. -// - If the path denotes a directory, then that directory is created. -// -// The returned string represents the file, so if the path specified was a -// directory path, then the defaultFilename provided is joined to the path -// and returned, otherwise the original path is returned un-modified. -// Note: filepath.Join does not preserve a trailing separator, therefore to make sure -// a path is interpreted as a directory and not a file, then the separator has -// to be appended manually onto the end of the path. -// If vfs is not provided, then the path is ensured directly on the native file -// system. - -func EnsurePathAt(path, defaultFilename string, perm os.FileMode, - fS ...MakeDirFS, -) (at string, err error) { - var ( - directory, file string - ) - - if strings.HasSuffix(path, string(os.PathSeparator)) { - directory = path - file = defaultFilename - } else { - directory, file = filepath.Split(path) - } - - if len(fS) > 0 { - if !fS[0].DirectoryExists(directory) { - err = fS[0].MakeDirAll(directory, perm) - } - } else { - err = os.MkdirAll(directory, perm) - } - - return filepath.Clean(filepath.Join(directory, file)), err -} diff --git a/lfs/ensure-path-at_test.go b/lfs/ensure-path-at_test.go deleted file mode 100644 index 08a1228..0000000 --- a/lfs/ensure-path-at_test.go +++ /dev/null @@ -1,91 +0,0 @@ -package lfs_test - -import ( - "errors" - "fmt" - "os" - "path/filepath" - "testing/fstest" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" - "github.com/snivilised/traverse/locale" -) - -var _ = Describe("EnsurePathAt", Ordered, func() { - var ( - mocks *lfs.ResolveMocks - fS *makeDirMapFS - ) - - BeforeAll(func() { - Expect(li18ngo.Use( - func(o *li18ngo.UseOptions) { - o.From.Sources = li18ngo.TranslationFiles{ - locale.SourceID: li18ngo.TranslationSource{Name: "traverse"}, - } - }, - )).To(Succeed()) - }) - - BeforeEach(func() { - mocks = &lfs.ResolveMocks{ - HomeFunc: func() (string, error) { - return filepath.Join(string(filepath.Separator), "home", "prodigy"), nil - }, - AbsFunc: func(_ string) (string, error) { - return "", errors.New("not required for these tests") - }, - } - - fS = &makeDirMapFS{ - mapFS: fstest.MapFS{ - filepath.Join("home", "prodigy"): &fstest.MapFile{ - Mode: os.ModeDir, - }, - }, - } - }) - - DescribeTable("with mapFS", - func(entry *ensureTE) { - home, _ := mocks.HomeFunc() - location := lab.TrimRoot(filepath.Join(home, entry.relative)) - - if entry.directory { - location += string(filepath.Separator) - } - - actual, err := lfs.EnsurePathAt(location, "default-test.log", lab.Perms.File, fS) - directory, _ := filepath.Split(actual) - directory = filepath.Clean(directory) - expected := lab.TrimRoot(lab.Path(home, entry.expected)) - - Expect(err).Error().To(BeNil()) - Expect(actual).To(Equal(expected)) - Expect(AsDirectory(lab.TrimRoot(directory))).To(ExistInFS(fS)) - }, - func(entry *ensureTE) string { - return fmt.Sprintf("๐Ÿงช ===> given: '%v', should: '%v'", entry.given, entry.should) - }, - - Entry(nil, &ensureTE{ - given: "path is file", - should: "create parent directory and return specified file path", - relative: filepath.Join("logs", "test.log"), - expected: "logs/test.log", - }), - - Entry(nil, &ensureTE{ - given: "path is directory", - should: "create parent directory and return default file path", - relative: "logs/", - directory: true, - expected: "logs/default-test.log", - }), - ) -}) diff --git a/lfs/file-systems.go b/lfs/file-systems.go deleted file mode 100644 index 32dbb89..0000000 --- a/lfs/file-systems.go +++ /dev/null @@ -1,505 +0,0 @@ -package lfs - -import ( - "fmt" - "io/fs" - "os" - "path/filepath" - - "github.com/snivilised/traverse/locale" -) - -// ๐Ÿ”ฅ An important note about using standard golang file systems (io.fs/fs.FS) -// as opposed to using the native os calls directly (os.XXX). -// Note that (io.fs/fs.FS) represents a virtual file system where as os.XXX -// represent operations on the local file system. Working with either of -// these is fundamentally different to working with the other; bear this in -// mind to avoid confusion. -// -// virtual file system -// =================== -// -// The client is expected to create a file system rooted at a particular path. -// This path must be absolute. Any function call on the resulting file system -// that requires a path must be relative to this root and therefore must not -// begin or end with a slash. -// -// When composing paths to use with a file system, one might think that using -// filepath.Separator and building paths with filepath.Join is the most -// prudent thing to do to ensure correct functioning on different platforms. When -// it comes to file systems, this is most certainly not the case. The paths -// are virtual and they are mapped into an underlying file system, which typically -// is the local file system. This means that paths used only need to use '/'. And -// the silly thing is, characters like ':', or '\' for windows should not be -// treated as separators by the underlying file system. So really using -// filepath.Separator with a virtual file system is not valid. -// - -func sanitise(root string) string { - return root -} - -// ๐Ÿงฉ ---> open - -// ๐ŸŽฏ openFS -type openFS struct { - fS fs.FS - root string -} - -func (f *openFS) Open(name string) (fs.File, error) { - return f.fS.Open(name) -} - -// ๐Ÿงฉ ---> stat - -// ๐ŸŽฏ statFS -type statFS struct { - *openFS -} - -func NewStatFS(at At) fs.StatFS { - ents := compose(sanitise(at.Root)) - return &ents.stat -} - -func (f *statFS) Stat(name string) (fs.FileInfo, error) { - return os.Stat(filepath.Join(f.root, name)) -} - -// ๐Ÿงฉ ---> file system query - -// ๐ŸŽฏ readDirFS -type readDirFS struct { - *openFS -} - -// NewReadDirFS creates a file system with read directory capability -func NewReadDirFS(at At) fs.ReadDirFS { - ents := compose(sanitise(at.Root)) - - return &ents.exists -} - -// Open opens the named file. -// -// When Open returns an error, it should be of type *PathError -// with the Op field set to "open", the Path field set to name, -// and the Err field describing the problem. -// -// Open should reject attempts to open names that do not satisfy -// ValidPath(name), returning a *PathError with Err set to -// ErrInvalid or ErrNotExist. -func (n *readDirFS) Open(name string) (fs.File, error) { - return n.fS.Open(name) -} - -// ReadDir reads the named directory -// and returns a list of directory entries sorted by filename. -// -// If fs implements [ReadDirFS], ReadDir calls fs.ReadDir. -// Otherwise ReadDir calls fs.Open and uses ReadDir and Close -// on the returned file. -func (n *readDirFS) ReadDir(name string) ([]fs.DirEntry, error) { - return fs.ReadDir(n.fS, name) -} - -// ๐ŸŽฏ queryStatusFS -type queryStatusFS struct { - *statFS - *readDirFS -} - -func (q *queryStatusFS) Open(name string) (fs.File, error) { - return q.statFS.fS.Open(name) -} - -// Stat returns a [FileInfo] describing the named file. -// If there is an error, it will be of type [*PathError]. -func (q *queryStatusFS) Stat(name string) (fs.FileInfo, error) { - return q.statFS.Stat(name) -} - -// ๐ŸŽฏ existsInFS -type existsInFS struct { - *queryStatusFS -} - -// ExistsInFS -func NewExistsInFS(at At) ExistsInFS { - ents := compose(sanitise(at.Root)) - - return &ents.exists -} - -// FileExists does file exist at the path specified -func (f *existsInFS) FileExists(name string) bool { - info, err := f.Stat(name) - if err != nil { - return false - } - - if info.IsDir() { - return false - } - - return true -} - -// DirectoryExists does directory exist at the path specified -func (f *existsInFS) DirectoryExists(name string) bool { - info, err := f.Stat(name) - if err != nil { - return false - } - - if !info.IsDir() { - return false - } - - return true -} - -// ๐ŸŽฏ readFileFS -type readFileFS struct { - *queryStatusFS -} - -func NewReadFileFS(at At) ReadFileFS { - ents := compose(sanitise(at.Root)) - - return &ents.reader -} - -// ReadFile reads the named file from the file system fs and returns its contents. -// A successful call returns a nil error, not [io.EOF]. -// (Because ReadFile reads the whole file, the expected EOF -// from the final Read is not treated as an error to be reported.) -// -// If fs implements [ReadFileFS], ReadFile calls fs.ReadFile. -// Otherwise ReadFile calls fs.Open and uses Read and Close -// on the returned [File]. -func (f *readFileFS) ReadFile(name string) ([]byte, error) { - return fs.ReadFile(f.queryStatusFS.statFS.fS, name) -} - -// ๐Ÿงฉ ---> file system mutation - -// ๐ŸŽฏ copyFS - -type copyFS struct { - *openFS -} - -func (f *copyFS) Copy(from, to string) error { - return fmt.Errorf("copy not implemented yet (from: %q, to: %q)", from, to) -} - -// CopyFS copies the file system fsys into the directory dir, -// creating dir if necessary. -func (f *copyFS) CopyFS(dir string, fsys fs.FS) error { - _ = fsys - return fmt.Errorf("copyFS not implemented yet (dir: %q)", dir) -} - -// ๐ŸŽฏ baseWriterFS -type baseWriterFS struct { - *openFS - *existsInFS - overwrite bool -} - -// ๐ŸŽฏ MakeDirFS -type makeDirAllFS struct { - *existsInFS -} - -// NewMakeDirFS -func NewMakeDirFS(at At) MakeDirFS { - ents := compose(sanitise(at.Root)).mutator(at.Overwrite) - - return &ents.writer -} - -// Mkdir creates a new directory with the specified name and permission -// bits (before umask). -// If there is an error, it will be of type *PathError. -func (f *makeDirAllFS) MakeDir(name string, perm os.FileMode) error { - if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) - } - - if f.DirectoryExists(name) { - return nil - } - - path := filepath.Join(f.statFS.root, name) - return os.Mkdir(path, perm) -} - -// MakeDirAll creates a directory named path, -// along with any necessary parents, and returns nil, -// or else returns an error. -// The permission bits perm (before umask) are used for all -// directories that MkdirAll creates. -// If path is already a directory, MakeDirAll does nothing -// and returns nil. -func (f *makeDirAllFS) MakeDirAll(name string, perm os.FileMode) error { - if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) - } - - if f.DirectoryExists(name) { - return nil - } - path := filepath.Join(f.statFS.root, name) - return os.MkdirAll(path, perm) -} - -// ๐ŸŽฏ removeFS - -type removeFS struct { - *openFS -} - -func (f *removeFS) Remove(name string) error { - if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) - } - - path := filepath.Join(f.root, filepath.Clean(name)) - return os.Remove(path) -} - -func (f *removeFS) RemoveAll(path string) error { - if !fs.ValidPath(path) { - return locale.NewInvalidPathError(path) - } - - return os.RemoveAll(filepath.Join(f.root, filepath.Clean(path))) -} - -// ๐ŸŽฏ renameFS - -type renameFS struct { - *openFS -} - -// Rename delegates to the Rename functionality implemented in the standard -// library. -func (s *renameFS) Rename(from, to string) error { - return os.Rename( - filepath.Join(s.root, from), - filepath.Join(s.root, to), - ) -} - -// ๐ŸŽฏ writeFileFS -type writeFileFS struct { - *baseWriterFS -} - -func NewWriteFileFS(at At) WriteFileFS { - ents := compose(sanitise(at.Root)).mutator(at.Overwrite) - - return &ents.writer -} - -// Create creates or truncates the named file. If the file already exists, -// it is truncated. If the file does not exist, it is created with mode 0o666 -// (before umask). If successful, methods on the returned File can -// be used for I/O; the associated file descriptor has mode O_RDWR. -// If there is an error, it will be of type *PathError. -// -// We need to maintain conformity with apis in the standard library. Ideally, -// this Create method would have the overwrite bool passed in as an argument, -// but doing so would break standard lib compatibility. Instead, the underlying -// implementation has to decide wether to Create on an override basis itself. -// The disadvantage of this approach is that the client can not decide on -// the fly wether a call to Create is on a override basis or not. This decision -// has to be made at the point of creating the file system. This is less -// flexible and just results in friction, but this is out of our power. -func (f *writeFileFS) Create(name string) (*os.File, error) { - if !fs.ValidPath(name) { - return nil, locale.NewInvalidPathError(name) - } - - if !f.overwrite && f.FileExists(name) { - return nil, os.ErrExist - } - - path := filepath.Join(f.root, name) - return os.Create(path) -} - -// WriteFile writes data to the named file, creating it if necessary. -// If the file does not exist, WriteFile creates it with permissions perm (before umask); -// otherwise WriteFile truncates it before writing, without changing permissions. -// Since WriteFile requires multiple system calls to complete, a failure mid-operation -// can leave the file in a partially written state. -func (f *writeFileFS) WriteFile(name string, data []byte, perm os.FileMode) error { - if !fs.ValidPath(name) { - return locale.NewInvalidPathError(name) - } - - path := filepath.Join(f.root, name) - return os.WriteFile(path, data, perm) -} - -// ๐Ÿงฉ ---> file system aggregators - -// ๐ŸŽฏ readerFS -type readerFS struct { - *existsInFS - *readDirFS - *readFileFS - *statFS -} - -// NewReaderFS -func NewReaderFS(at At) ReaderFS { - ents := compose(sanitise(at.Root)) - - return &ents.reader -} - -// ๐ŸŽฏ moverFS -type moverFS struct { - mover lazyMover -} - -// ๐ŸŽฏ writerFS -type writerFS struct { - *copyFS - *makeDirAllFS - *moverFS - *removeFS - *renameFS - *writeFileFS -} - -func NewWriterFS(at At) WriterFS { - ents := compose(sanitise(at.Root)).mutator(at.Overwrite) - - return &ents.writer -} - -// ๐ŸŽฏ mutatorFS -type mutatorFS struct { - *readerFS - *writerFS -} - -// Move is similar to rename but it has distinctly different semantics, which -// also varies depending on whether the file system was created with overwrite -// enabled or not. -// When overwrite is enabled, a move with overwrite the destination. If not -// enabled, Move will return as error (os.ErrExist). -// The paths denoted by from and to must be in different locations, otherwise -// the move amounts to a rename and the client should use Rename instead of -// move. When this scenario is detected, an error is returned. -func (f *mutatorFS) Move(from, to string) error { - return f.mover.instance(f.baseWriterFS.root, f.overwrite, f).move(from, to) -} - -func NewTraverseFS(at At) TraverseFS { - ents := compose(sanitise(at.Root)).mutator(at.Overwrite) - - return &mutatorFS{ - readerFS: &ents.reader, - writerFS: &ents.writer, - } -} - -func NewUniversalFS(at At) UniversalFS { - ents := compose(sanitise(at.Root)).mutator(at.Overwrite) - - return &mutatorFS{ - readerFS: &ents.reader, - writerFS: &ents.writer, - } -} - -// ๐Ÿงฉ ---> construction - -type ( - entities struct { - open openFS - read readDirFS - stat statFS - query queryStatusFS - exists existsInFS - reader readerFS - copy copyFS - remove removeFS - rename renameFS - writer writerFS - } -) - -func (e *entities) mutator(overwrite bool) *entities { - e.writer = writerFS{ - copyFS: ©FS{ - openFS: &e.open, - }, - makeDirAllFS: &makeDirAllFS{ - existsInFS: &e.exists, - }, - moverFS: &moverFS{}, - removeFS: &removeFS{ - openFS: &e.open, - }, - renameFS: &renameFS{ - openFS: &e.open, - }, - writeFileFS: &writeFileFS{ - baseWriterFS: &baseWriterFS{ - existsInFS: &e.exists, - openFS: &e.open, - overwrite: overwrite, - }, - }, - } - - return e -} - -func compose(root string) *entities { - open := openFS{ - fS: os.DirFS(root), - root: root, - } - read := readDirFS{ - openFS: &open, - } - stat := statFS{ - openFS: &open, - } - query := queryStatusFS{ - statFS: &statFS{ - openFS: &open, - }, - readDirFS: &read, - } - exists := existsInFS{ - queryStatusFS: &query, - } - - reader := readerFS{ - readDirFS: &read, - readFileFS: &readFileFS{ - queryStatusFS: &query, - }, - existsInFS: &exists, - statFS: &stat, - } - - return &entities{ - open: open, - read: read, - stat: stat, - query: query, - exists: exists, - reader: reader, - } -} diff --git a/lfs/from-file-info.go b/lfs/from-file-info.go deleted file mode 100644 index 5f0483b..0000000 --- a/lfs/from-file-info.go +++ /dev/null @@ -1,32 +0,0 @@ -package lfs - -import ( - "io/fs" -) - -type syntheticEntry struct { - fi fs.FileInfo -} - -func (e *syntheticEntry) Name() string { - return e.fi.Name() -} - -func (e *syntheticEntry) IsDir() bool { - return e.fi.IsDir() -} - -func (e *syntheticEntry) Type() fs.FileMode { - return e.fi.Mode() -} - -func (e *syntheticEntry) Info() (fs.FileInfo, error) { - return e.fi, nil -} - -// FromFileInfo synthesises a DirEntry instance from a FileInfo -func FromFileInfo(fi fs.FileInfo) fs.DirEntry { - return &syntheticEntry{ - fi: fi, - } -} diff --git a/lfs/fs-copy_test.go b/lfs/fs-copy_test.go deleted file mode 100644 index a22118a..0000000 --- a/lfs/fs-copy_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package lfs_test - -import ( - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: copy/all", Ordered, func() { - var ( - root string - fS lfs.UniversalFS - single string - ) - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - BeforeEach(func() { - fS = lfs.NewUniversalFS(lfs.At{ - Root: root, - Overwrite: false, - }) - scratch(root) - }) - - Context("op: Copy", func() { - When("given: ", func() { - It("๐Ÿงช should: ", func() { - _ = fS - _ = single - }) - }) - }) - - Context("op: CopyAll", func() { - When("given: ", func() { - It("๐Ÿงช should: ", func() { - - }) - }) - }) -}) diff --git a/lfs/fs-create_test.go b/lfs/fs-create_test.go deleted file mode 100644 index b26ed34..0000000 --- a/lfs/fs-create_test.go +++ /dev/null @@ -1,90 +0,0 @@ -package lfs_test - -import ( - "os" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: create", Ordered, func() { - var root string - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - Context("fs: WriteFileFS", func() { - BeforeEach(func() { - scratch(root) - }) - - Context("overwrite", func() { - var fS lfs.WriteFileFS - - BeforeEach(func() { - fS = lfs.NewWriteFileFS(lfs.At{ - Root: root, - Overwrite: true, - }) - }) - - Context("op: Create", func() { - When("given: file does not already exist", func() { - It("๐Ÿงช should: create successfully", func() { - Expect(require(root, lab.Static.FS.Scratch)).To(Succeed()) - name := lab.Static.FS.Create.Destination - file, err := fS.Create(name) - Expect(err).To(Succeed()) - defer file.Close() - - Expect(AsFile(name)).To(ExistInFS(fS)) - }) - }) - - When("given: file exists", func() { - It("๐Ÿงช should: create successfully", func() { - Expect(require( - root, lab.Static.FS.Scratch, lab.Static.FS.Create.Destination, - )).To(Succeed()) - name := lab.Static.FS.Create.Destination - file, err := fS.Create(name) - Expect(err).To(Succeed()) - defer file.Close() - - Expect(AsFile(name)).To(ExistInFS(fS)) - }) - }) - }) - }) - - Context("tentative", func() { - var fS lfs.WriteFileFS - - BeforeEach(func() { - fS = lfs.NewWriteFileFS(lfs.At{ - Root: root, - Overwrite: false, - }) - }) - - Context("op: Create", func() { - When("given: file exists", func() { - It("๐Ÿงช should: fail", func() { - file := lab.Static.FS.Create.Destination - Expect(require( - root, lab.Static.FS.Scratch, file, - )).To(Succeed()) - _, err := fS.Create(file) - Expect(err).To(MatchError(os.ErrExist)) - }) - }) - }) - }) - }) -}) diff --git a/lfs/fs-make-dir_test.go b/lfs/fs-make-dir_test.go deleted file mode 100644 index d7bf385..0000000 --- a/lfs/fs-make-dir_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package lfs_test - -import ( - "fmt" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: make-dir/all", Ordered, func() { - var root string - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - Context("tentative", func() { - Context("fs: MakeDirFS", func() { - var ( - fS lfs.MakeDirFS - ) - - BeforeEach(func() { - fS = lfs.NewMakeDirFS(lfs.At{ - Root: root, - Overwrite: false, - }) - scratch(root) - }) - - Context("op: MakeDir", func() { - When("given: path does not exist", func() { - It("๐Ÿงช should: complete ok", func() { - path := lab.Static.FS.Scratch - Expect(fS.MakeDir(path, lab.Perms.Dir.Perm())).To( - Succeed(), fmt.Sprintf("failed to MakeDir %q", path), - ) - - Expect(AsDirectory(path)).To(ExistInFS(fS)) - }) - }) - - When("given: path already exists", func() { - It("๐Ÿงช should: complete ok", func() { - path := lab.Static.FS.Existing.Directory - Expect(fS.MakeDir(path, lab.Perms.Dir.Perm())).To( - Succeed(), fmt.Sprintf("failed to MakeDir %q", path), - ) - }) - }) - }) - - Context("op: MakeDirAll", func() { - When("given: path does not exist", func() { - It("๐Ÿงช should: complete ok", func() { - path := lab.Static.FS.MakeDir.MakeAll - Expect(fS.MakeDirAll(path, lab.Perms.Dir.Perm())).To( - Succeed(), fmt.Sprintf("failed to MakeDir %q", path), - ) - - Expect(AsDirectory(path)).To(ExistInFS(fS)) - }) - }) - - When("given: path already exists", func() { - It("๐Ÿงช should: complete ok", func() { - path := lab.Static.FS.Existing.Directory - Expect(fS.MakeDir(path, lab.Perms.Dir.Perm())).To( - Succeed(), fmt.Sprintf("failed to MakeDir %q", path), - ) - - Expect(AsDirectory(path)).To(ExistInFS(fS)) - }) - }) - }) - }) - }) -}) diff --git a/lfs/fs-misc_test.go b/lfs/fs-misc_test.go deleted file mode 100644 index 11de2be..0000000 --- a/lfs/fs-misc_test.go +++ /dev/null @@ -1,124 +0,0 @@ -package lfs_test - -import ( - "io/fs" - "os" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -// NB: these tests should NEVER be run in parallel because they interact with -// local filesystem. -var _ = Describe("file systems", Ordered, func() { - var root string - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - Context("fs: StatFS", func() { - var fS fs.StatFS - - BeforeEach(func() { - fS = lfs.NewStatFS(lfs.At{ - Root: root, - }) - }) - - Context("op: FileExists", func() { - When("given: existing path", func() { - It("๐Ÿงช should: return true", func() { - _, err := fS.Stat(lab.Static.FS.Existing.File) - Expect(err).To(Succeed()) - }) - }) - - When("given: path does not exist", func() { - It("๐Ÿงช should: return false", func() { - _, err := fS.Stat(lab.Static.Foo) - Expect(err).To(MatchError(os.ErrNotExist)) - }) - }) - }) - }) - - Context("fs: ExistsInFS", func() { - var fS lfs.ExistsInFS - - BeforeEach(func() { - fS = lfs.NewExistsInFS(lfs.At{ - Root: root, - }) - }) - - Context("op: FileExists", func() { - When("given: existing path", func() { - It("๐Ÿงช should: return true", func() { - Expect(AsFile(lab.Static.FS.Existing.File)).To(ExistInFS(fS)) - }) - }) - - When("given: path does not exist", func() { - It("๐Ÿงช should: return false", func() { - Expect(AsFile(lab.Static.Foo)).NotTo(ExistInFS(fS)) - }) - }) - }) - - Context("op: DirectoryExists", func() { - When("given: existing path", func() { - It("๐Ÿงช should: return true", func() { - Expect(AsDirectory(lab.Static.FS.Existing.Directory)).To(ExistInFS(fS)) - }) - }) - - When("given: path does not exist", func() { - It("๐Ÿงช should: return false", func() { - Expect(AsDirectory(lab.Static.Foo)).NotTo(ExistInFS(fS)) - }) - }) - }) - }) - - Context("fs: ReadFileFS", func() { - var fS lfs.ReadFileFS - - BeforeEach(func() { - fS = lfs.NewReadFileFS(lfs.At{ - Root: root, - }) - }) - - Context("op: ReadFile", func() { - When("given: existing path", func() { - It("๐Ÿงช should: ", func() { - _, err := fS.ReadFile(lab.Static.FS.Existing.File) - Expect(err).To(Succeed()) - }) - }) - - When("given: path does not exist", func() { - It("๐Ÿงช should: ", func() { - _, err := fS.ReadFile(lab.Static.Foo) - Expect(err).NotTo(Succeed()) - }) - }) - }) - }) - - Context("fs: RenameFS", func() { - Context("op: Rename", func() { - When("given: ", func() { - It("๐Ÿงช should: ", func() { - - }) - }) - }) - }) -}) diff --git a/lfs/fs-move_test.go b/lfs/fs-move_test.go deleted file mode 100644 index fa68a47..0000000 --- a/lfs/fs-move_test.go +++ /dev/null @@ -1,360 +0,0 @@ -package lfs_test - -import ( - "fmt" - "path/filepath" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" - "github.com/snivilised/traverse/locale" -) - -// Note [clash/no-clash]: when an item is moved to the destination, clash -// refers to the scenario where the source already exists in the destination, -// whereas no-clash is the opposite. -// -// Eg, if moving src/foo.txt to dest/foo.txt, a clash scenario means foo.txt -// already exists in dest/ and no clash where it doesn't. The success of the -// operation depends on wether the overwrite flag has been specified in the -// filesystem. - -var _ = Describe("op: move", Ordered, func() { - var ( - root string - fS lfs.UniversalFS - ) - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - DescribeTable("fs: UniversalFS", - func(entry fsTE[lfs.UniversalFS]) { - for _, overwrite := range []bool{false, true} { - scratch(root) - - fS = lfs.NewUniversalFS(lfs.At{ - Root: root, - Overwrite: overwrite, - }) - entry.overwrite = overwrite - - if entry.arrange != nil { - entry.arrange(entry, fS) - } - entry.action(entry, fS) - } - }, - func(entry fsTE[lfs.UniversalFS]) string { - return fmt.Sprintf("๐Ÿงช ===> given: target is '%v', %v should: '%v'", - entry.given, entry.op, entry.should, - ) - }, - - // ๐Ÿ”† - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] directory exists, [no-clash]", - should: "succeed", - note: "filename not included in the destination path (from/file.txt => to)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsFile(lab.Static.FS.Move.To.File)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] directory exists, [clash]", - should: "succeed, only if override", - note: "filename not included in the destination path (from/file.txt => to)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, - entry.require, - entry.from, - )).To(Succeed()) - Expect(require(root, - lab.Static.FS.Move.Destination, - lab.Static.FS.Move.To.File, - )).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - if entry.overwrite { - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsFile(lab.Static.FS.Move.To.File)).To(ExistInFS(fS)) - return - } - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).NotTo(Succeed()) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] directory exists, [no-clash]", - should: "succeed", - note: "filename IS included in the destination path (from/file.txt => to/file.txt)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - destination := lab.Static.FS.Move.To.File - Expect(fS.Move(entry.from, destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsFile(destination)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] directory exists, [clash]", - should: "succeed, only if override", - note: "filename IS included in the destination path (from/file.txt => to/file.txt)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - - if entry.overwrite { - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - return - } - Expect(require(root, - lab.Static.FS.Move.Destination, - lab.Static.FS.Move.To.File, - )).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - destination := lab.Static.FS.Move.To.File - - if entry.overwrite { - Expect(fS.Move(entry.from, destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsFile(destination)).To(ExistInFS(fS)) - return - } - Expect(fS.Move(entry.from, destination)).NotTo(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] directory exists, [no clash]", - should: "succeed", - note: "directory not included in the destination path (from/dir => to)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsDirectory(lab.Static.FS.Move.To.Directory)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] directory exists, [clash]", - should: "fail", - note: "directory not included in the destination path (from/dir => to)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - if entry.overwrite { - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).NotTo(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - return - } - - Expect(fS.Move(entry.from, lab.Static.FS.Move.Destination)).NotTo(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] directory exists, [no clash]", - should: "succeed", - note: "directory IS included in the destination path (from/dir => to/dir)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - destination := lab.Static.FS.Move.To.Directory - Expect(fS.Move(entry.from, destination)).To(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - Expect(AsDirectory(destination)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] directory exists, [clash]", - should: "fail", - note: "directory IS included in the destination path (from/dir => to/dir)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - destination := lab.Static.FS.Move.To.Directory - Expect(fS.Move(entry.from, destination)).NotTo(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file missing", - should: "fail", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.Foo, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - err := fS.Move(entry.from, entry.to) - Expect(err).NotTo(Succeed(), fmt.Sprintf("OVERWRITE: %v", entry.overwrite)) - Expect(locale.IsBinaryFsOpError(err)).To(BeTrue()) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] directory missing", - should: "fail", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Move.Destination, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - destination := filepath.Join(entry.to, lab.Static.Foo) - Expect(fS.Move(entry.from, destination)).NotTo(Succeed(), - fmt.Sprintf("OVERWRITE: %v", entry.overwrite), - ) - }, - }), - - // The following tests are a duplicate of those defined for the rename - // operation ๐Ÿ’ , where the target item is being renamed into the same directory, - // but these should be rejected with an error, because this amounts to a - // rename which is not the intended use of Move. Instead a custom error - // is returned that denotes same directory so that the client can detect this - // and invoke rename, with the same parameters. The exception to this is - // if the from/to names refer to the same file, in which case the Move - // is ignored as a no op. - // - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] name does not exist, [no-clash]", - should: "fail, same directory move, use rename instead", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Rename.From.File, - to: lab.Static.FS.Rename.To.File, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - IsSameDirMoveRejectionError(fS.Move(entry.from, entry.to), entry.should) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] file exists, [to] equal to [from], [clash]", - should: "succeed, ignored", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Rename.From.File, - to: lab.Static.FS.Rename.From.File, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - Expect(fS.Move(entry.from, entry.to)).To(Succeed()) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] name does not exist, [no-clash]", - should: "fail, same directory move, use rename instead", - op: "Move", - require: lab.Static.FS.Rename.From.Directory, - from: lab.Static.FS.Rename.From.Directory, - to: lab.Static.FS.Rename.To.Directory, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - IsSameDirMoveRejectionError(fS.Move(entry.from, entry.to), entry.should) - }, - }), - - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "[from] directory exists, [to] equal to [from], [clash]", - should: "fail, directory names can't be same", - op: "Move", - require: lab.Static.FS.Rename.From.Directory, - from: lab.Static.FS.Rename.From.Directory, - to: lab.Static.FS.Rename.From.Directory, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - Expect(require(root, entry.require)).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - IsSameDirMoveRejectionError(fS.Move(entry.from, entry.to), entry.should) - }, - }), - ) -}) diff --git a/lfs/fs-mover-overwrite.go b/lfs/fs-mover-overwrite.go deleted file mode 100644 index c0dc147..0000000 --- a/lfs/fs-mover-overwrite.go +++ /dev/null @@ -1,17 +0,0 @@ -package lfs - -type overwriteMover struct { - baseMover -} - -func (m *overwriteMover) create() mover { - m.actions = movers{ - {true, false, false, false}: m.moveItemWithName, // from exists as file, to does not exist - {true, false, true, false}: m.moveItemWithName, // from exists as dir, to does not exist - {true, true, false, true}: m.moveItemWithoutName, // from exists as file,to exists as dir - {true, true, true, true}: m.moveItemWithoutNameClash, // from exists as dir, to exists as dir - {true, true, false, false}: m.noOp, // from and to refer to the same existing file - } - - return m -} diff --git a/lfs/fs-mover-tentative.go b/lfs/fs-mover-tentative.go deleted file mode 100644 index 37e9398..0000000 --- a/lfs/fs-mover-tentative.go +++ /dev/null @@ -1,57 +0,0 @@ -package lfs - -import ( - "path/filepath" - - "github.com/snivilised/traverse/locale" -) - -type tentativeMover struct { - baseMover -} - -func (m *tentativeMover) create() mover { - m.actions = movers{ - {true, false, false, false}: m.moveItemWithName, // from exists as file, to does not exist - {true, false, true, false}: m.moveDirectoryWithName, // from exists as dir, to does not exist - {true, true, false, true}: m.moveItemWithoutName, // from exists as file,to exists as dir - {true, true, true, true}: m.moveItemWithoutNameClash, // from exists as dir, to exists as dir - {true, true, false, false}: m.rejectOverwriteOrNoOp, // from and to may refer to the same existing file - } - - return m -} - -func (m *tentativeMover) moveDirectoryWithName(from, to string) error { - // 'to' includes the file name eg: - // from/file.txt => to/file.txt - // - if filepath.Dir(from) == filepath.Dir(to) { - return locale.NewRejectSameDirMoveError(moveOpName, from, to) - } - - return m.moveItemWithName(from, to) -} - -func (m *tentativeMover) moveItemWithoutName(from, to string) error { - // 'to' does not include the file name, so it has to be appended, eg: - // from/file.txt => to/ - // - if _, err := m.fS.Stat(filepath.Join(to, filepath.Base(from))); err == nil { - return locale.NewInvalidBinaryFsOpError("Move", from, to) - } - - return m.baseMover.moveItemWithoutName(from, to) -} - -func (m *tentativeMover) rejectOverwriteOrNoOp(from, to string) error { - // both file names exists, but they may or may not be the same item. If - // they are not in the same location then we reject the overwrite attempt - // otherwise they are the same item and this should effectively be a no op. - // - if filepath.Dir(from) != filepath.Dir(to) { - return locale.NewInvalidBinaryFsOpError(moveOpName, from, to) - } - - return nil -} diff --git a/lfs/fs-mover.go b/lfs/fs-mover.go deleted file mode 100644 index 8808914..0000000 --- a/lfs/fs-mover.go +++ /dev/null @@ -1,155 +0,0 @@ -package lfs - -import ( - "os" - "path/filepath" - "sync" - - "github.com/snivilised/traverse/internal/third/lo" - "github.com/snivilised/traverse/locale" -) - -const ( - moveOpName = "Move" -) - -type ( - mover interface { - create() mover - move(from, to string) error - } - - moveFunc func(from, to string) error - - moverBitmask struct { - fromExists bool - toExists bool - fromIsDir bool - toIsDir bool - } - - movers map[moverBitmask]moveFunc - - baseMover struct { - root string - fS UniversalFS - actions movers - } -) - -func (m *baseMover) move(from, to string) error { - mask := m.query(from, to) - - if action, exists := m.actions[mask]; exists { - if err := action(from, to); err != nil { - // we can't mask the original message - // - // errors.Wrap() - // return locale.NewInvalidBinaryFsOpError(moveOpName, from, to) - return err - } - return nil - } - - return locale.NewInvalidBinaryFsOpError(moveOpName, from, to) -} - -func (m *baseMover) query(from, to string) moverBitmask { - fromExists, fromIsDir := m.peek(from) - toExists, toIsDir := m.peek(to) - - return moverBitmask{ - fromExists: fromExists, - toExists: toExists, - fromIsDir: fromIsDir, - toIsDir: toIsDir, - } -} - -func (m *baseMover) peek(name string) (exists, isDir bool) { - if m.fS.DirectoryExists(name) { - return true, true - } - - if m.fS.FileExists(name) { - return true, false - } - - return false, false -} - -func (m *baseMover) moveItemWithName(from, to string) error { - // 'to' includes the file name eg: - // from/file.txt => to/file.txt - // - if filepath.Dir(from) == filepath.Dir(to) { - return locale.NewRejectSameDirMoveError(moveOpName, from, to) - } - - return os.Rename( - filepath.Join(m.root, from), - filepath.Join(m.root, to), - ) -} - -func (m *baseMover) moveItemWithoutName(from, to string) error { - // 'to' does not include the file name, so it has to be appended, eg: - // from/file.txt => to/ - // - return os.Rename( - filepath.Join(m.root, from), - filepath.Join(m.root, to, filepath.Base(from)), - ) -} - -func (m *baseMover) moveItemWithoutNameClash(from, to string) error { - fromBase := filepath.Base(from) - toBase := filepath.Base(to) - - if fromBase == toBase { - // If there were a merge facility, this is where we would implement this, - // ie merge the from directory with to, instead of returning an error. - // - return locale.NewRejectSameDirMoveError(moveOpName, from, to) - } - - return m.moveItemWithoutName(from, to) -} - -func (m *baseMover) noOp(_, _ string) error { - return nil -} - -type lazyMover struct { - once sync.Once - mover mover -} - -func (l *lazyMover) instance(root string, overwrite bool, fS UniversalFS) mover { - l.once.Do(func() { - l.mover = l.create(root, overwrite, fS) - }) - - return l.mover -} - -func (l *lazyMover) create(root string, overwrite bool, fS UniversalFS) mover { - return lo.TernaryF(overwrite, - func() mover { - return &overwriteMover{ - baseMover: baseMover{ - root: root, - fS: fS, - }, - } - }, - func() mover { - return &tentativeMover{ - baseMover: baseMover{ - root: root, - fS: fS, - }, - } - }, - ).create() -} diff --git a/lfs/fs-remove_test.go b/lfs/fs-remove_test.go deleted file mode 100644 index 7e56e7b..0000000 --- a/lfs/fs-remove_test.go +++ /dev/null @@ -1,144 +0,0 @@ -package lfs_test - -import ( - "errors" - "fmt" - "os" - "path/filepath" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: remove", Ordered, func() { - var ( - root string - fS lfs.UniversalFS - ) - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - BeforeEach(func() { - scratchPath := filepath.Join(root, lab.Static.FS.Scratch) - - if _, err := os.Stat(scratchPath); err == nil { - Expect(os.RemoveAll(scratchPath)).To(Succeed(), - fmt.Sprintf("failed to delete existing directory %q", scratchPath), - ) - } - }) - - DescribeTable("removal", - func(entry fsTE[lfs.UniversalFS]) { - for _, overwrite := range []bool{false, true} { - fS = lfs.NewUniversalFS(lfs.At{ - Root: root, - Overwrite: entry.overwrite, - }) - entry.overwrite = overwrite - - if entry.arrange != nil { - entry.arrange(entry, fS) - } - entry.action(entry, fS) - } - }, - func(entry fsTE[lfs.UniversalFS]) string { - return fmt.Sprintf("๐Ÿงช ===> given: target is '%v', %v should: '%v'", - entry.given, entry.op, entry.should, - ) - }, - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "file and exists", - should: "succeed", - op: "Remove", - require: lab.Static.FS.Scratch, - target: lab.Static.FS.Remove.File, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - err := require(root, entry.require, entry.target) - Expect(err).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - if entry.overwrite { - // tbd - return - } - Expect(fS.Remove(entry.target)).To(Succeed()) - }, - }), - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "path does not exist", - should: "fail", - op: "Remove", - require: lab.Static.FS.Scratch, - target: lab.Static.Foo, - action: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - if entry.overwrite { - // tbd - return - } - Expect(fS.Remove(entry.target)).To(MatchError(os.ErrNotExist)) - }, - }), - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "directory exists and not empty", - should: "fail", - op: "Remove", - require: lab.Static.FS.Scratch, - target: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - err := require(root, entry.require, lab.Static.FS.Remove.File) - Expect(err).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - if entry.overwrite { - // tbd - return - } - Expect(errors.Unwrap(fS.Remove(entry.target))).To( - MatchError("directory not empty"), - ) - }, - }), - // - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "path does not exist", - should: "succeed", - op: "RemoveAll", - require: lab.Static.FS.Scratch, - target: lab.Static.Foo, - action: func(entry fsTE[lfs.UniversalFS], fS lfs.UniversalFS) { - if entry.overwrite { - // tbd - return - } - Expect(fS.RemoveAll(entry.target)).To(Succeed()) - }, - }), - Entry(nil, fsTE[lfs.UniversalFS]{ - given: "directory exists and not empty", - should: "succeed", - op: "RemoveAll", - require: lab.Static.FS.Scratch, - target: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - err := require(root, entry.require, lab.Static.FS.Remove.File) - Expect(err).To(Succeed()) - }, - action: func(entry fsTE[lfs.UniversalFS], _ lfs.UniversalFS) { - if entry.overwrite { - // tbd - return - } - Expect(fS.RemoveAll(entry.target)).To(Succeed()) - }, - }), - ) -}) diff --git a/lfs/fs-rename_test.go b/lfs/fs-rename_test.go deleted file mode 100644 index a5675bb..0000000 --- a/lfs/fs-rename_test.go +++ /dev/null @@ -1,272 +0,0 @@ -package lfs_test - -import ( - "fmt" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: rename", Ordered, func() { - var ( - root string - fS lfs.RenameFS - ) - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - BeforeEach(func() { - fS = lfs.NewUniversalFS(lfs.At{ - Root: root, - Overwrite: false, - }) - - scratch(root) - }) - - DescribeTable("fs: RenameFS", - func(entry fsTE[lfs.RenameFS]) { - if entry.arrange != nil { - entry.arrange(entry, fS) - } - entry.action(entry, fS) - }, - func(entry fsTE[lfs.RenameFS]) string { - return fmt.Sprintf("๐Ÿงช ===> given: target is '%v', %v should: '%v'", - entry.given, entry.op, entry.should, - ) - }, - // The following tests are a duplicate of those defined for the move - // operation ๐Ÿ”†, but with appropriately adjusted expectations. - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] directory exists, [no-clash]", - should: "fail, because filename is missing, from to path", - note: "filename not included in the destination path (from/file.txt => to)", - op: "Rename", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] directory exists, [clash]", - should: "succeed, only if override", - note: "filename not included in the destination path (from/file.txt => to)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, - entry.require, - entry.from, - )).To(Succeed()) - Expect(require(root, - lab.Static.FS.Move.Destination, - lab.Static.FS.Move.To.File, - )).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] directory exists, [no-clash]", - should: "succeed", - note: "filename IS included in the destination path (from/file.txt => to/file.txt)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - destination := lab.Static.FS.Move.To.File - Expect(fS.Rename(entry.from, destination)).To(Succeed()) - Expect(AsFile(destination)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] directory exists, [clash]", - should: "succeed; move and overwrite", - note: "filename IS included in the destination path (from/file.txt => to/file.txt)", - op: "Move", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Move.From.File, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - - if entry.overwrite { - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - return - } - Expect(require(root, - lab.Static.FS.Move.Destination, - lab.Static.FS.Move.To.File, - )).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - Expect(fS.Rename(entry.from, lab.Static.FS.Move.To.File)).To(Succeed()) - Expect(AsFile(lab.Static.FS.Move.From.File)).NotTo(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] directory exists, [no clash]", - should: "fail, because dir name is missing, from to path", - note: "directory not included in the destination path (from/dir => to)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] directory exists, [clash]", - should: "fail", - note: "directory not included in the destination path (from/dir => to)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - IsLinkError(fS.Rename(entry.from, lab.Static.FS.Move.Destination), entry.should) - Expect(AsDirectory(lab.Static.FS.Move.From.Directory)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] directory exists, [no clash]", - should: "succeed", - note: "directory IS included in the destination path (from/dir => to/dir)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - destination := lab.Static.FS.Move.To.Directory - Expect(fS.Rename(entry.from, destination)).To(Succeed()) - Expect(AsDirectory(destination)).To(ExistInFS(fS)) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] directory exists, [clash]", - should: "fail", - note: "directory IS included in the destination path (from/dir => to/dir)", - op: "Move", - require: lab.Static.FS.Move.From.Directory, - from: lab.Static.FS.Move.From.Directory, - to: lab.Static.FS.Scratch, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.Destination)).To(Succeed()) - Expect(require(root, lab.Static.FS.Move.To.Directory)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - destination := lab.Static.FS.Move.To.Directory - Expect(fS.Rename(entry.from, destination)).NotTo(Succeed()) - Expect(AsDirectory(lab.Static.FS.Move.From.Directory)).To(ExistInFS(fS)) - }, - }), - - // ๐Ÿ’  The tests in the follow section are defined for scenarios where the - // target item is being renamed into the same directory; ie it is a rename, - // without moving to a different directory. - // - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] name does not exist, [no-clash]", - should: "succeed", - op: "Rename", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Rename.From.File, - to: lab.Static.FS.Rename.To.File, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - Expect(fS.Rename(entry.from, entry.to)).To(Succeed()) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] file exists, [to] equal to [from], [clash]", - should: "succeed, ignored", - op: "Rename", - require: lab.Static.FS.Scratch, - from: lab.Static.FS.Rename.From.File, - to: lab.Static.FS.Rename.From.File, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require, entry.from)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - Expect(fS.Rename(entry.from, entry.to)).To(Succeed()) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] name does not exist, [no-clash]", - should: "succeed", - op: "Rename", - require: lab.Static.FS.Rename.From.Directory, - from: lab.Static.FS.Rename.From.Directory, - to: lab.Static.FS.Rename.To.Directory, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - Expect(fS.Rename(entry.from, entry.to)).To(Succeed()) - }, - }), - - Entry(nil, fsTE[lfs.RenameFS]{ - given: "[from] directory exists, [to] equal to [from], [clash]", - should: "fail, directory names can't be same", - op: "Rename", - require: lab.Static.FS.Rename.From.Directory, - from: lab.Static.FS.Rename.From.Directory, - to: lab.Static.FS.Rename.From.Directory, - arrange: func(entry fsTE[lfs.RenameFS], _ lfs.RenameFS) { - Expect(require(root, entry.require)).To(Succeed()) - }, - action: func(entry fsTE[lfs.RenameFS], fS lfs.RenameFS) { - IsLinkError(fS.Rename(entry.from, entry.to), entry.should) - }, - }), - ) -}) diff --git a/lfs/fs-write-file_test.go b/lfs/fs-write-file_test.go deleted file mode 100644 index 42b5275..0000000 --- a/lfs/fs-write-file_test.go +++ /dev/null @@ -1,74 +0,0 @@ -package lfs_test - -import ( - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - "github.com/snivilised/li18ngo" - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/lfs" -) - -var _ = Describe("op: write-file", Ordered, func() { - var root string - - BeforeAll(func() { - Expect(li18ngo.Use()).To(Succeed()) - - root = lab.Repo("test") - }) - - Context("fs: WriteFileFS", func() { - BeforeEach(func() { - scratch(root) - }) - - Context("overwrite", func() { - var fS lfs.WriteFileFS - - BeforeEach(func() { - fS = lfs.NewWriteFileFS(lfs.At{ - Root: root, - Overwrite: true, - }) - }) - - Context("op: WriteFile", func() { - When("given: file does not already exist", func() { - It("๐Ÿงช should: write successfully", func() { - Expect(require(root, lab.Static.FS.Scratch)).To(Succeed()) - name := lab.Static.FS.Write.Destination - Expect(fS.WriteFile( - name, lab.Static.FS.Write.Content, lab.Perms.File.Perm(), - )).To(Succeed()) - Expect(AsFile(name)).To(ExistInFS(fS)) - }) - }) - }) - }) - - Context("tentative", func() { - var fS lfs.WriteFileFS - - BeforeEach(func() { - fS = lfs.NewWriteFileFS(lfs.At{ - Root: root, - Overwrite: false, - }) - }) - - Context("op: WriteFile", func() { - When("given: file does not already exist", func() { - It("๐Ÿงช should: write successfully", func() { - file := lab.Static.FS.Write.Destination - Expect(require( - root, lab.Static.FS.Scratch, file, - )).To(Succeed()) - Expect(fS.WriteFile( - file, lab.Static.FS.Write.Content, lab.Perms.File.Perm(), - )).To(Succeed()) - }) - }) - }) - }) - }) -}) diff --git a/lfs/lfs-defs.go b/lfs/lfs-defs.go deleted file mode 100644 index def387b..0000000 --- a/lfs/lfs-defs.go +++ /dev/null @@ -1,117 +0,0 @@ -package lfs - -import ( - "io/fs" - "os" -) - -// ๐Ÿ“ฆ pkg: lfs - contains local file system abstractions for navigation. -// Since there are no standard write-able file system interfaces, -// we need to define proprietary ones here in this package. -// This is a low level package that should not use anything else in -// traverse. - -type ( - // At represents generic info required to create a file system - At struct { - Root string - Overwrite bool - } - - // FileSystems contains the logical file systems required - // for navigation. - FileSystems struct { - // T is the file system that contains just the functionality required - // for traversal. It can also represent other file systems including afero, - // providing the appropriate adapters are in place. - T TraverseFS - } - - // ExistsInFS contains methods that check the existence of file system items. - ExistsInFS interface { - // FileExists does file exist at the path specified - FileExists(name string) bool - - // DirectoryExists does directory exist at the path specified - DirectoryExists(name string) bool - } - - // ReadFileFS file system non streaming reader - ReadFileFS interface { - fs.FS - // Read reads file at path, from file system specified - ReadFile(name string) ([]byte, error) - } - - // ReaderFS - ReaderFS interface { - fs.StatFS - fs.ReadDirFS - ExistsInFS - ReadFileFS - } - - // MakeDirFS is a file system with a MkDirAll method. - MakeDirFS interface { - ExistsInFS - MakeDir(name string, perm os.FileMode) error - MakeDirAll(name string, perm os.FileMode) error - } - - // MoveFS - MoveFS interface { - } - - // CopyFS - CopyFS interface { - Copy(from, to string) error - // CopyFS copies the file system fsys into the directory dir, - // creating dir if necessary. - CopyFS(dir string, fsys fs.FS) error - } - - // RemoveFS - RemoveFS interface { - Remove(name string) error - RemoveAll(path string) error - } - - // RenameFS - RenameFS interface { - Rename(from, to string) error - } - - // WriteFileFS file system non streaming writer - WriteFileFS interface { - // Create creates or truncates the named file. - Create(name string) (*os.File, error) - // Write writes file at path, to file system specified - WriteFile(name string, data []byte, perm os.FileMode) error - } - - // WriterFS - WriterFS interface { - CopyFS - ExistsInFS - MakeDirFS - MoveFS - RemoveFS - RenameFS - WriteFileFS - } - - // TraverseFS non streaming file system with reader and some - // writer capabilities - TraverseFS interface { - MakeDirFS - ReaderFS - WriteFileFS - } - - // UniversalFS the file system that can do it all - UniversalFS interface { - ReaderFS - WriterFS - Move(from, to string) error - } -) diff --git a/lfs/lfs-suite_test.go b/lfs/lfs-suite_test.go deleted file mode 100644 index bda8bf7..0000000 --- a/lfs/lfs-suite_test.go +++ /dev/null @@ -1,195 +0,0 @@ -package lfs_test - -import ( - "errors" - "fmt" - "io/fs" - "os" - "path/filepath" - "strings" - "testing" - "testing/fstest" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - lab "github.com/snivilised/traverse/internal/laboratory" - "github.com/snivilised/traverse/locale" -) - -func TestLfs(t *testing.T) { - RegisterFailHandler(Fail) - RunSpecs(t, "Lfs Suite") -} - -type ( - ensureTE struct { - given string - should string - relative string - expected string - directory bool - } - - RPEntry struct { - given string - should string - path string - expect string - } - - funcFS[T any] func(entry fsTE[T], fS T) - - fsTE[T any] struct { - given string - should string - note string - op string - overwrite bool - directory bool - require string - target string - from string - to string - arrange funcFS[T] - action funcFS[T] - } -) - -func (t *fsTE[T]) run(fS T) { - if t.arrange != nil { - t.arrange(*t, fS) - } - t.action(*t, fS) -} - -var ( - fakeHome = filepath.Join(string(filepath.Separator), "home", "rabbitweed") - fakeAbsCwd = filepath.Join(string(filepath.Separator), "home", "rabbitweed", "music", "xpander") - fakeAbsParent = filepath.Join(string(filepath.Separator), "home", "rabbitweed", "music") -) - -// require ensures that a path exists. If files are also provided, -// it will create these files too. The files are relative to the root -// and should be prefixed by parent; that is to say, when a test needs -// scratch/foo.txt, parent = 'scratch' and file = 'scratch/foo.txt'; -// ie te file still needs to be relative to root, not parent. -func require(root, parent string, files ...string) error { - if err := os.MkdirAll(filepath.Join(root, parent), lab.Perms.Dir.Perm()); err != nil { - return fmt.Errorf("failed to create directory: %q (%w)", parent, err) - } - - for _, name := range files { - handle, err := os.Create(filepath.Join(root, name)) - if err != nil { - return fmt.Errorf("failed to create file: %q (%w)", name, err) - } - - handle.Close() - } - - return nil -} - -func scratch(root string) { - scratchPath := filepath.Join(root, lab.Static.FS.Scratch) - - if _, err := os.Stat(scratchPath); err == nil { - Expect(os.RemoveAll(scratchPath)).To(Succeed(), - fmt.Sprintf("failed to delete existing directory %q", scratchPath), - ) - } -} - -func fakeHomeResolver() (string, error) { - return fakeHome, nil -} - -func fakeAbsResolver(path string) (string, error) { - if strings.HasPrefix(path, "..") { - return filepath.Join(fakeAbsParent, path[2:]), nil - } - - if strings.HasPrefix(path, ".") { - return filepath.Join(fakeAbsCwd, path[1:]), nil - } - - return path, nil -} - -func IsLinkError(err error, reason string) { - var linkErr *os.LinkError - Expect(errors.As(err, &linkErr)).To(BeTrue(), fmt.Sprintf("not LinkError, %q", reason)) -} - -func IsSameDirMoveRejectionError(err error, reason string) { - Expect(locale.IsRejectSameDirMoveError(err)).To(BeTrue(), - fmt.Sprintf("not SameDirMoveRejectionError, %q", reason), - ) -} - -type ( - makeDirMapFS struct { - mapFS fstest.MapFS - } -) - -func (f *makeDirMapFS) FileExists(path string) bool { - fi, err := f.mapFS.Stat(path) - if err != nil { - return false - } - - if fi.IsDir() { - return false - } - - return true -} - -func (f *makeDirMapFS) DirectoryExists(path string) bool { - if strings.HasPrefix(path, string(filepath.Separator)) { - path = path[1:] - } - - fileInfo, err := f.mapFS.Stat(path) - if err != nil { - return false - } - - if !fileInfo.IsDir() { - return false - } - - return true -} - -func (f *makeDirMapFS) MakeDir(path string, perm os.FileMode) error { - if exists := f.DirectoryExists(path); !exists { - f.mapFS[path] = &fstest.MapFile{ - Mode: fs.ModeDir | perm, - } - } - - return nil -} - -func (f *makeDirMapFS) MakeDirAll(path string, perm os.FileMode) error { - var current string - segments := filepath.SplitList(path) - - for _, part := range segments { - if current == "" { - current = part - } else { - current += string(filepath.Separator) + part - } - - if exists := f.DirectoryExists(current); !exists { - f.mapFS[current] = &fstest.MapFile{ - Mode: fs.ModeDir | perm, - } - } - } - - return nil -} diff --git a/lfs/matchers_test.go b/lfs/matchers_test.go deleted file mode 100644 index 1d912b2..0000000 --- a/lfs/matchers_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package lfs_test - -import ( - "fmt" - - "github.com/onsi/gomega/types" - "github.com/snivilised/traverse/lfs" -) - -type PathExistsMatcher struct { - fS interface{} -} - -type AsDirectory string -type AsFile string - -func ExistInFS(fs interface{}) types.GomegaMatcher { - return &PathExistsMatcher{ - fS: fs, - } -} - -func (m *PathExistsMatcher) Match(actual interface{}) (bool, error) { - FS, fileSystemOK := m.fS.(lfs.ExistsInFS) - if !fileSystemOK { - return false, fmt.Errorf("โŒ matcher expected an lfs.ExistsInFS instance (%T)", FS) - } - - if actualPath, dirOK := actual.(AsDirectory); dirOK { - return FS.DirectoryExists(string(actualPath)), nil - } - - if actualPath, fileOK := actual.(AsFile); fileOK { - return FS.FileExists(string(actualPath)), nil - } - - return false, fmt.Errorf("โŒ matcher expected an AsDirectory or AsFile instance (%T)", actual) -} - -func (m *PathExistsMatcher) FailureMessage(actual interface{}) string { - return fmt.Sprintf("๐Ÿ”ฅ Expected\n\t%v\npath to exist", actual) -} - -func (m *PathExistsMatcher) NegatedFailureMessage(actual interface{}) string { - return fmt.Sprintf("๐Ÿ”ฅ Expected\n\t%v\npath NOT to exist\n", actual) -} diff --git a/lfs/resolve-mocks.go b/lfs/resolve-mocks.go deleted file mode 100644 index 776329a..0000000 --- a/lfs/resolve-mocks.go +++ /dev/null @@ -1,29 +0,0 @@ -package lfs - -// AbsFunc signature of function used to obtain the absolute representation of -// a path. -type AbsFunc func(path string) (string, error) - -// Abs function invoker, allows a function to be used in place where -// an instance of an interface would be expected. -func (f AbsFunc) Abs(path string) (string, error) { - return f(path) -} - -// HomeUserFunc signature of function used to obtain the user's home directory. -type HomeUserFunc func() (string, error) - -// Home function invoker, allows a function to be used in place where -// an instance of an interface would be expected. -func (f HomeUserFunc) Home() (string, error) { - return f() -} - -// ResolveMocks, used to override the internal functions used -// to resolve the home path (os.UserHomeDir) and the abs path -// (filepath.Abs). In normal usage, these do not need to be provided, -// just used for testing purposes. -type ResolveMocks struct { - HomeFunc HomeUserFunc - AbsFunc AbsFunc -} diff --git a/lfs/resolve-path.go b/lfs/resolve-path.go deleted file mode 100644 index 7659718..0000000 --- a/lfs/resolve-path.go +++ /dev/null @@ -1,55 +0,0 @@ -package lfs - -import ( - "os" - "path/filepath" - - "github.com/snivilised/traverse/internal/third/lo" -) - -// ResolvePath performs 2 forms of path resolution. The first is resolving a -// home path reference, via the ~ character; ~ is replaced by the user's -// home path. The second resolves ./ or ../ relative path. The overrides -// do not need to be provided. -func ResolvePath(path string, mocks ...ResolveMocks) string { - result := path - - if len(mocks) > 0 { - m := mocks[0] - result = lo.TernaryF(result[0] == '~', - func() string { - if h, err := m.HomeFunc(); err == nil { - return filepath.Join(h, result[1:]) - } - - return path - }, - func() string { - if a, err := m.AbsFunc(result); err == nil { - return a - } - - return path - }, - ) - } else { - result = lo.TernaryF(result[0] == '~', - func() string { - if h, err := os.UserHomeDir(); err == nil { - return filepath.Join(h, result[1:]) - } - - return path - }, - func() string { - if a, err := filepath.Abs(result); err == nil { - return a - } - - return path - }, - ) - } - - return result -} diff --git a/lfs/resolve-path_test.go b/lfs/resolve-path_test.go deleted file mode 100644 index 40fdf57..0000000 --- a/lfs/resolve-path_test.go +++ /dev/null @@ -1,106 +0,0 @@ -package lfs_test - -import ( - "fmt" - "path/filepath" - "strings" - - . "github.com/onsi/ginkgo/v2" //nolint:revive // ok - . "github.com/onsi/gomega" //nolint:revive // ok - - "github.com/snivilised/li18ngo" - "github.com/snivilised/traverse/lfs" - "github.com/snivilised/traverse/locale" -) - -var _ = Describe("ResolvePath", Ordered, func() { - BeforeAll(func() { - Expect(li18ngo.Use( - func(o *li18ngo.UseOptions) { - o.From.Sources = li18ngo.TranslationFiles{ - locale.SourceID: li18ngo.TranslationSource{Name: "traverse"}, - } - }, - )).To(Succeed()) - }) - - DescribeTable("Overrides provided", - func(entry *RPEntry) { - mocks := lfs.ResolveMocks{ - HomeFunc: fakeHomeResolver, - AbsFunc: fakeAbsResolver, - } - - if filepath.Separator == '/' { - actual := lfs.ResolvePath(entry.path, mocks) - Expect(actual).To(Equal(entry.expect)) - } else { - normalisedPath := strings.ReplaceAll(entry.path, "/", string(filepath.Separator)) - normalisedExpect := strings.ReplaceAll(entry.expect, "/", string(filepath.Separator)) - - actual := lfs.ResolvePath(normalisedPath, mocks) - Expect(actual).To(Equal(normalisedExpect)) - } - }, - func(entry *RPEntry) string { - return fmt.Sprintf("๐Ÿงช ===> given: '%v', should: '%v'", entry.given, entry.should) - }, - - Entry(nil, &RPEntry{ - given: "path is a valid absolute path", - should: "return path unmodified", - path: "/home/rabbitweed/foo", - expect: "/home/rabbitweed/foo", - }), - Entry(nil, &RPEntry{ - given: "path contains leading ~", - should: "replace ~ with home path", - path: "~/foo", - expect: "/home/rabbitweed/foo", - }), - Entry(nil, &RPEntry{ - given: "path is relative to cwd", - should: "replace ~ with home path", - path: "./foo", - expect: "/home/rabbitweed/music/xpander/foo", - }), - Entry(nil, &RPEntry{ - given: "path is relative to parent", - should: "replace ~ with home path", - path: "../foo", - expect: "/home/rabbitweed/music/foo", - }), - Entry(nil, &RPEntry{ - given: "path is relative to grand parent", - should: "replace ~ with home path", - path: "../../foo", - expect: "/home/rabbitweed/foo", - }), - ) - - When("No overrides provided", func() { - Context("and: home", func() { - It("๐Ÿงช should: not fail", func() { - lfs.ResolvePath("~/") - }) - }) - - Context("and: abs cwd", func() { - It("๐Ÿงช should: not fail", func() { - lfs.ResolvePath("./") - }) - }) - - Context("and: abs parent", func() { - It("๐Ÿงช should: not fail", func() { - lfs.ResolvePath("../") - }) - }) - - Context("and: abs grand parent", func() { - It("๐Ÿงช should: not fail", func() { - lfs.ResolvePath("../..") - }) - }) - }) -}) diff --git a/lfs/separate.go b/lfs/separate.go deleted file mode 100644 index bdead76..0000000 --- a/lfs/separate.go +++ /dev/null @@ -1,31 +0,0 @@ -package lfs - -import ( - "io/fs" - - "github.com/snivilised/traverse/internal/third/lo" -) - -func Separate(entries []fs.DirEntry) (files, folders []fs.DirEntry) { - grouped := lo.GroupBy(entries, func(entry fs.DirEntry) bool { - return entry.IsDir() - }) - - const ( - asFile = false - asFolder = true - ) - - // incase lo.GroupBy has returned a nil for a particular grouping, - // we make sure we at least have an empty slice instead of allowing - // nil to be returned to represent an empty result set. - // - files = lo.Ternary(grouped[asFile] == nil, - []fs.DirEntry{}, grouped[asFile], - ) - folders = lo.Ternary(grouped[asFolder] == nil, - []fs.DirEntry{}, grouped[asFolder], - ) - - return files, folders -} diff --git a/lfs/split-parent.go b/lfs/split-parent.go deleted file mode 100644 index ddad317..0000000 --- a/lfs/split-parent.go +++ /dev/null @@ -1,12 +0,0 @@ -package lfs - -import ( - "path/filepath" -) - -func SplitParent(path string) (d, f string) { - d = filepath.Dir(path) - f = filepath.Base(path) - - return d, f -} diff --git a/pref/using.go b/pref/using.go index f972151..29c91bb 100644 --- a/pref/using.go +++ b/pref/using.go @@ -1,9 +1,9 @@ package pref import ( + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/locale" ) @@ -86,12 +86,12 @@ func validate(using *Using) error { type ( TraverseFileSystemBuilder interface { - Build(root string) lfs.TraverseFS + Build(root string) nef.TraverseFS } - CreateTraverseFS func(root string) lfs.TraverseFS + CreateTraverseFS func(root string) nef.TraverseFS ) -func (fn CreateTraverseFS) Build(root string) lfs.TraverseFS { +func (fn CreateTraverseFS) Build(root string) nef.TraverseFS { return fn(root) } diff --git a/tapable/tapable_test.go b/tapable/tapable_test.go index 3e30a55..830dd55 100644 --- a/tapable/tapable_test.go +++ b/tapable/tapable_test.go @@ -7,11 +7,11 @@ import ( . "github.com/onsi/ginkgo/v2" //nolint:revive // ok . "github.com/onsi/gomega" //nolint:revive // ok + nef "github.com/snivilised/nefilim" tv "github.com/snivilised/traverse" "github.com/snivilised/traverse/core" lab "github.com/snivilised/traverse/internal/laboratory" "github.com/snivilised/traverse/internal/opts" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -212,7 +212,7 @@ var _ = Describe("Tapable", Ordered, func() { }, ) - sys := tv.NewReadDirFS(lfs.At{ + sys := tv.NewReadDirFS(nef.At{ Root: root, }) _, _ = o.Hooks.ReadDirectory.Default()(sys, root) diff --git a/traverse-api.go b/traverse-api.go index 2533aa2..33402b7 100644 --- a/traverse-api.go +++ b/traverse-api.go @@ -3,10 +3,10 @@ package tv import ( "time" + nef "github.com/snivilised/nefilim" "github.com/snivilised/traverse/core" "github.com/snivilised/traverse/enums" "github.com/snivilised/traverse/internal/filtering" - "github.com/snivilised/traverse/lfs" "github.com/snivilised/traverse/pref" ) @@ -54,19 +54,19 @@ type ( ResumeStrategy = enums.ResumeStrategy // ๐ŸŒ€ lfs - At = lfs.At - CopyFS = lfs.CopyFS - ExistsInFS = lfs.ExistsInFS - FileSystems = lfs.FileSystems - MakeDirFS = lfs.MakeDirFS - ReaderFS = lfs.ReaderFS - ReadFileFS = lfs.ReadFileFS - RemoveFS = lfs.RemoveFS - RenameFS = lfs.RenameFS - TraverseFS = lfs.TraverseFS - UniversalFS = lfs.UniversalFS - WriteFileFS = lfs.WriteFileFS - WriterFS = lfs.WriterFS + At = nef.At + CopyFS = nef.CopyFS + ExistsInFS = nef.ExistsInFS + FileSystems = nef.FileSystems + MakeDirFS = nef.MakeDirFS + ReaderFS = nef.ReaderFS + ReadFileFS = nef.ReadFileFS + RemoveFS = nef.RemoveFS + RenameFS = nef.RenameFS + TraverseFS = nef.TraverseFS + UniversalFS = nef.UniversalFS + WriteFileFS = nef.WriteFileFS + WriterFS = nef.WriterFS // ๐ŸŒ€ pref Option = pref.Option @@ -95,29 +95,29 @@ var ( // ๐ŸŒ€ lfs // NewReadDirFS creates a file system with read directory capability - NewReadDirFS = lfs.NewReadDirFS + NewReadDirFS = nef.NewReadDirFS // NewReaderFS creates a read only file system - NewReaderFS = lfs.NewReaderFS + NewReaderFS = nef.NewReaderFS // NewReadFileFS creates a file system with read file capability - NewReadFileFS = lfs.NewReadFileFS + NewReadFileFS = nef.NewReadFileFS // NewStatFS creates a file system with Stat method - NewStatFS = lfs.NewStatFS + NewStatFS = nef.NewStatFS // NewTraverseFS creates a file system that implements functionality required // by the traverse - NewTraverseFS = lfs.NewTraverseFS + NewTraverseFS = nef.NewTraverseFS // NewUniversalFS creates a file system that's got it all - NewUniversalFS = lfs.NewUniversalFS + NewUniversalFS = nef.NewUniversalFS // NewWriteFileFS creates a file system with write file capability - NewWriteFileFS = lfs.NewWriteFileFS + NewWriteFileFS = nef.NewWriteFileFS // NewWriterFS creates a file system with writer capabilities - NewWriterFS = lfs.NewWriterFS + NewWriterFS = nef.NewWriterFS // ๐ŸŒ€ filtering