@@ -450,38 +450,43 @@ final class ExportedBlob extends ExportedObject {
450450 }));
451451 }
452452
453- /// Copy binary blob from [bucket] and [source] to this file.
454- Future <void > copyFrom (Bucket bucket, String source) async {
453+ /// Copy binary blob from [absoluteSourceObjectName] to this file.
454+ ///
455+ /// Requires that [absoluteSourceObjectName] is a `gs:/<bucket>/<objectName>`
456+ /// style URL. These can be created with [Bucket.absoluteObjectName] .
457+ ///
458+ /// [sourceInfo] is required to be [ObjectInfo] for the source object.
459+ /// This method will use [ObjectInfo.length] and [ObjectInfo.md5Hash] to
460+ /// determine if it's necessary to copy the object.
461+ Future <void > copyFrom (
462+ String absoluteSourceObjectName,
463+ ObjectInfo sourceInfo,
464+ ) async {
455465 final metadata = _metadata ();
456- Future <ObjectInfo ?>? srcInfo;
457466
458467 await Future .wait (_owner._prefixes.map ((prefix) async {
459468 await _owner._pool.withResource (() async {
460469 final dst = prefix + _objectName;
461470
462471 // Check if the dst already exists
463472 if (await _owner._bucket.tryInfo (dst) case final dstInfo? ) {
464- // Fetch info for source object (if we haven't already done this)
465- srcInfo ?? = bucket.tryInfo (source);
466- if (await srcInfo case final srcInfo? ) {
467- if (dstInfo.contentEquals (srcInfo)) {
468- // If both source and dst exists, and their content matches, then
469- // we only need to update the "validated" metadata. And we only
470- // need to update the "validated" timestamp if it's older than
471- // _retouchDeadline
472- final retouchDeadline = clock.agoBy (_updateValidatedAfter);
473- if (dstInfo.metadata.validated.isBefore (retouchDeadline)) {
474- await _owner._bucket.updateMetadata (dst, metadata);
475- }
476- return ;
473+ if (dstInfo.contentEquals (sourceInfo)) {
474+ // If both source and dst exists, and their content matches, then
475+ // we only need to update the "validated" metadata. And we only
476+ // need to update the "validated" timestamp if it's older than
477+ // _retouchDeadline
478+ final retouchDeadline = clock.agoBy (_updateValidatedAfter);
479+ if (dstInfo.metadata.validated.isBefore (retouchDeadline)) {
480+ await _owner._bucket.updateMetadata (dst, metadata);
477481 }
482+ return ;
478483 }
479484 }
480485
481486 // If dst or source doesn't exist, then we shall attempt to make a copy.
482487 // (if source doesn't exist we'll consistently get an error from here!)
483488 await _owner._storage.copyObject (
484- bucket. absoluteObjectName (source) ,
489+ absoluteSourceObjectName ,
485490 _owner._bucket.absoluteObjectName (dst),
486491 metadata: metadata,
487492 );
0 commit comments