forked from TrueCloudLab/rclone
swift: fix upload when using no_chunk to return the correct size
When using the VFS with swift and --swift-no-chunk, PutStream was returning objects with size -1 which was causing corrupted transfer messages. This was fixed by counting the bytes transferred in a streamed file and updating the metadata with that.
This commit is contained in:
parent
fdef567da6
commit
9e81fc343e
2 changed files with 66 additions and 0 deletions
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/rclone/rclone/fs/operations"
|
||||
"github.com/rclone/rclone/fs/walk"
|
||||
"github.com/rclone/rclone/lib/pacer"
|
||||
"github.com/rclone/rclone/lib/readers"
|
||||
)
|
||||
|
||||
// Constants
|
||||
|
@ -1224,8 +1225,13 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||
}
|
||||
o.headers = nil // wipe old metadata
|
||||
} else {
|
||||
var inCount *readers.CountingReader
|
||||
if size >= 0 {
|
||||
headers["Content-Length"] = strconv.FormatInt(size, 10) // set Content-Length if we know it
|
||||
} else {
|
||||
// otherwise count the size for later
|
||||
inCount = readers.NewCountingReader(in)
|
||||
in = inCount
|
||||
}
|
||||
var rxHeaders swift.Headers
|
||||
err = o.fs.pacer.CallNoRetry(func() (bool, error) {
|
||||
|
@ -1242,6 +1248,10 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
|
|||
o.md5 = rxHeaders["ETag"]
|
||||
o.contentType = contentType
|
||||
o.headers = headers
|
||||
if inCount != nil {
|
||||
// update the size if streaming from the reader
|
||||
o.size = int64(inCount.BytesRead())
|
||||
}
|
||||
}
|
||||
|
||||
// If file was a dynamic large object then remove old/all segments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue