in util/gcs/fake/fake.go [41:79]
func (cc *ConditionalClient) check(ctx context.Context, from, to *gcs.Path) error {
if from != nil && cc.read != nil {
attrs, err := cc.UploadClient.Stat(ctx, *from)
switch {
case err != nil:
return err
case cc.read.GenerationMatch != 0 && cc.read.GenerationMatch != attrs.Generation:
return fmt.Errorf("bad genneration due to GenerationMatch: %w", &googleapi.Error{
Code: http.StatusPreconditionFailed,
})
case cc.read.GenerationNotMatch != 0 && cc.read.GenerationNotMatch == attrs.Generation:
return fmt.Errorf("bad generation due to GenerationNotMatch: %w", &googleapi.Error{
Code: http.StatusPreconditionFailed,
})
}
}
if to != nil && cc.write != nil {
attrs, err := cc.UploadClient.Stat(ctx, *to)
switch {
case err == storage.ErrObjectNotExist:
if cc.write.GenerationMatch != 0 {
return fmt.Errorf("bad generation: %w", &googleapi.Error{
Code: http.StatusPreconditionFailed,
})
}
case err != nil:
return err
case cc.write.GenerationMatch != 0 && cc.write.GenerationMatch != attrs.Generation:
return fmt.Errorf("bad generation due to GenerationMatch: %w", &googleapi.Error{
Code: http.StatusPreconditionFailed,
})
case cc.write.GenerationNotMatch != 0 && cc.write.GenerationNotMatch == attrs.Generation:
return fmt.Errorf("bad generation due to GenerationNotMatch: %w", &googleapi.Error{
Code: http.StatusPreconditionFailed,
})
}
}
return nil
}