Skip to content

Commit 6523abe

Browse files
authored
Remove duplicate code of buildHeaders() in ComposeSource (#1116)
1 parent 49006f4 commit 6523abe

File tree

3 files changed

+19
-37
lines changed

3 files changed

+19
-37
lines changed

api/src/main/java/io/minio/ComposeSource.java

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package io.minio;
1919

2020
import com.google.common.base.Objects;
21-
import com.google.common.collect.HashMultimap;
2221
import com.google.common.collect.Multimap;
2322
import com.google.common.collect.Multimaps;
2423
import io.minio.errors.InternalException;
@@ -84,36 +83,10 @@ private void validateSize(long objectSize) {
8483
public void buildHeaders(long objectSize, String etag) {
8584
validateSize(objectSize);
8685
this.objectSize = Long.valueOf(objectSize);
87-
88-
String copySource = S3Escaper.encodePath(bucketName + "/" + objectName);
89-
if (versionId != null) {
90-
copySource += "?versionId=" + S3Escaper.encode(versionId);
91-
}
92-
93-
Multimap<String, String> headers = HashMultimap.create();
94-
headers.put("x-amz-copy-source", copySource);
95-
headers.put("x-amz-copy-source-if-match", (matchETag != null) ? matchETag : etag);
96-
97-
if (notMatchETag != null) {
98-
headers.put("x-amz-copy-source-if-none-match", notMatchETag);
99-
}
100-
101-
if (modifiedSince != null) {
102-
headers.put(
103-
"x-amz-copy-source-if-modified-since",
104-
modifiedSince.format(Time.HTTP_HEADER_DATE_FORMAT));
105-
}
106-
107-
if (unmodifiedSince != null) {
108-
headers.put(
109-
"x-amz-copy-source-if-unmodified-since",
110-
unmodifiedSince.format(Time.HTTP_HEADER_DATE_FORMAT));
86+
Multimap<String, String> headers = genCopyHeaders();
87+
if (!headers.containsKey("x-amz-copy-source-if-match")) {
88+
headers.put("x-amz-copy-source-if-match", etag);
11189
}
112-
113-
if (ssec != null) {
114-
headers.putAll(Multimaps.forMap(ssec.copySourceHeaders()));
115-
}
116-
11790
this.headers = Multimaps.unmodifiableMultimap(headers);
11891
}
11992

api/src/main/java/io/minio/MinioClient.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,16 @@ public ObjectWriteResponse copyObject(CopyObjectArgs args)
11951195
ServerException, XmlParserException {
11961196
checkArgs(args);
11971197
args.validateSse(this.baseUrl);
1198-
if (args.source().offset() != null || args.source().length() != null) {
1199-
return composeObject(new ComposeObjectArgs(args));
1198+
1199+
long size = -1;
1200+
if (args.source().offset() != null && args.source().length() != null) {
1201+
StatObjectResponse stat = statObject(new StatObjectArgs((ObjectReadArgs) args.source()));
1202+
size = stat.size();
12001203
}
12011204

1202-
StatObjectResponse stat = statObject(new StatObjectArgs((ObjectReadArgs) args.source()));
1203-
if (stat.size() > ObjectWriteArgs.MAX_PART_SIZE) {
1205+
if (args.source().offset() != null
1206+
|| args.source().length() != null
1207+
|| size > ObjectWriteArgs.MAX_PART_SIZE) {
12041208
if (args.metadataDirective() != null && args.metadataDirective() == Directive.COPY) {
12051209
throw new IllegalArgumentException(
12061210
"COPY metadata directive is not applicable to source object size greater than 5 GiB");
@@ -1336,11 +1340,14 @@ private int calculatePartCount(List<ComposeSource> sources)
13361340
*
13371341
* // Create my-bucketname/my-objectname with user metadata by combining source object
13381342
* // list.
1343+
* Map<String, String> userMetadata = new HashMap<>();
1344+
* userMetadata.put("My-Project", "Project One");
13391345
* minioClient.composeObject(
13401346
* ComposeObjectArgs.builder()
13411347
* .bucket("my-bucketname")
13421348
* .object("my-objectname")
13431349
* .sources(sourceObjectList)
1350+
* .userMetadata(userMetadata)
13441351
* .build());
13451352
*
13461353
* // Create my-bucketname/my-objectname with user metadata and server-side encryption
@@ -1350,9 +1357,9 @@ private int calculatePartCount(List<ComposeSource> sources)
13501357
* .bucket("my-bucketname")
13511358
* .object("my-objectname")
13521359
* .sources(sourceObjectList)
1360+
* .userMetadata(userMetadata)
13531361
* .ssec(sse)
13541362
* .build());
1355-
*
13561363
* }</pre>
13571364
*
13581365
* @param args {@link ComposeObjectArgs} object.

docs/API.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,12 +1081,14 @@ minioClient.composeObject(
10811081

10821082
// Create my-bucketname/my-objectname with user metadata by combining source object
10831083
// list.
1084+
Map<String, String> userMetadata = new HashMap<>();
1085+
userMetadata.put("My-Project", "Project One");
10841086
minioClient.composeObject(
10851087
ComposeObjectArgs.builder()
10861088
.bucket("my-bucketname")
10871089
.object("my-objectname")
10881090
.sources(sourceObjectList)
1089-
.headers(Multimaps.forMap(userMetadata))
1091+
.userMetadata(userMetadata)
10901092
.build());
10911093

10921094
// Create my-bucketname/my-objectname with user metadata and server-side encryption
@@ -1096,7 +1098,7 @@ minioClient.composeObject(
10961098
.bucket("my-bucketname")
10971099
.object("my-objectname")
10981100
.sources(sourceObjectList)
1099-
.headers(Multimaps.forMap(userMetadata))
1101+
.userMetadata(userMetadata)
11001102
.ssec(sse)
11011103
.build());
11021104
```

0 commit comments

Comments
 (0)