When handling errors in storageHandler check underlying error (#13178)

Unfortunately there was a mistake in #13164 which fails to handle
os.PathError wrapping an os.ErrNotExist

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
tokarchuk/v1.17
zeripath 4 years ago committed by GitHub
parent 4cc8697a65
commit 25b7766673
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/storage/minio.go
  2. 5
      routers/routes/routes.go

@ -32,7 +32,7 @@ type minioObject struct {
func (m *minioObject) Stat() (os.FileInfo, error) { func (m *minioObject) Stat() (os.FileInfo, error) {
oi, err := m.Object.Stat() oi, err := m.Object.Stat()
if err != nil { if err != nil {
return nil, err return nil, convertMinioErr(err)
} }
return &minioFileInfo{oi}, nil return &minioFileInfo{oi}, nil

@ -7,6 +7,7 @@ package routes
import ( import (
"bytes" "bytes"
"encoding/gob" "encoding/gob"
"errors"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -127,7 +128,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix) rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix)
u, err := objStore.URL(rPath, path.Base(rPath)) u, err := objStore.URL(rPath, path.Base(rPath))
if err != nil { if err != nil {
if err == os.ErrNotExist { if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
log.Warn("Unable to find %s %s", prefix, rPath) log.Warn("Unable to find %s %s", prefix, rPath)
ctx.Error(404, "file not found") ctx.Error(404, "file not found")
return return
@ -160,7 +161,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
//If we have matched and access to release or issue //If we have matched and access to release or issue
fr, err := objStore.Open(rPath) fr, err := objStore.Open(rPath)
if err != nil { if err != nil {
if err == os.ErrNotExist { if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
log.Warn("Unable to find %s %s", prefix, rPath) log.Warn("Unable to find %s %s", prefix, rPath)
ctx.Error(404, "file not found") ctx.Error(404, "file not found")
return return

Loading…
Cancel
Save