@@ -40,8 +40,9 @@ type source struct {
40
40
// repo is go.googlesource.com repo ("go", "net", and so on).
41
41
// rev is git revision.
42
42
//
43
- // ErrTooBig is returned if the response size exceeds a size that on 2021-05-25
44
- // was deemed to be enough to meet expected legitimate future needs for a while.
43
+ // An error of type TooBigError is returned if the compressed tarball exceeds a size that
44
+ // on 2021-11-22 was deemed to be enough to meet expected legitimate future needs for a while.
45
+ // See golang.org/issue/46379.
45
46
func GetSourceTgz (sl spanlog.Logger , repo , rev string ) (tgz io.Reader , err error ) {
46
47
sp := sl .CreateSpan ("get_source" , repo + "@" + rev )
47
48
defer func () { sp .Done (err ) }()
@@ -77,13 +78,22 @@ func GetSourceTgz(sl spanlog.Logger, repo, rev string) (tgz io.Reader, err error
77
78
return nil , err
78
79
}
79
80
if v .(source ).TooBig {
80
- return nil , ErrTooBig
81
+ return nil , TooBigError { Repo : repo , Rev : rev , Limit : maxSize ( repo )}
81
82
}
82
83
return bytes .NewReader (v .(source ).Tgz ), nil
83
84
}
84
85
85
- // ErrTooBig is the error returned when the source is considered too big.
86
- var ErrTooBig = fmt .Errorf ("rejected because compressed tarball exceeded a limit of %d MB; see golang.org/issue/46379" , maxSize / 1024 / 1024 )
86
+ // TooBigError is the error returned when the source revision is considered too big.
87
+ type TooBigError struct {
88
+ Repo string
89
+ Rev string
90
+ Limit int64 // Max size in bytes.
91
+ }
92
+
93
+ func (e TooBigError ) Error () string {
94
+ return fmt .Sprintf ("rejected because compressed tarball of repository go.googlesource.com/%s at revision %s exceeded a limit of %d MB; see golang.org/issue/46379" ,
95
+ e .Repo , e .Rev , e .Limit / 1024 / 1024 )
96
+ }
87
97
88
98
var gitMirrorClient * http.Client
89
99
@@ -139,8 +149,8 @@ func getSourceTgzFromURL(hc *http.Client, service, repo, rev, url string) (sourc
139
149
return source {}, fmt .Errorf ("fetching %s/%s from %s: %v; body: %s" , repo , rev , service , res .Status , slurp )
140
150
}
141
151
// See golang.org/issue/11224 for a discussion on tree filtering.
142
- b , err := ioutil .ReadAll (io .LimitReader (res .Body , maxSize + 1 ))
143
- if len (b ) > maxSize && err == nil {
152
+ b , err := ioutil .ReadAll (io .LimitReader (res .Body , maxSize ( repo ) + 1 ))
153
+ if int64 ( len (b )) > maxSize ( repo ) && err == nil {
144
154
return source {TooBig : true }, nil
145
155
}
146
156
if err != nil {
@@ -149,9 +159,24 @@ func getSourceTgzFromURL(hc *http.Client, service, repo, rev, url string) (sourc
149
159
return source {Tgz : b }, nil
150
160
}
151
161
152
- // maxSize is an artificial limit on how big of a source tarball this package is
153
- // is willing to accept. It's expected humans may need to manage it every couple
154
- // of years for the evolving needs of the Go project, and ideally not more often.
162
+ // maxSize controls artificial limits on how big of a compressed source tarball
163
+ // this package is willing to accept. It's expected humans may need to manage
164
+ // these limits every couple of years for the evolving needs of the Go project,
165
+ // and ideally not much more often.
155
166
//
156
- // As of 2021-05-25, a compressed tarball of x/website is 55 MB; Go source is 22 MB.
157
- const maxSize = 100 << 20
167
+ // repo is a go.googlesource.com repo ("go", "net", and so on).
168
+ func maxSize (repo string ) int64 {
169
+ switch repo {
170
+ default :
171
+ // As of 2021-11-22, a compressed tarball of Go source is 23 MB,
172
+ // x/net is 1.2 MB,
173
+ // x/build is 1.1 MB,
174
+ // x/tools is 2.9 MB.
175
+ return 100 << 20
176
+ case "website" :
177
+ // In 2021, all content in x/blog (52 MB) and x/talks (74 MB) moved
178
+ // to x/website. This makes x/website an outlier, with a compressed
179
+ // tarball size of 135 MB. Give it some room to grow from there.
180
+ return 200 << 20
181
+ }
182
+ }
0 commit comments