aboutsummaryrefslogtreecommitdiffstats
path: root/modules/storage
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-04-03 17:19:59 +0100
committerGitHub <noreply@github.com>2021-04-03 18:19:59 +0200
commit0bb8bd8190a7c3ec84b934642607e24058145b9e (patch)
treea26069b2548e053ef91f384697f8ff9cfb11a1c2 /modules/storage
parent3cc7d27b6f23628e1ecc9ac1e5f61728be73da76 (diff)
downloadgitea-0bb8bd8190a7c3ec84b934642607e24058145b9e.tar.gz
gitea-0bb8bd8190a7c3ec84b934642607e24058145b9e.zip
Add size to Save function (#15264)
Fix #15253 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/storage')
-rw-r--r--modules/storage/local.go2
-rw-r--r--modules/storage/minio.go4
-rw-r--r--modules/storage/storage.go13
3 files changed, 13 insertions, 6 deletions
diff --git a/modules/storage/local.go b/modules/storage/local.go
index 982d2b88c6..46e5d60e6b 100644
--- a/modules/storage/local.go
+++ b/modules/storage/local.go
@@ -66,7 +66,7 @@ func (l *LocalStorage) Open(path string) (Object, error) {
}
// Save a file
-func (l *LocalStorage) Save(path string, r io.Reader) (int64, error) {
+func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error) {
p := filepath.Join(l.dir, path)
if err := os.MkdirAll(filepath.Dir(p), os.ModePerm); err != nil {
return 0, err
diff --git a/modules/storage/minio.go b/modules/storage/minio.go
index 0e0cb3690d..724445c0ab 100644
--- a/modules/storage/minio.go
+++ b/modules/storage/minio.go
@@ -131,13 +131,13 @@ func (m *MinioStorage) Open(path string) (Object, error) {
}
// Save save a file to minio
-func (m *MinioStorage) Save(path string, r io.Reader) (int64, error) {
+func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error) {
uploadInfo, err := m.client.PutObject(
m.ctx,
m.bucket,
m.buildMinioPath(path),
r,
- -1,
+ size,
minio.PutObjectOptions{ContentType: "application/octet-stream"},
)
if err != nil {
diff --git a/modules/storage/storage.go b/modules/storage/storage.go
index ec3a1c14a1..65f8978e5a 100644
--- a/modules/storage/storage.go
+++ b/modules/storage/storage.go
@@ -65,7 +65,8 @@ type Object interface {
// ObjectStorage represents an object storage to handle a bucket and files
type ObjectStorage interface {
Open(path string) (Object, error)
- Save(path string, r io.Reader) (int64, error)
+ // Save store a object, if size is unknown set -1
+ Save(path string, r io.Reader, size int64) (int64, error)
Stat(path string) (os.FileInfo, error)
Delete(path string) error
URL(path, name string) (*url.URL, error)
@@ -80,7 +81,13 @@ func Copy(dstStorage ObjectStorage, dstPath string, srcStorage ObjectStorage, sr
}
defer f.Close()
- return dstStorage.Save(dstPath, f)
+ size := int64(-1)
+ fsinfo, err := f.Stat()
+ if err == nil {
+ size = fsinfo.Size()
+ }
+
+ return dstStorage.Save(dstPath, f, size)
}
// SaveFrom saves data to the ObjectStorage with path p from the callback
@@ -94,7 +101,7 @@ func SaveFrom(objStorage ObjectStorage, p string, callback func(w io.Writer) err
}
}()
- _, err := objStorage.Save(p, pr)
+ _, err := objStorage.Save(p, pr, -1)
return err
}