From 24b8784d71096f3dfa38d6533a770f45a49cda43 Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Tue, 4 Feb 2020 17:17:45 +0100 Subject: [PATCH] Ensure that binaries downloaded with BAZELISK_BASE_URL set are put into mirror-specific cache folders. FYI @ali5h --- bazelisk.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bazelisk.go b/bazelisk.go index d008c5a7..902862cf 100644 --- a/bazelisk.go +++ b/bazelisk.go @@ -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 { @@ -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)