Skip to content

Commit

Permalink
Fix 'file name too long' errors on darwin (bazelbuild#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
bduffany authored Feb 1, 2023
1 parent de8e903 commit 990c873
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package core

import (
"bufio"
"crypto/sha256"
"fmt"
"io"
"io/ioutil"
Expand All @@ -30,6 +31,7 @@ const (
skipWrapperEnv = "BAZELISK_SKIP_WRAPPER"
wrapperPath = "./tools/bazel"
rcFileName = ".bazeliskrc"
maxDirLength = 255
)

var (
Expand Down Expand Up @@ -729,5 +731,12 @@ func migrate(bazelPath string, baseArgs []string, flags []string) {

func dirForURL(url string) string {
// Replace all characters that might not be allowed in filenames with "-".
return regexp.MustCompile("[[:^alnum:]]").ReplaceAllString(url, "-")
dir := regexp.MustCompile("[[:^alnum:]]").ReplaceAllString(url, "-")
// Work around length limit on some systems by truncating and then appending
// a sha256 hash of the URL.
if len(dir) > maxDirLength {
suffix := fmt.Sprintf("...%x", sha256.Sum256([]byte(url)))
dir = dir[:maxDirLength-len(suffix)] + suffix
}
return dir
}

0 comments on commit 990c873

Please sign in to comment.