From 1ee709c3ace46b0c208a47a209a0386688c65e23 Mon Sep 17 00:00:00 2001 From: plastikfan Date: Sat, 17 Feb 2024 18:27:50 +0000 Subject: [PATCH] fix(proxy,command): correct paths and remove dry run file creation (#172) --- src/app/proxy/enter-shrink.go | 10 +++- .../proxy/filing/dry-run-finder-decorator.go | 58 ------------------- src/app/proxy/filing/file-manager.go | 46 +++++++++------ src/app/proxy/filing/path-finder.go | 16 +---- src/app/proxy/filing/path-finder_test.go | 1 - src/app/proxy/pixa_test.go | 43 ++++++-------- 6 files changed, 54 insertions(+), 120 deletions(-) delete mode 100644 src/app/proxy/filing/dry-run-finder-decorator.go diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index 2683e58..a4b0631 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -43,6 +43,10 @@ func (e *ShrinkEntry) DiscoverOptionsFn(o *nav.TraverseOptions) { slog.String("presentation", presentation), ) + if e.Inputs.Root.PreviewFam.Native.DryRun { + return nil + } + return e.FileManager.Create(journal, false) }, } @@ -168,12 +172,14 @@ func EnterShrink( finder := filing.NewFinder(&filing.NewFinderInfo{ Advanced: params.Inputs.Root.Configs.Advanced, Schemes: params.Inputs.Root.Configs.Schemes, + Scheme: params.Inputs.Root.ProfileFam.Native.Scheme, OutputPath: params.Inputs.ParamSet.Native.OutputPath, TrashPath: params.Inputs.ParamSet.Native.TrashPath, - DryRun: params.Inputs.Root.PreviewFam.Native.DryRun, Observer: params.Inputs.Root.Observers.PathFinder, }) - fileManager := filing.NewManager(params.Vfs, finder) + fileManager := filing.NewManager(params.Vfs, finder, + params.Inputs.Root.PreviewFam.Native.DryRun, + ) if agent, err = ipc.New( params.Inputs.Root.Configs.Advanced, diff --git a/src/app/proxy/filing/dry-run-finder-decorator.go b/src/app/proxy/filing/dry-run-finder-decorator.go deleted file mode 100644 index 8309e0a..0000000 --- a/src/app/proxy/filing/dry-run-finder-decorator.go +++ /dev/null @@ -1,58 +0,0 @@ -package filing - -import ( - "path/filepath" - - "github.com/snivilised/extendio/xfs/nav" - "github.com/snivilised/pixa/src/app/proxy/common" -) - -func ComposeFake(name, label string) string { - return FilenameWithoutExtension(name) + label + filepath.Ext(name) -} - -type dryRunPathFinderDecorator struct { - decorated *PathFinder -} - -func (d *dryRunPathFinderDecorator) Transfer(info *common.PathInfo) (folder, file string) { - if d.decorated.TransparentInput() { - folder = info.Origin - file = info.Item.Extension.Name - } else { - folder, file = d.decorated.Transfer(info) - } - - return folder, file -} - -func (d *dryRunPathFinderDecorator) Result(info *common.PathInfo) (folder, file string) { - if d.decorated.TransparentInput() { - folder = info.Origin - file = ComposeFake(info.Item.Extension.Name, d.decorated.Statics().Fake) - } else { - folder, file = d.decorated.Result(info) - } - - return folder, file -} - -func (d *dryRunPathFinderDecorator) TransparentInput() bool { - return d.decorated.TransparentInput() -} - -func (d *dryRunPathFinderDecorator) JournalFullPath(item *nav.TraverseItem) string { - return d.decorated.JournalFullPath(item) -} - -func (d *dryRunPathFinderDecorator) Statics() *common.StaticInfo { - return d.decorated.Statics() -} - -func (d *dryRunPathFinderDecorator) Scheme() string { - return d.decorated.Scheme() -} - -func (d *dryRunPathFinderDecorator) Observe(t common.PathFinder) common.PathFinder { - return t -} diff --git a/src/app/proxy/filing/file-manager.go b/src/app/proxy/filing/file-manager.go index 04f1a18..c5e14f5 100644 --- a/src/app/proxy/filing/file-manager.go +++ b/src/app/proxy/filing/file-manager.go @@ -16,10 +16,11 @@ const ( errorDestination = "" ) -func NewManager(vfs storage.VirtualFS, finder common.PathFinder) common.FileManager { +func NewManager(vfs storage.VirtualFS, finder common.PathFinder, dryRun bool) common.FileManager { return &FileManager{ Vfs: vfs, finder: finder, + dryRun: dryRun, } } @@ -28,6 +29,7 @@ func NewManager(vfs storage.VirtualFS, finder common.PathFinder) common.FileMana type FileManager struct { Vfs storage.VirtualFS finder common.PathFinder + dryRun bool } func (fm *FileManager) Finder() common.PathFinder { @@ -66,31 +68,35 @@ func (fm *FileManager) Setup(pi *common.PathInfo) (destination string, err error // we don't want to rename/move the source... // if folder, file := fm.finder.Transfer(pi); folder != "" { - if err = fm.Vfs.MkdirAll(folder, perm); err != nil { - return errorDestination, errors.Wrapf( - err, "could not create parent setup for '%v'", pi.Item.Path, - ) + if !fm.dryRun { + if err = fm.Vfs.MkdirAll(folder, perm); err != nil { + return errorDestination, errors.Wrapf( + err, "could not create parent setup for '%v'", pi.Item.Path, + ) + } } destination = filepath.Join(folder, file) - if !fm.Vfs.FileExists(pi.Item.Path) { - return errorDestination, fmt.Errorf( - "source file: '%v' does not exist", pi.Item.Path, - ) - } - - if pi.Item.Path != destination { - if fm.Vfs.FileExists(destination) { + if !fm.dryRun { + if !fm.Vfs.FileExists(pi.Item.Path) { return errorDestination, fmt.Errorf( - "destination file: '%v' already exists", destination, + "source file: '%v' does not exist", pi.Item.Path, ) } - if err := fm.Vfs.Rename(pi.Item.Path, destination); err != nil { - return errorDestination, errors.Wrapf( - err, "could not complete setup for '%v'", pi.Item.Path, - ) + if pi.Item.Path != destination { + if fm.Vfs.FileExists(destination) { + return errorDestination, fmt.Errorf( + "destination file: '%v' already exists", destination, + ) + } + + if err := fm.Vfs.Rename(pi.Item.Path, destination); err != nil { + return errorDestination, errors.Wrapf( + err, "could not complete setup for '%v'", pi.Item.Path, + ) + } } } } @@ -99,6 +105,10 @@ func (fm *FileManager) Setup(pi *common.PathInfo) (destination string, err error } func (fm *FileManager) Tidy(pi *common.PathInfo) error { + if fm.dryRun { + return nil + } + journalFile := fm.finder.JournalFullPath(pi.Item) if !fm.Vfs.FileExists(journalFile) { diff --git a/src/app/proxy/filing/path-finder.go b/src/app/proxy/filing/path-finder.go index 3a2db5b..fc0d5fd 100644 --- a/src/app/proxy/filing/path-finder.go +++ b/src/app/proxy/filing/path-finder.go @@ -17,7 +17,6 @@ type NewFinderInfo struct { Profile string OutputPath string TrashPath string - DryRun bool Observer common.PathFinder } @@ -41,20 +40,7 @@ func NewFinder( }, } - finder.init(&NewFinderInfo{ - Advanced: info.Advanced, - Schemes: info.Schemes, - OutputPath: info.OutputPath, - TrashPath: info.TrashPath, - DryRun: info.DryRun, - Observer: info.Observer, - }) - - if info.DryRun { - return &dryRunPathFinderDecorator{ - decorated: finder, - } - } + finder.init(info) if info.Observer != nil { return info.Observer.Observe(finder) diff --git a/src/app/proxy/filing/path-finder_test.go b/src/app/proxy/filing/path-finder_test.go index 0da6581..61b7eaf 100644 --- a/src/app/proxy/filing/path-finder_test.go +++ b/src/app/proxy/filing/path-finder_test.go @@ -101,7 +101,6 @@ var _ = Describe("PathFinder", Ordered, func() { Scheme: entry.scheme, OutputPath: entry.output, TrashPath: entry.trash, - DryRun: entry.dry, }) origin := filepath.Join("foo", "sessions", "scan01") diff --git a/src/app/proxy/pixa_test.go b/src/app/proxy/pixa_test.go index d894055..bf0c1e7 100644 --- a/src/app/proxy/pixa_test.go +++ b/src/app/proxy/pixa_test.go @@ -13,10 +13,8 @@ import ( "github.com/snivilised/extendio/xfs/utils" "github.com/snivilised/pixa/src/app/command" "github.com/snivilised/pixa/src/app/proxy/common" - "github.com/snivilised/pixa/src/app/proxy/filing" "github.com/snivilised/pixa/src/internal/helpers" - "github.com/snivilised/pixa/src/internal/matchers" ) func openInputTTY() (*os.File, error) { @@ -47,7 +45,6 @@ type controllerTE struct { isTui bool dry bool intermediate string - withFake bool outputFlag string trashFlag string profile string @@ -99,21 +96,18 @@ func assertInFs(entry *samplerTE, ) { vfs := bs.Vfs - if entry.mandatory != nil && entry.dry { // - dejaVu := filepath.Join(DejaVu, entry.supplements.directory) - supplement := helpers.Path(entry.intermediate, dejaVu) + // this needs rework, to be done in another issue + // + // if entry.mandatory != nil { + // dejaVu := filepath.Join(DejaVu, entry.supplements.directory) + // supplement := helpers.Path(entry.intermediate, dejaVu) - for _, original := range entry.mandatory { - originalPath := filepath.Join(supplement, original) + // for _, original := range entry.mandatory { + // originalPath := filepath.Join(supplement, original) - if entry.withFake { - fake := filing.ComposeFake(original, bs.Configs.Advanced.FakeLabel()) - originalPath = filepath.Join(directory, fake) - } - - Expect(matchers.AsFile(originalPath)).To(matchers.ExistInFS(vfs)) - } - } + // Expect(matchers.AsFile(originalPath)).To(matchers.ExistInFS(vfs)) + // } + // } observer.assert(entry, directory, vfs) } @@ -240,7 +234,7 @@ var _ = Describe("pixa", Ordered, func() { intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01", supplements: supplements{ // file: "$SUPP/ADHOC.TRASH", - directory: "ADHOC/TRASH", + directory: "ADHOC", }, inputs: helpers.BackyardWorldsPlanet9Scan01First6, }, @@ -708,9 +702,8 @@ var _ = Describe("pixa", Ordered, func() { "--gaussian-blur", "0.51", "--interlace", "line", }, - dry: true, - withFake: true, - mandatory: helpers.BackyardWorldsPlanet9Scan01First6, + dry: true, + // mandatory: helpers.BackyardWorldsPlanet9Scan01First6, intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01", supplements: supplements{ // file: "$SUPP/ADHOC.TRASH", @@ -730,9 +723,8 @@ var _ = Describe("pixa", Ordered, func() { "--gaussian-blur", "0.51", "--interlace", "line", }, - dry: true, - withFake: true, - mandatory: helpers.BackyardWorldsPlanet9Scan01First6, + dry: true, + // mandatory: helpers.BackyardWorldsPlanet9Scan01First6, intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01", supplements: supplements{ // file: "$SUPP/ADHOC.TRASH", @@ -753,9 +745,8 @@ var _ = Describe("pixa", Ordered, func() { "--gaussian-blur", "0.51", "--interlace", "line", }, - dry: true, - withFake: true, - mandatory: helpers.BackyardWorldsPlanet9Scan01First6, + dry: true, + // mandatory: helpers.BackyardWorldsPlanet9Scan01First6, intermediate: "nasa/exo/Backyard Worlds - Planet 9/sessions/scan-01", supplements: supplements{ // file: "$SUPP/ADHOC.TRASH",