Skip to content

Commit

Permalink
Fix updateMetadata in gcloud, release 0.8.18 (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfj authored Nov 18, 2024
1 parent 020a6a1 commit f1cb2b1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
4 changes: 4 additions & 0 deletions pkgs/gcloud/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.8.18
- Fix bug in `Bucket.updateMetadata` such that `acl: null` is allowed.
Since, this is the only valid value for buckets with uniform access policies.

## 0.8.17
- Fix bug in `ObjectMetadata.replace` where `contentEncoding` overwrote
`contentDisposition` and `contentLanguage`.
Expand Down
8 changes: 4 additions & 4 deletions pkgs/gcloud/lib/src/storage_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,13 @@ class _BucketImpl implements Bucket {
// TODO: support other ObjectMetadata implementations?
var md = metadata as _ObjectMetadata;
var object = md._object;
if (md._object.acl == null && _defaultObjectAcl == null) {
throw ArgumentError('ACL is required for update');
}
if (md.contentType == null) {
throw ArgumentError('Content-Type is required for update');
}
md._object.acl ??= _defaultObjectAcl!._toObjectAccessControlList();
// If no ACL is passed use the default (if any).
if (object.acl == null && _defaultObjectAcl != null) {
object.acl = _defaultObjectAcl!._toObjectAccessControlList();
}
return _api.objects.update(object, bucketName, objectName);
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/gcloud/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: gcloud
version: 0.8.17
version: 0.8.18
description: >-
High level idiomatic Dart API for Google Cloud Storage, Pub-Sub and Datastore.
repository: https://github.com/dart-lang/labs/tree/main/pkgs/gcloud
Expand Down
26 changes: 26 additions & 0 deletions pkgs/gcloud/test/storage/e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,31 @@ void main() {
], (Function f) => f().then(expectAsync1((_) {})));
});
});

test('update-metadata', () {
return withTestBucket((Bucket bucket) async {
await bucket.writeBytes(
'test-m',
metadata: ObjectMetadata(
contentType: 'application/test-1',
),
[1, 2, 3],
);

final info = await bucket.info('test-m');
expect(info.metadata.contentType, 'application/test-1');

await bucket.updateMetadata(
'test-m',
ObjectMetadata(
contentType: 'application/test-2',
));

final info2 = await bucket.info('test-m');
expect(info2.metadata.contentType, 'application/test-2');

await bucket.delete('test-m');
});
});
});
}

0 comments on commit f1cb2b1

Please sign in to comment.