mirror of https://github.com/go-gitea/gitea.git
Fix read size
This commit is contained in:
parent
8dcf589c65
commit
c3f1090719
|
@ -6,11 +6,8 @@ package setting
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
// StorageType is a type of Storage
|
||||
|
@ -75,17 +72,6 @@ type AzureBlobStorageConfig struct {
|
|||
ServeDirect bool `ini:"SERVE_DIRECT"`
|
||||
}
|
||||
|
||||
func (cfg AzureBlobStorageConfig) ConnectionString() string {
|
||||
u, err := url.Parse(cfg.Endpoint)
|
||||
if err != nil {
|
||||
log.Fatal("parse endpoint %s failed: %v", cfg.Endpoint, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("DefaultEndpointsProtocol=%s;AccountName=%s;AccountKey=%s;EndpointSuffix=%s",
|
||||
u.Scheme, cfg.AccountName, cfg.AccountKey, u.Host)
|
||||
}
|
||||
|
||||
func (cfg *AzureBlobStorageConfig) ToShadow() {
|
||||
if cfg.AccountKey != "" {
|
||||
cfg.AccountKey = "******"
|
||||
|
|
|
@ -182,18 +182,19 @@ func (a *AzureBlobStorage) Open(path string) (Object, error) {
|
|||
|
||||
// Save saves a file to azure blob storage
|
||||
func (a *AzureBlobStorage) Save(path string, r io.Reader, size int64) (int64, error) {
|
||||
rd := util.NewCountingReader(r)
|
||||
_, err := a.client.UploadStream(
|
||||
a.ctx,
|
||||
a.cfg.Container,
|
||||
a.buildAzureBlobPath(path),
|
||||
r,
|
||||
rd,
|
||||
// TODO: support set block size and concurrency
|
||||
&blockblob.UploadStreamOptions{},
|
||||
)
|
||||
if err != nil {
|
||||
return 0, convertAzureBlobErr(err)
|
||||
}
|
||||
return size, nil
|
||||
return int64(rd.Count()), nil
|
||||
}
|
||||
|
||||
type azureBlobFileInfo struct {
|
||||
|
|
|
@ -76,3 +76,24 @@ func IsEmptyReader(r io.Reader) (err error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
type CountingReader struct {
|
||||
io.Reader
|
||||
n int
|
||||
}
|
||||
|
||||
var _ io.Reader = &CountingReader{}
|
||||
|
||||
func (w *CountingReader) Count() int {
|
||||
return w.n
|
||||
}
|
||||
|
||||
func (w *CountingReader) Read(p []byte) (int, error) {
|
||||
n, err := w.Reader.Read(p)
|
||||
w.n += n
|
||||
return n, err
|
||||
}
|
||||
|
||||
func NewCountingReader(rd io.Reader) *CountingReader {
|
||||
return &CountingReader{Reader: rd}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ func saveUploadChunkBase(st storage.ObjectStorage, ctx *ArtifactContext,
|
|||
}
|
||||
}
|
||||
if writtenSize != contentSize {
|
||||
checkErr = errors.Join(checkErr, fmt.Errorf("contentSize not match body size"))
|
||||
checkErr = errors.Join(checkErr, fmt.Errorf("writtenSize %d not match contentSize %d", writtenSize, contentSize))
|
||||
}
|
||||
if checkErr != nil {
|
||||
if err := st.Delete(storagePath); err != nil {
|
||||
|
|
Loading…
Reference in New Issue