generated from snivilised/arcadia
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(proxy): implement dry run mode (#146)
- Loading branch information
1 parent
486d37c
commit 243098b
Showing
15 changed files
with
312 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package ipc | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/snivilised/cobrass/src/clif" | ||
"github.com/snivilised/extendio/xfs/storage" | ||
"github.com/snivilised/pixa/src/cfg" | ||
) | ||
|
||
type fakeAgent struct { | ||
baseAgent | ||
vfs storage.VirtualFS | ||
advanced cfg.AdvancedConfig | ||
} | ||
|
||
func (a *fakeAgent) IsInstalled() bool { | ||
_, err := a.program.Look() | ||
|
||
return err == nil | ||
} | ||
|
||
func (a *fakeAgent) Invoke(thirdPartyCL clif.ThirdPartyCommandLine, source, destination string) error { | ||
var ( | ||
err error | ||
fake *os.File | ||
) | ||
|
||
before := []string{source} | ||
|
||
if fake, err = a.vfs.Create(destination); err != nil { | ||
return err | ||
} | ||
|
||
// for this to work, the dry run decorator needs to be in place ... | ||
// | ||
fmt.Printf("---> 🚀 created fake destination at '%v'\n", destination) | ||
|
||
defer fake.Close() | ||
|
||
return a.program.Execute( | ||
clif.Expand(before, thirdPartyCL, destination)..., | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.