mirror of
				https://github.com/go-gitea/gitea
				synced 2025-11-04 05:18:25 +00:00 
			
		
		
		
	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> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -30,7 +30,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
 | 
				
			||||||
@@ -58,6 +58,26 @@ type MinioStorage struct {
 | 
				
			|||||||
	basePath string
 | 
						basePath string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func convertMinioErr(err error) error {
 | 
				
			||||||
 | 
						if err == nil {
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						errResp, ok := err.(minio.ErrorResponse)
 | 
				
			||||||
 | 
						if !ok {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Convert two responses to standard analogues
 | 
				
			||||||
 | 
						switch errResp.Code {
 | 
				
			||||||
 | 
						case "NoSuchKey":
 | 
				
			||||||
 | 
							return os.ErrNotExist
 | 
				
			||||||
 | 
						case "AccessDenied":
 | 
				
			||||||
 | 
							return os.ErrPermission
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return err
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewMinioStorage returns a minio storage
 | 
					// NewMinioStorage returns a minio storage
 | 
				
			||||||
func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error) {
 | 
					func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error) {
 | 
				
			||||||
	configInterface, err := toConfig(MinioStorageConfig{}, cfg)
 | 
						configInterface, err := toConfig(MinioStorageConfig{}, cfg)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,11 @@ package routes
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"bytes"
 | 
						"bytes"
 | 
				
			||||||
	"encoding/gob"
 | 
						"encoding/gob"
 | 
				
			||||||
 | 
						"errors"
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
	"io"
 | 
						"io"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"path"
 | 
						"path"
 | 
				
			||||||
	"strings"
 | 
						"strings"
 | 
				
			||||||
	"text/template"
 | 
						"text/template"
 | 
				
			||||||
@@ -125,7 +128,13 @@ 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 {
 | 
				
			||||||
				ctx.Error(500, err.Error())
 | 
									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
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									log.Error("Error whilst getting URL for %s %s. Error: %v", prefix, rPath, err)
 | 
				
			||||||
 | 
									ctx.Error(500, fmt.Sprintf("Error whilst getting URL for %s %s", prefix, rPath))
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			http.Redirect(
 | 
								http.Redirect(
 | 
				
			||||||
@@ -152,7 +161,13 @@ 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 {
 | 
				
			||||||
			ctx.Error(500, err.Error())
 | 
								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
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								log.Error("Error whilst opening %s %s. Error: %v", prefix, rPath, err)
 | 
				
			||||||
 | 
								ctx.Error(500, fmt.Sprintf("Error whilst opening %s %s", prefix, rPath))
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		defer fr.Close()
 | 
							defer fr.Close()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user