1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-14 14:37:20 +00:00

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

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:
techknowlogick
2020-10-18 10:52:03 -04:00
committed by GitHub
parent 1ba4a7ec16
commit aca13f941c
2 changed files with 38 additions and 3 deletions

View File

@ -30,7 +30,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
@ -58,6 +58,26 @@ type MinioStorage struct {
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
func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error) {
configInterface, err := toConfig(MinioStorageConfig{}, cfg)