Skip to content

Commit

Permalink
Ensure that binaries downloaded with BAZELISK_BASE_URL set are put in…
Browse files Browse the repository at this point in the history
…to mirror-specific cache folders.

FYI @ali5h
  • Loading branch information
philwo committed Feb 4, 2020
1 parent 05f5542 commit 24b8784
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bazelisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ func getSortedKeys(data map[string]*flagDetails) []string {
return result
}

func dirForURL(url string) string {
// Replace all characters that might not be allowed in filenames with "-".
return regexp.MustCompile("[[:^alnum:]]").ReplaceAllString(url, "-")
}

func main() {
bazeliskHome := os.Getenv("BAZELISK_HOME")
if len(bazeliskHome) == 0 {
Expand Down Expand Up @@ -769,7 +774,12 @@ func main() {
log.Fatalf("could not resolve the version '%s' to an actual version number: %v", bazelVersion, err)
}

bazelDirectory := filepath.Join(bazeliskHome, "bin", bazelFork)
bazelForkOrURL := dirForURL(os.Getenv("BAZELISK_BASE_URL"))
if len(bazelForkOrURL) == 0 {
bazelForkOrURL = bazelFork
}

bazelDirectory := filepath.Join(bazeliskHome, "bin", bazelForkOrURL)
err = os.MkdirAll(bazelDirectory, 0755)
if err != nil {
log.Fatalf("could not create directory %s: %v", bazelDirectory, err)
Expand Down

0 comments on commit 24b8784

Please sign in to comment.