Skip to content

Commit

Permalink
Fixed installing binaries from URLs that have upper case letter. (#106)
Browse files Browse the repository at this point in the history
Thanks to @WiardJ for noticing.

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka authored Dec 21, 2021
1 parent c05be99 commit 85e49a7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
36 changes: 34 additions & 2 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,47 @@ func latestModVersion(listFile string) (_ string, err error) {
return lastVersion, nil
}

// encodePath returns the safe encoding of the given module path.
// It fails if the module path is invalid.
// Copied & modified from https://github.com/golang/go/blob/c54bc3448390d4ae4495d6d2c03c9dd4111b08f1/src/cmd/go/internal/module/module.go#L421
func encodePath(path string) string {
haveUpper := false
for _, r := range path {
if 'A' <= r && r <= 'Z' {
haveUpper = true
}
}

if !haveUpper {
return path
}

var buf []byte
for _, r := range path {
if 'A' <= r && r <= 'Z' {
buf = append(buf, '!', byte(r+'a'-'A'))
} else {
buf = append(buf, byte(r))
}
}
return string(buf)
}

// resolveInGoModCache will try to find a referenced module in the Go modules cache.
func resolveInGoModCache(logger *log.Logger, verbose bool, update runner.GetUpdatePolicy, target *bingo.Package) error {
modMetaCache := filepath.Join(gomodcache(), "cache/download")
modulePath := target.Path()
// Case sensitivity problem is fixed by replacing upper case with '/!<lower case letter>` signature.
// See https://tip.golang.org/cmd/go/#hdr-Module_proxy_protocol
lookupModulePath := encodePath(modulePath)

// Since we don't know which part of full path is package, which part is module.
// Start from longest and go until we find one.
for ; len(strings.Split(modulePath, "/")) > 2; modulePath = filepath.Dir(modulePath) {
modMetaDir := filepath.Join(modMetaCache, modulePath, "@v")
for ; len(strings.Split(lookupModulePath, "/")) > 2; func() {
lookupModulePath = filepath.Dir(lookupModulePath)
modulePath = filepath.Dir(modulePath)
}() {
modMetaDir := filepath.Join(modMetaCache, lookupModulePath, "@v")
if _, err := os.Stat(modMetaDir); err != nil {
if os.IsNotExist(err) {
if verbose {
Expand Down
2 changes: 1 addition & 1 deletion pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package version
import "github.com/Masterminds/semver"

// Version returns 'bingo' version.
const Version = "v0.5.1"
const Version = "v0.5.2"

var (
Go114 = semver.MustParse("1.14")
Expand Down

0 comments on commit 85e49a7

Please sign in to comment.