fix(gateway): gracefully handle files with unknown sizes in directory listings
Steven Allen committed
Sep 26, 2019 at 12:34 UTC
e8a6c0c050e398a5b5f896770c7e79226eea6e4d
1 file changed
+6
-6
core/corehttp/gateway_handler.go
+6
-6
@@ -306,14 +306,14 @@ func (i *gatewayHandler) getOrHeadHandler(w http.ResponseWriter, r *http.Request
306
var dirListing []directoryItem
307
dirit := dir.Entries()
308
for dirit.Next() {
309
- // See comment above where originalUrlPath is declared.
310
- s, err := dirit.Node().Size()
311
- if err != nil {
312
- internalWebError(w, err)
313
- return
309
+ size := "?"
310
+ if s, err := dirit.Node().Size(); err == nil {
311
+ // Size may not be defined/supported. Continue anyways.
312
+ size = humanize.Bytes(uint64(s))
313
}
314
316
- di := directoryItem{humanize.Bytes(uint64(s)), dirit.Name(), gopath.Join(originalUrlPath, dirit.Name())}
315
+ // See comment above where originalUrlPath is declared.
316
+ di := directoryItem{size, dirit.Name(), gopath.Join(originalUrlPath, dirit.Name())}
317
dirListing = append(dirListing, di)
318
}
319
if dirit.Err() != nil {