mirror of
https://github.com/restic/restic.git
synced 2025-12-11 18:47:50 +00:00
azure/b2/gs/s3/swift: adapt cloud backend
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user