Skip to content

Commit

Permalink
Merge pull request #23 from Futrime/hotfix/issue-22
Browse files Browse the repository at this point in the history
Fix #22
  • Loading branch information
futrime authored Jan 25, 2023
2 parents eaf94d7 + e03f231 commit f670465
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func Run() {
return
}

isMatched := false
selectVersion:
for _, version := range versionList {
for _, innerVersionRange := range versionRange {
Expand All @@ -164,15 +165,18 @@ func Run() {
return
}
specifiersToFetch.PushBack(specifier)
isMatched = true
break selectVersion
}
}
}
}

// If no version is selected, error.
logger.Error("no version of " + toothPath + " matches the requirement of " + specifier.String())
return
if !isMatched {
// If no version is selected, error.
logger.Error("no version of " + toothPath + " matches the requirement of " + specifier.String())
return
}
}
}

Expand Down
24 changes: 19 additions & 5 deletions src/cmd/install/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ func downloadTooth(specifier Specifier) (string, error) {
}

// Get the tooth file url.
url := context.Goproxy + "/" + specifier.ToothRepo() + "/@v/v" + specifier.ToothVersion().String() + "+incompatible.zip"
urlSuffix := "+incompatible.zip"
if strings.HasPrefix(specifier.ToothVersion().String(), "0.") || strings.HasPrefix(specifier.ToothVersion().String(), "1.") {
urlSuffix = ".zip"
}
url := context.Goproxy + "/" + specifier.ToothRepo() + "/@v/v" + specifier.ToothVersion().String() + urlSuffix

// Download the tooth file to the cache.
cacheDir, err := localfile.CacheDir()
Expand Down Expand Up @@ -120,10 +124,13 @@ func fetchVersionList(repoPath string) ([]versionutils.Version, error) {

url := context.Goproxy + "/" + repoPath + "/@v/list"

// To lowercases.
url = strings.ToLower(url)

// Get the version list.
resp, err := http.Get(url)
if err != nil {
return nil, errors.New("cannot access GOPROXY: " + repoPath)
return nil, errors.New("cannot access GOPROXY: " + context.Goproxy)
}
defer resp.Body.Close()

Expand Down Expand Up @@ -247,7 +254,7 @@ func install(t toothfile.ToothFile) error {

// isValidRepoPath checks if the repoPath is valid.
func isValidRepoPath(repoPath string) bool {
reg := regexp.MustCompile(`^[a-z0-9][a-z0-9-_\.\/]*$`)
reg := regexp.MustCompile(`^[a-zA-Z\d-_\.\/]*$`)

// If not matched or the matched string is not the same as the specifier, it is an
// invalid requirement specifier.
Expand All @@ -261,12 +268,19 @@ func validateToothRepoVersion(repoPath string, version versionutils.Version) err
}

// Check if the version is valid.
url := context.Goproxy + "/" + repoPath + "/@v/v" + version.String() + "+incompatible.info"
urlSuffix := "+incompatible.info"
if strings.HasPrefix(version.String(), "0.") || strings.HasPrefix(version.String(), "1.") {
urlSuffix = ".info"
}
url := context.Goproxy + "/" + repoPath + "/@v/v" + version.String() + urlSuffix

// To lower case.
url = strings.ToLower(url)

// Get the version information.
resp, err := http.Get(url)
if err != nil {
return errors.New("cannot access GOPROXY: " + repoPath)
return errors.New("cannot access GOPROXY: " + context.Goproxy)
}
defer resp.Body.Close()

Expand Down

0 comments on commit f670465

Please sign in to comment.