]> source.dussan.org Git - gitea.git/commitdiff
When handling errors in storageHandler check underlying error (#13178)
authorzeripath <art27@cantab.net>
Sun, 18 Oct 2020 01:29:06 +0000 (02:29 +0100)
committerGitHub <noreply@github.com>
Sun, 18 Oct 2020 01:29:06 +0000 (21:29 -0400)
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>
modules/storage/minio.go
routers/routes/routes.go

index 4a2819de5ef37c8faf0d3107e6fa78b9c5feb634..0e0cb3690da64d21c21cad0a00755cd879c16651 100644 (file)
@@ -32,7 +32,7 @@ type minioObject struct {
 func (m *minioObject) Stat() (os.FileInfo, error) {
        oi, err := m.Object.Stat()
        if err != nil {
-               return nil, err
+               return nil, convertMinioErr(err)
        }
 
        return &minioFileInfo{oi}, nil
index adda919857630cd78e13f7579dc3ee351484e898..9f7ff277cf0d4e6f6753cb38179f11f99db4cb4e 100644 (file)
@@ -7,6 +7,7 @@ package routes
 import (
        "bytes"
        "encoding/gob"
+       "errors"
        "fmt"
        "io"
        "net/http"
@@ -127,7 +128,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
                        rPath := strings.TrimPrefix(req.RequestURI, "/"+prefix)
                        u, err := objStore.URL(rPath, path.Base(rPath))
                        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)
                                        ctx.Error(404, "file not found")
                                        return
@@ -160,7 +161,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
                //If we have matched and access to release or issue
                fr, err := objStore.Open(rPath)
                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)
                                ctx.Error(404, "file not found")
                                return