Skip to content

Commit

Permalink
fix(proxy): non transparent with output path finder unit tests (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Feb 17, 2024
1 parent b6983af commit 139a078
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/app/proxy/filing/filing-defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ func SupplementFilename(name, supp string, statics *common.StaticInfo) string {
return statics.FileSupplement(withoutExt, supp) + path.Ext(name)
}

func SupplementDirectory(directory, supp string) string {
func SupplementFolder(directory, supp string) string {
return filepath.Join(directory, supp)
}
66 changes: 25 additions & 41 deletions src/app/proxy/filing/path-finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func NewFinder(
finder := &PathFinder{
Sch: info.Scheme,
ExplicitProfile: info.Profile,
Arity: 1,
Stats: &common.StaticInfo{
Adhoc: advanced.AdhocLabel(),
Legacy: advanced.LegacyLabel(),
Expand Down Expand Up @@ -71,9 +70,7 @@ const (
pfPathUndefined pfPath = iota
pfPathInputTransferFolder
pfPathTxInputDestinationFolder
pfPathInputDestinationFileOriginalExt
pfPathResultFolder
pfPathResultFile
)

const (
Expand Down Expand Up @@ -120,17 +117,11 @@ func init() {
pfPathTxInputDestinationFolder: templateSegments{
"${{OUTPUT-ROOT}}",
},
pfPathInputDestinationFileOriginalExt: templateSegments{
"${{ITEM-FULL-NAME}}",
},
pfPathResultFolder: templateSegments{
"${{OUTPUT-ROOT}}",
"${{ITEM-SUB-PATH}}",
"${{SUPPLEMENT}}",
},
pfPathResultFile: templateSegments{
"${{RESULT-NAME}}",
},
}
}

Expand Down Expand Up @@ -194,19 +185,12 @@ type PathFinder struct {
// - full: (inline) -- item.parent
Output string
Trash string
Arity int
Ext *ExtensionTransformation
transparentInput bool
Stats *common.StaticInfo
}

func (f *PathFinder) init(info *NewFinderInfo) {
schemes := info.Schemes
if f.Sch != "" {
schemeCFG, _ := schemes.Scheme(f.Sch)
f.Arity = len(schemeCFG.Profiles())
}

f.Output = info.OutputPath
f.Trash = info.TrashPath

Expand Down Expand Up @@ -261,7 +245,15 @@ func (f *PathFinder) Scheme() string {
func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
folder = func() string {
if info.Cuddle {
return info.Origin
return info.Origin // should we return empty string here?
}

if info.Output != "" && info.Trash == "" {
// When output folder is specified, then the results will be diverted there.
// This means there is no need to transfer the input, unless trash has
// also been specified.
//
return ""
}

segments := pfTemplates[pfPathInputTransferFolder]
Expand All @@ -279,13 +271,21 @@ func (f *PathFinder) Transfer(info *common.PathInfo) (folder, file string) {
"${{TRANSFER-DESTINATION}}": to,
"${{ITEM-SUB-PATH}}": info.Item.Extension.SubPath,
"${{DEJA-VU}}": f.Stats.DejaVu(),
"${{SUPPLEMENT}}": f.folderSupplement(info.Profile),
"${{SUPPLEMENT}}": f.folderProfileSupplement(info.Profile),
}, segments...)
}()

file = func() string {
if info.Output != "" && info.Trash == "" {
// When output folder is specified, then the results will be diverted there.
// This means there is no need to transfer the input, unless trash has
// also been specified.
//
return ""
}

if info.Cuddle {
supp := fmt.Sprintf("%v.%v", f.Stats.DejaVu(), f.fileSupplement(info.Profile))
supp := fmt.Sprintf("%v.%v", f.Stats.DejaVu(), f.fileProfileSupplement(info.Profile))

return SupplementFilename(
info.Item.Extension.Name, supp, f.Stats,
Expand Down Expand Up @@ -340,7 +340,7 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
}, segments...)
},
func() string {
segments := pfTemplates[pfPathInputTransferFolder]
segments := pfTemplates[pfPathResultFolder]
to := lo.TernaryF(f.Output != "",
func() string {
return f.Output
Expand All @@ -350,27 +350,15 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
},
)
// If there is no scheme or profile, then the user is
// only relying flags on the command line, ie running adhoc
// only relying on flags on the command line, ie running adhoc
// so the result path should include an adhoc label. Otherwise,
// the result should reflect the supplementary path.
//

// if arity >1 then we need to use a different field list
// the current one below only works for arity=1.
// when arity > 1 we need the following:

/*
[0]:"${{TRANSFER-DESTINATION}}"
[1]:"${{ITEM-SUB-PATH}}"
[2]:"${{DEJA-VU}}"
[3]:"${{SUPPLEMENT}}"
[4]:"${{TRASH-LABEL}}"
*/

return pfTemplates.evaluate(pfFieldValues{
"${{OUTPUT-ROOT}}": to,
"${{SUPPLEMENT}}": f.folderSupplement(info.Profile),
"${{ITEM-SUB-PATH}}": info.Item.Extension.SubPath,
"${{SUPPLEMENT}}": f.folderProfileSupplement(info.Profile),
}, segments...)
},
)
Expand All @@ -380,17 +368,13 @@ func (f *PathFinder) Result(info *common.PathInfo) (folder, file string) {
// The file name just matches the input file name. The folder name
// provides the context.
//
segments := pfTemplates[pfPathResultFile]

return pfTemplates.evaluate(pfFieldValues{ // this looks like incorrect use of template (file!)
"${{RESULT-NAME}}": info.Item.Extension.Name,
}, segments...)
return info.Item.Extension.Name
}()

return folder, f.mutateExtension(file)
}

func (f *PathFinder) folderSupplement(profile string) string {
func (f *PathFinder) folderProfileSupplement(profile string) string {
return lo.TernaryF(f.Sch == "" && profile == "",
func() string {
adhocLabel := f.Stats.Adhoc
Expand All @@ -402,7 +386,7 @@ func (f *PathFinder) folderSupplement(profile string) string {
)
}

func (f *PathFinder) fileSupplement(profile string) string {
func (f *PathFinder) fileProfileSupplement(profile string) string {
var (
result string
)
Expand Down
Loading

0 comments on commit 139a078

Please sign in to comment.