internal/sourcecache: double size limit for repository source

The x/website repository is getting bigger as x/blog is being
merged into it. The 50 MB size limit has lasted many years.
Hopefully doubling it will too.

Make the error message more detailed so it's easier to tell
that the limit is in x/build code rather than elsewhere.

Fixes golang/go#46379.

Change-Id: I4c89fb0ae3d706a13537e2f6c898aed2efd959b7
Reviewed-on: https://go-review.googlesource.com/c/build/+/322658
Trust: Dmitri Shuralyov <dmitshur@golang.org>
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
Dmitri Shuralyov 2021-05-25 22:24:22 -04:00
Родитель b5eec30959
Коммит b496187191
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -122,10 +122,10 @@ func getSourceTgzFromURL(hc *http.Client, source, repo, rev, urlStr string) (tgz
return nil, fmt.Errorf("fetching %s/%s from %s: %v; body: %s", repo, rev, source, res.Status, slurp)
}
// TODO(bradfitz): finish golang.org/issue/11224
const maxSize = 50 << 20 // talks repo is over 25MB; go source is 7.8MB on 2015-06-15
const maxSize = 100 << 20 // As of 2021-05-25, a compressed tarball of x/website is 55 MB; Go source is 22 MB.
slurp, err := ioutil.ReadAll(io.LimitReader(res.Body, maxSize+1))
if len(slurp) > maxSize && err == nil {
err = fmt.Errorf("body over %d bytes", maxSize)
err = fmt.Errorf("rejected because body exceeded a limit of %d MB; see golang.org/issue/46379", maxSize/1024/1024)
}
if err != nil {
return nil, fmt.Errorf("reading %s/%s from %s: %v", repo, rev, source, err)