forked from TrueCloudLab/restic
azure/b2/gs/s3/swift: adapt cloud backend
This commit is contained in:
parent
e793c002ec
commit
d40f23e716
5 changed files with 116 additions and 3 deletions
|
@ -153,7 +153,18 @@ func (be *beSwift) openReader(ctx context.Context, h backend.Handle, length int,
|
|||
|
||||
obj, _, err := be.conn.ObjectOpen(ctx, be.container, objName, false, headers)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "conn.ObjectOpen")
|
||||
return nil, fmt.Errorf("conn.ObjectOpen: %w", err)
|
||||
}
|
||||
|
||||
if length > 0 {
|
||||
// get response length, but don't cause backend calls
|
||||
cctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
objLength, e := obj.Length(cctx)
|
||||
if e == nil && objLength != int64(length) {
|
||||
_ = obj.Close()
|
||||
return nil, &swift.Error{StatusCode: http.StatusRequestedRangeNotSatisfiable, Text: "restic-file-too-short"}
|
||||
}
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
|
@ -242,6 +253,21 @@ func (be *beSwift) IsNotExist(err error) bool {
|
|||
return errors.As(err, &e) && e.StatusCode == http.StatusNotFound
|
||||
}
|
||||
|
||||
func (be *beSwift) IsPermanentError(err error) bool {
|
||||
if be.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
var serr *swift.Error
|
||||
if errors.As(err, &serr) {
|
||||
if serr.StatusCode == http.StatusRequestedRangeNotSatisfiable || serr.StatusCode == http.StatusUnauthorized || serr.StatusCode == http.StatusForbidden {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Delete removes all restic objects in the container.
|
||||
// It will not remove the container itself.
|
||||
func (be *beSwift) Delete(ctx context.Context) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue