forked from TrueCloudLab/restic
s3: Use streaming API and remove workarounds
This commit is contained in:
parent
68a91d66b7
commit
89ace85903
1 changed files with 2 additions and 56 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"restic"
|
"restic"
|
||||||
|
@ -197,53 +198,6 @@ func (be *Backend) Path() string {
|
||||||
return be.cfg.Prefix
|
return be.cfg.Prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
// nopCloserFile wraps *os.File and overwrites the Close() method with method
|
|
||||||
// that does nothing. In addition, the method Len() is implemented, which
|
|
||||||
// returns the size of the file (filesize - current offset).
|
|
||||||
type nopCloserFile struct {
|
|
||||||
*os.File
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f nopCloserFile) Close() error {
|
|
||||||
debug.Log("prevented Close()")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Len returns the remaining length of the file (filesize - current offset).
|
|
||||||
func (f nopCloserFile) Len() int {
|
|
||||||
debug.Log("Len() called")
|
|
||||||
fi, err := f.Stat()
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pos, err := f.Seek(0, io.SeekCurrent)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
size := fi.Size() - pos
|
|
||||||
debug.Log("returning file size %v", size)
|
|
||||||
return int(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
type lenner interface {
|
|
||||||
Len() int
|
|
||||||
io.Reader
|
|
||||||
}
|
|
||||||
|
|
||||||
// nopCloserLenner wraps a lenner and overwrites the Close() method with method
|
|
||||||
// that does nothing. In addition, the method Size() is implemented, which
|
|
||||||
// returns the size of the file (filesize - current offset).
|
|
||||||
type nopCloserLenner struct {
|
|
||||||
lenner
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *nopCloserLenner) Close() error {
|
|
||||||
debug.Log("prevented Close()")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save stores data in the backend at the handle.
|
// Save stores data in the backend at the handle.
|
||||||
func (be *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) {
|
func (be *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err error) {
|
||||||
debug.Log("Save %v", h)
|
debug.Log("Save %v", h)
|
||||||
|
@ -262,15 +216,7 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd io.Reader) (err
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent the HTTP client from closing a file
|
// prevent the HTTP client from closing a file
|
||||||
if f, ok := rd.(*os.File); ok {
|
rd = ioutil.NopCloser(rd)
|
||||||
debug.Log("reader is %#T, using nopCloserFile{}", rd)
|
|
||||||
rd = nopCloserFile{f}
|
|
||||||
} else if l, ok := rd.(lenner); ok {
|
|
||||||
debug.Log("reader is %#T, using nopCloserLenner{}", rd)
|
|
||||||
rd = nopCloserLenner{l}
|
|
||||||
} else {
|
|
||||||
debug.Log("reader is %#T, no specific workaround enabled", rd)
|
|
||||||
}
|
|
||||||
|
|
||||||
be.sem.GetToken()
|
be.sem.GetToken()
|
||||||
debug.Log("PutObject(%v, %v)", be.cfg.Bucket, objName)
|
debug.Log("PutObject(%v, %v)", be.cfg.Bucket, objName)
|
||||||
|
|
Loading…
Reference in a new issue