Skip to content

[gcloud] Support GCS preconditions for object write/delete/copy#352

Open
Amayyas wants to merge 1 commit into
dart-lang:mainfrom
Amayyas:gcloud-gcs-preconditions
Open

[gcloud] Support GCS preconditions for object write/delete/copy#352
Amayyas wants to merge 1 commit into
dart-lang:mainfrom
Amayyas:gcloud-gcs-preconditions

Conversation

@Amayyas

@Amayyas Amayyas commented Jul 8, 2026

Copy link
Copy Markdown

Adds optional ifGenerationMatch and ifMetagenerationMatch parameters to the object write, delete, metadata-update and copy operations, enabling optimistic concurrency control as described at https://cloud.google.com/storage/docs/request-preconditions.

The parameter types mirror the existing ObjectGeneration API (objectGeneration is a String, metaGeneration is an int), so a value read from ObjectInfo.generation can be passed straight back as a precondition without conversion. An ifGenerationMatch of 0 (as the string '0') limits a write/copy to the case where the object does not yet exist.

The change is purely additive and non-breaking.

Fixes #184

Add optional `ifGenerationMatch` and `ifMetagenerationMatch` parameters to
the object write, delete, metadata update and copy operations, enabling
optimistic concurrency control as described at
https://cloud.google.com/storage/docs/request-preconditions.

The parameter types mirror the existing `ObjectGeneration` API
(`objectGeneration` is a `String`, `metaGeneration` is an `int`) so values
read from `ObjectInfo.generation` can be passed straight back as
preconditions without conversion. The change is purely additive and
non-breaking.

Fixes dart-lang#184
@Amayyas Amayyas requested a review from a team as a code owner July 8, 2026 18:35
@jonasfj

jonasfj commented Jul 9, 2026

Copy link
Copy Markdown
Member

for the record, I think https://pub.dev/packages/google_cloud_storage is the future, consider giving it a try, I think it has some of these features.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

PR Health

Unused Dependencies ✔️
Package Status
gcloud ✔️ All dependencies utilized correctly.

For details on how to fix these, see dependency_validator.

This check can be disabled by tagging the PR with skip-unused-dependencies-check.

Breaking changes ✔️
Package Change Current Version New Version Needed Version Looking good?
gcloud Breaking 0.9.0 0.9.1-wip 0.9.1-wip ✔️

This check can be disabled by tagging the PR with skip-breaking-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

Coverage ✔️
File Coverage
pkgs/gcloud/lib/src/storage_impl.dart 💚 76 % ⬆️ 4 %
pkgs/gcloud/lib/storage.dart 💚 60 %

This check for test coverage is informational (issues shown here will not fail the PR).

This check can be disabled by tagging the PR with skip-coverage-check.

License Headers ✔️
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/timezone/example/example.dart
pkgs/timezone/test/datetime_browser_test.dart
pkgs/timezone/test/datetime_test.dart
pkgs/timezone/test/datetime_test_no_database.dart
pkgs/timezone/test/env_test.dart
pkgs/timezone/test/two_way_test.dart
pkgs/timezone/test/zicfile_test.dart
pkgs/timezone/test/zone_tab_test.dart
pkgs/timezone/tool/encode_dart.dart
pkgs/timezone/tool/encode_tzf.dart
pkgs/timezone/tool/get.dart
pkgs/timezone/tool/test_random.dart
pkgs/timezone/tool/zone_dump.dart

This check can be disabled by tagging the PR with skip-license-check.

@Amayyas

Amayyas commented Jul 9, 2026

Copy link
Copy Markdown
Author

Thanks for the pointer — I hadn't come across google_cloud_storage.

Reading through it, it does look like the direction of travel, but it's still marked experimental (0.6.2, under labs.dart.dev, with a warning about a high expected rate of breaking changes). So for anyone currently on package:gcloud there isn't a stable migration path yet, and #184 was labelled contributions-welcome, which is what prompted me to pick it up.

Happy to go whichever way is most useful to you:

  • land this in gcloud as a stopgap for existing users (it's additive — the only compatibility caveat is for anyone implementing the Bucket / Storage abstract classes, which the issue already anticipated), or
  • close this and look at whether google_cloud_storage is missing preconditions on the object write/delete/copy paths, and contribute there instead.

Just let me know which you'd prefer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preconditions for deletion / writing in GCS

2 participants