Skip to content

Commit

Permalink
fix(proxy,command): correct paths and remove dry run file creation (#172
Browse files Browse the repository at this point in the history
)
  • Loading branch information
plastikfan committed Feb 17, 2024
1 parent 6ef4f47 commit 1ee709c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 120 deletions.
10 changes: 8 additions & 2 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}
Expand Down Expand Up @@ -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,
Expand Down
58 changes: 0 additions & 58 deletions src/app/proxy/filing/dry-run-finder-decorator.go

This file was deleted.

46 changes: 28 additions & 18 deletions src/app/proxy/filing/file-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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,
)
}
}
}
}
Expand All @@ -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) {
Expand Down
16 changes: 1 addition & 15 deletions src/app/proxy/filing/path-finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type NewFinderInfo struct {
Profile string
OutputPath string
TrashPath string
DryRun bool
Observer common.PathFinder
}

Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/app/proxy/filing/path-finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
43 changes: 17 additions & 26 deletions src/app/proxy/pixa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -47,7 +45,6 @@ type controllerTE struct {
isTui bool
dry bool
intermediate string
withFake bool
outputFlag string
trashFlag string
profile string
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 1ee709c

Please sign in to comment.