Skip to content

Commit

Permalink
for downloading object, be pessimistic and check how many bytes got c…
Browse files Browse the repository at this point in the history
…opied
  • Loading branch information
su47flying committed Feb 12, 2021
1 parent 7b09e30 commit 8932e32
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/objstore/objstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,17 @@ func DownloadFile(ctx context.Context, logger log.Logger, bkt BucketReader, src,
}()
defer runutil.CloseWithLogOnErr(logger, f, "download block's output file")

if _, err = io.Copy(f, rc); err != nil {
atts, err := bkt.Attributes(ctx, src)
if err != nil {
return errors.Wrapf(err, "attributes file %s", src)
}
copied, err := io.Copy(f, rc)
if err != nil {
return errors.Wrap(err, "copy object to file")
}
if copied != atts.Size {
return errors.Errorf("copy object to file %s. object length %v but got %v", src, atts.Size, copied)
}
return nil
}

Expand Down

0 comments on commit 8932e32

Please sign in to comment.