Skip to content

Commit f1cb2b1

Browse files
authored
Fix updateMetadata in gcloud, release 0.8.18 (#188)
1 parent 020a6a1 commit f1cb2b1

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

pkgs/gcloud/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.8.18
2+
- Fix bug in `Bucket.updateMetadata` such that `acl: null` is allowed.
3+
Since, this is the only valid value for buckets with uniform access policies.
4+
15
## 0.8.17
26
- Fix bug in `ObjectMetadata.replace` where `contentEncoding` overwrote
37
`contentDisposition` and `contentLanguage`.

pkgs/gcloud/lib/src/storage_impl.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,13 @@ class _BucketImpl implements Bucket {
286286
// TODO: support other ObjectMetadata implementations?
287287
var md = metadata as _ObjectMetadata;
288288
var object = md._object;
289-
if (md._object.acl == null && _defaultObjectAcl == null) {
290-
throw ArgumentError('ACL is required for update');
291-
}
292289
if (md.contentType == null) {
293290
throw ArgumentError('Content-Type is required for update');
294291
}
295-
md._object.acl ??= _defaultObjectAcl!._toObjectAccessControlList();
292+
// If no ACL is passed use the default (if any).
293+
if (object.acl == null && _defaultObjectAcl != null) {
294+
object.acl = _defaultObjectAcl!._toObjectAccessControlList();
295+
}
296296
return _api.objects.update(object, bucketName, objectName);
297297
}
298298

pkgs/gcloud/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: gcloud
2-
version: 0.8.17
2+
version: 0.8.18
33
description: >-
44
High level idiomatic Dart API for Google Cloud Storage, Pub-Sub and Datastore.
55
repository: https://github.com/dart-lang/labs/tree/main/pkgs/gcloud

pkgs/gcloud/test/storage/e2e_test.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,31 @@ void main() {
341341
], (Function f) => f().then(expectAsync1((_) {})));
342342
});
343343
});
344+
345+
test('update-metadata', () {
346+
return withTestBucket((Bucket bucket) async {
347+
await bucket.writeBytes(
348+
'test-m',
349+
metadata: ObjectMetadata(
350+
contentType: 'application/test-1',
351+
),
352+
[1, 2, 3],
353+
);
354+
355+
final info = await bucket.info('test-m');
356+
expect(info.metadata.contentType, 'application/test-1');
357+
358+
await bucket.updateMetadata(
359+
'test-m',
360+
ObjectMetadata(
361+
contentType: 'application/test-2',
362+
));
363+
364+
final info2 = await bucket.info('test-m');
365+
expect(info2.metadata.contentType, 'application/test-2');
366+
367+
await bucket.delete('test-m');
368+
});
369+
});
344370
});
345371
}

0 commit comments

Comments
 (0)