Skip to content

Commit 25b7766

Browse files
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>
1 parent 4cc8697 commit 25b7766

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

modules/storage/minio.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type minioObject struct {
3232
func (m *minioObject) Stat() (os.FileInfo, error) {
3333
oi, err := m.Object.Stat()
3434
if err != nil {
35-
return nil, err
35+
return nil, convertMinioErr(err)
3636
}
3737

3838
return &minioFileInfo{oi}, nil

routers/routes/routes.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package routes
77
import (
88
"bytes"
99
"encoding/gob"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"net/http"
@@ -127,7 +128,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
127128
rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix)
128129
u, err := objStore.URL(rPath, path.Base(rPath))
129130
if err != nil {
130-
if err == os.ErrNotExist {
131+
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
131132
log.Warn("Unable to find %s %s", prefix, rPath)
132133
ctx.Error(404, "file not found")
133134
return
@@ -160,7 +161,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
160161
//If we have matched and access to release or issue
161162
fr, err := objStore.Open(rPath)
162163
if err != nil {
163-
if err == os.ErrNotExist {
164+
if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) {
164165
log.Warn("Unable to find %s %s", prefix, rPath)
165166
ctx.Error(404, "file not found")
166167
return

0 commit comments

Comments
 (0)