mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
azure/b2/gs/s3/swift: adapt cloud backend
This commit is contained in:
@@ -167,6 +167,20 @@ func (be *Backend) IsNotExist(err error) bool {
|
||||
return bloberror.HasCode(err, bloberror.BlobNotFound)
|
||||
}
|
||||
|
||||
func (be *Backend) IsPermanentError(err error) bool {
|
||||
if be.IsNotExist(err) {
|
||||
return true
|
||||
}
|
||||
|
||||
var aerr *azcore.ResponseError
|
||||
if errors.As(err, &aerr) {
|
||||
if aerr.StatusCode == http.StatusRequestedRangeNotSatisfiable || aerr.StatusCode == http.StatusUnauthorized || aerr.StatusCode == http.StatusForbidden {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Join combines path components with slashes.
|
||||
func (be *Backend) Join(p ...string) string {
|
||||
return path.Join(p...)
|
||||
@@ -313,6 +327,11 @@ func (be *Backend) openReader(ctx context.Context, h backend.Handle, length int,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if length > 0 && (resp.ContentLength == nil || *resp.ContentLength != int64(length)) {
|
||||
_ = resp.Body.Close()
|
||||
return nil, &azcore.ResponseError{ErrorCode: "restic-file-too-short", StatusCode: http.StatusRequestedRangeNotSatisfiable}
|
||||
}
|
||||
|
||||
return resp.Body, err
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user