Skip to content

Commit

Permalink
Fix conditional write when generation = 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiggoha committed Dec 14, 2023
1 parent d0688e1 commit c5b0dcc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion experimental/gcp-log/internal/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ func (c *Client) WriteCheckpoint(ctx context.Context, newCPRaw []byte) error {
bkt := c.gcsClient.Bucket(c.bucket)
obj := bkt.Object(layout.CheckpointPath)

w := obj.If(gcs.Conditions{GenerationMatch: c.checkpointGen}).NewWriter(ctx)
var cond gcs.Conditions
if c.checkpointGen == 0 {
cond = gcs.Conditions{DoesNotExist: true}
} else {
cond = gcs.Conditions{GenerationMatch: c.checkpointGen}
}

w := obj.If(cond).NewWriter(ctx)
if _, err := w.Write(newCPRaw); err != nil {
return err
}
Expand Down

0 comments on commit c5b0dcc

Please sign in to comment.