Skip to content

Commit

Permalink
chore(storage): refactor read conditions (#4929)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz committed Oct 5, 2021
1 parent 76f0014 commit 07c804b
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions storage/reader.go
Expand Up @@ -30,7 +30,6 @@ import (
"cloud.google.com/go/internal/trace"
"google.golang.org/api/googleapi"
storagepb "google.golang.org/genproto/googleapis/storage/v2"
"google.golang.org/protobuf/proto"
)

var crc32cTable = crc32.MakeTable(crc32.Castagnoli)
Expand Down Expand Up @@ -475,8 +474,10 @@ func (o *ObjectHandle) newRangeReaderWithGRPC(ctx context.Context, offset, lengt
}
req.ReadOffset = start

// TODO: refactor this to use applyCondsProto.
setRequestConditions(req, o.conds)
if err := applyCondsProto("reopenWithGRPC", o.gen, o.conds, req); err != nil {
cancel()
return nil, nil, err
}

var stream storagepb.Storage_ReadObjectClient
var msg *storagepb.ReadObjectResponse
Expand Down Expand Up @@ -681,29 +682,6 @@ func (r *Reader) reopenStream(seen int64) (*storagepb.ReadObjectResponse, error)
return res.response, nil
}

// setRequestConditions is used to apply the given Conditions to a gRPC request
// message.
//
// This is an experimental API and not intended for public use.
func setRequestConditions(req *storagepb.ReadObjectRequest, conds *Conditions) {
if conds == nil {
return
}
if conds.MetagenerationMatch != 0 {
req.IfMetagenerationMatch = proto.Int64(conds.MetagenerationMatch)
} else if conds.MetagenerationNotMatch != 0 {
req.IfMetagenerationNotMatch = proto.Int64(conds.MetagenerationNotMatch)
}
switch {
case conds.GenerationNotMatch != 0:
req.IfGenerationNotMatch = proto.Int64(conds.GenerationNotMatch)
case conds.GenerationMatch != 0:
req.IfGenerationMatch = proto.Int64(conds.GenerationMatch)
case conds.DoesNotExist:
req.IfGenerationMatch = proto.Int64(0)
}
}

// Size returns the size of the object in bytes.
// The returned value is always the same and is not affected by
// calls to Read or Close.
Expand Down

0 comments on commit 07c804b

Please sign in to comment.