Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,9 @@ public CopyWriter copy(CopyRequest copyRequest) {
// only set the destination if it is not equal to the default instance
// otherwise we will clobber default values populated in the gcs server side for the object
// metadata
if (!cleanedDst.equals(Object.getDefaultInstance())) {
// If the caller provided a BlobInfo target (overrideInfo), always send the destination so the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the fix work generically for proto2, proto3 etc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should work generically. The FIX always sends destination when a target BlobInfo is given, even if it's empty. Proto2 and proto3 both send an empty destination to the server and don't drop it

// server does not fall back to copying the source object's metadata.
if (copyRequest.overrideInfo() || !cleanedDst.equals(Object.getDefaultInstance())) {
Comment thread
Dhriti07 marked this conversation as resolved.
b.setDestination(cleanedDst);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,31 @@ public void testCopyBlobUpdateMetadata() {
assertTrue(storage.delete(gen1.getBlobId()));
}

@Test
public void testCopyBlob_targetBlobInfo_doesNotInheritMetadata() {
BlobId source = BlobId.of(bucket.getName(), generator.randomObjectName() + "-source");
Blob remoteSourceBlob =
storage.create(
BlobInfo.newBuilder(source).setMetadata(ImmutableMap.of("k", "v")).build(),
BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
BlobInfo target = BlobInfo.newBuilder(bucket, generator.randomObjectName() + "-target").build();
CopyRequest req =
CopyRequest.newBuilder()
.setSource(source)
.setTarget(target, BlobTargetOption.doesNotExist())
.build();

CopyWriter copyWriter = storage.copy(req);
Blob copied = copyWriter.getResult();

assertTrue(copyWriter.isDone());
assertThat(copied.getMetadata()).isAnyOf(null, ImmutableMap.of());

assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(copied.getBlobId()));
}

@Test
public void testCopyBlobFail() {

Expand Down
Loading