Skip to content

Commit 6f2dfca

Browse files
committed
add missing changes from backport go-gitea#13164
Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent d18344b commit 6f2dfca

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

modules/storage/local.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"path/filepath"
1313

14+
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/util"
1516
)
1617

@@ -39,7 +40,7 @@ func NewLocalStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
3940
return nil, err
4041
}
4142
config := configInterface.(LocalStorageConfig)
42-
43+
log.Info("Creating new Local Storage at %s", config.Path)
4344
if err := os.MkdirAll(config.Path, os.ModePerm); err != nil {
4445
return nil, err
4546
}

modules/storage/minio.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16+
"code.gitea.io/gitea/modules/log"
1617
"github.com/minio/minio-go/v7"
1718
"github.com/minio/minio-go/v7/pkg/credentials"
1819
)
@@ -82,16 +83,17 @@ func convertMinioErr(err error) error {
8283
func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error) {
8384
configInterface, err := toConfig(MinioStorageConfig{}, cfg)
8485
if err != nil {
85-
return nil, err
86+
return nil, convertMinioErr(err)
8687
}
8788
config := configInterface.(MinioStorageConfig)
8889

90+
log.Info("Creating Minio storage at %s:%s with base path %s", config.Endpoint, config.Bucket, config.BasePath)
8991
minioClient, err := minio.New(config.Endpoint, &minio.Options{
9092
Creds: credentials.NewStaticV4(config.AccessKeyID, config.SecretAccessKey, ""),
9193
Secure: config.UseSSL,
9294
})
9395
if err != nil {
94-
return nil, err
96+
return nil, convertMinioErr(err)
9597
}
9698

9799
if err := minioClient.MakeBucket(ctx, config.Bucket, minio.MakeBucketOptions{
@@ -100,7 +102,7 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
100102
// Check to see if we already own this bucket (which happens if you run this twice)
101103
exists, errBucketExists := minioClient.BucketExists(ctx, config.Bucket)
102104
if !exists || errBucketExists != nil {
103-
return nil, err
105+
return nil, convertMinioErr(err)
104106
}
105107
}
106108

@@ -121,7 +123,7 @@ func (m *MinioStorage) Open(path string) (Object, error) {
121123
var opts = minio.GetObjectOptions{}
122124
object, err := m.client.GetObject(m.ctx, m.bucket, m.buildMinioPath(path), opts)
123125
if err != nil {
124-
return nil, err
126+
return nil, convertMinioErr(err)
125127
}
126128
return &minioObject{object}, nil
127129
}
@@ -137,7 +139,7 @@ func (m *MinioStorage) Save(path string, r io.Reader) (int64, error) {
137139
minio.PutObjectOptions{ContentType: "application/octet-stream"},
138140
)
139141
if err != nil {
140-
return 0, err
142+
return 0, convertMinioErr(err)
141143
}
142144
return uploadInfo.Size, nil
143145
}
@@ -184,22 +186,26 @@ func (m *MinioStorage) Stat(path string) (os.FileInfo, error) {
184186
return nil, os.ErrNotExist
185187
}
186188
}
187-
return nil, err
189+
return nil, convertMinioErr(err)
188190
}
189191
return &minioFileInfo{info}, nil
190192
}
191193

192194
// Delete delete a file
193195
func (m *MinioStorage) Delete(path string) error {
194-
return m.client.RemoveObject(m.ctx, m.bucket, m.buildMinioPath(path), minio.RemoveObjectOptions{})
196+
if err := m.client.RemoveObject(m.ctx, m.bucket, m.buildMinioPath(path), minio.RemoveObjectOptions{}); err != nil {
197+
return convertMinioErr(err)
198+
}
199+
return nil
195200
}
196201

197202
// URL gets the redirect URL to a file. The presigned link is valid for 5 minutes.
198203
func (m *MinioStorage) URL(path, name string) (*url.URL, error) {
199204
reqParams := make(url.Values)
200205
// TODO it may be good to embed images with 'inline' like ServeData does, but we don't want to have to read the file, do we?
201206
reqParams.Set("response-content-disposition", "attachment; filename=\""+quoteEscaper.Replace(name)+"\"")
202-
return m.client.PresignedGetObject(m.ctx, m.bucket, m.buildMinioPath(path), 5*time.Minute, reqParams)
207+
u, err := m.client.PresignedGetObject(m.ctx, m.bucket, m.buildMinioPath(path), 5*time.Minute, reqParams)
208+
return u, convertMinioErr(err)
203209
}
204210

205211
// IterateObjects iterates across the objects in the miniostorage
@@ -213,13 +219,13 @@ func (m *MinioStorage) IterateObjects(fn func(path string, obj Object) error) er
213219
}) {
214220
object, err := m.client.GetObject(lobjectCtx, m.bucket, mObjInfo.Key, opts)
215221
if err != nil {
216-
return err
222+
return convertMinioErr(err)
217223
}
218224
if err := func(object *minio.Object, fn func(path string, obj Object) error) error {
219225
defer object.Close()
220226
return fn(strings.TrimPrefix(m.basePath, mObjInfo.Key), &minioObject{object})
221227
}(object, fn); err != nil {
222-
return err
228+
return convertMinioErr(err)
223229
}
224230
}
225231
return nil

0 commit comments

Comments
 (0)