Skip to content

Commit

Permalink
fix: deduced exec candidate has precedence over name
Browse files Browse the repository at this point in the history
  • Loading branch information
femnad committed Jan 4, 2024
1 parent 429f309 commit fd2b381
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 28 deletions.
9 changes: 5 additions & 4 deletions entity/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ func (r Release) ExpandURL(s settings.Settings) (string, error) {
return settings.ExpandStringWithLookup(s, r.Url, map[string]string{"version": version}), nil
}

func (r Release) ExpandSymlinks(maybeExec string) []NamedLink {
func (r Release) ExpandSymlinks(execCandidate string) []NamedLink {
var links []NamedLink
var expanded []NamedLink

name := r.Name()
if name == "" && maybeExec != "" {
name = maybeExec
name := execCandidate
if name == "" {
name = r.Name()
}

symlinks := r.Symlink
if len(r.NamedLink) == 0 && len(symlinks) == 0 && !r.DontLink && name != "" {
symlinks = []string{name}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

const (
version = "0.26.0"
version = "0.26.1"
)

type args struct {
Expand Down
2 changes: 1 addition & 1 deletion precheck/unless/unless.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func shouldSkip(unlessable Unlessable, s settings.Settings) bool {

if version == "" {
// No version specification, but command has succeeded so should skip the operation.
internal.Log.Debugf("%s has no version specification, assumming operation should be skipped", name)
internal.Log.Debugf("%s has no version specification, assuming operation should be skipped", name)
return true
}

Expand Down
18 changes: 11 additions & 7 deletions provision/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ type extractionHint struct {

type extractionFn func(entity.Release, extractionHint) (ReleaseInfo, error)

// ReleaseInfo stores an archive's root dir and species if the root dir is part of the archive files.
// ReleaseInfo stores an archive's root dir and specifies if the root dir is part of the archive files.
type ReleaseInfo struct {
execCandidate string
hasRootDir bool
maybeExec string
target string
targetOverride string
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func getReleaseInfo(archive entity.Release, entries []archiveEntry) (ReleaseInfo
}
}

var maybeExec string
var execCandidate string
var hasRootDir bool
var target string

Expand All @@ -302,10 +302,14 @@ func getReleaseInfo(archive entity.Release, entries []archiveEntry) (ReleaseInfo
}

if len(execs) == 1 {
maybeExec = execs[0].name
execCandidate = execs[0].name
}

return ReleaseInfo{hasRootDir: hasRootDir, maybeExec: maybeExec, target: target, targetOverride: archive.Target}, nil
return ReleaseInfo{
execCandidate: execCandidate,
hasRootDir: hasRootDir,
target: target,
targetOverride: archive.Target}, nil
}

func getOutputPath(info ReleaseInfo, fileName, dirName string) string {
Expand Down Expand Up @@ -490,7 +494,7 @@ func copyBinary(release entity.Release, hint extractionHint) (info ReleaseInfo,
return
}

return ReleaseInfo{hasRootDir: true, maybeExec: name, target: target}, nil
return ReleaseInfo{execCandidate: name, hasRootDir: true, target: target}, nil
}

func getExtractionFn(fileType string) (extractionFn, error) {
Expand Down Expand Up @@ -596,7 +600,7 @@ func ensureRelease(release entity.Release, s settings.Settings) error {
target, _ = path.Split(target)
target = path.Join(target, info.targetOverride)
}
for _, symlink := range release.ExpandSymlinks(info.maybeExec) {
for _, symlink := range release.ExpandSymlinks(info.execCandidate) {
err = createSymlink(symlink, target, s.GetBinPath())
if err != nil {
internal.Log.Errorf("error creating symlink for release %s: %v", releaseURL, err)
Expand Down
30 changes: 15 additions & 15 deletions provision/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ func Test_determineArchiveRoot(t *testing.T) {
}},
},
want: ReleaseInfo{
hasRootDir: true,
maybeExec: "dir/foo",
target: "dir",
execCandidate: "dir/foo",
hasRootDir: true,
target: "dir",
},
},
{
Expand All @@ -89,9 +89,9 @@ func Test_determineArchiveRoot(t *testing.T) {
}},
},
want: ReleaseInfo{
hasRootDir: false,
maybeExec: "foo",
target: "foo",
execCandidate: "foo",
hasRootDir: false,
target: "foo",
},
},
{
Expand All @@ -114,9 +114,9 @@ func Test_determineArchiveRoot(t *testing.T) {
},
},
want: ReleaseInfo{
hasRootDir: false,
maybeExec: "foo",
target: "qux",
execCandidate: "foo",
hasRootDir: false,
target: "qux",
},
},
{
Expand All @@ -138,9 +138,9 @@ func Test_determineArchiveRoot(t *testing.T) {
},
},
want: ReleaseInfo{
hasRootDir: false,
maybeExec: "foo",
target: "foo",
execCandidate: "foo",
hasRootDir: false,
target: "foo",
},
},
{
Expand All @@ -162,9 +162,9 @@ func Test_determineArchiveRoot(t *testing.T) {
},
},
want: ReleaseInfo{
hasRootDir: true,
maybeExec: "qux/baz/foo",
target: "qux",
execCandidate: "qux/baz/foo",
hasRootDir: true,
target: "qux",
},
},
}
Expand Down

0 comments on commit fd2b381

Please sign in to comment.