Skip to content

Commit

Permalink
use a different client for copy to possible new bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Sep 4, 2023
1 parent e3d2321 commit 8157a1a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions source/java/src/org/lucee/extension/resource/s3/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -1255,17 +1255,18 @@ public void copyObject(String srcBucketName, String srcObjectName, String trgBuc

flushExists(srcBucketName, srcObjectName);
flushExists(trgBucketName, trgObjectName);
AmazonS3Client client = getAmazonS3(null, null);
// AmazonS3Client client = getAmazonS3(srcBucketName, null);

boolean doesExistBefore = client.doesBucketExistV2(trgBucketName);
AmazonS3Client srcClient = getAmazonS3(srcBucketName, null);
AmazonS3Client trgClient = getAmazonS3(null, targetRegion);

// AmazonS3Client client = getAmazonS3(srcBucketName, null);

try {
CopyObjectRequest cor = new CopyObjectRequest(srcBucketName, srcObjectName, trgBucketName, trgObjectName);

if (acl != null) setACL(cor, acl);
try {
client.copyObject(cor);
trgClient.copyObject(cor);
}
catch (AmazonServiceException se) {
// could be an Pseudo folder
Expand All @@ -1276,11 +1277,11 @@ public void copyObject(String srcBucketName, String srcObjectName, String trgBuc
}
throw toS3Exception(se);
}
else if (se.getErrorCode().equals("NoSuchBucket") && !client.doesBucketExistV2(trgBucketName)) {
else if (se.getErrorCode().equals("NoSuchBucket") && !srcClient.doesBucketExistV2(trgBucketName)) {
boolean customACL = true;

if (acl == null) {
acl = client.getBucketAcl(srcBucketName);
acl = srcClient.getBucketAcl(srcBucketName);
customACL = acl == null;
}
CreateBucketRequest cbr = new CreateBucketRequest(trgBucketName);
Expand Down Expand Up @@ -1310,16 +1311,16 @@ else if (se.getErrorCode().equals("NoSuchBucket") && !client.doesBucketExistV2(t
}
}
else {
throw new S3Exception(se.getErrorCode() + ";after:" + client.doesBucketExistV2(trgBucketName) + ";before:" + doesExistBefore + ";could not copy ["
+ srcBucketName + "/" + srcObjectName + "] to [" + trgBucketName + "/" + trgObjectName + "] ", se);
throw new S3Exception("could not copy [" + srcBucketName + "/" + srcObjectName + "] to [" + trgBucketName + "/" + trgObjectName + "] ", se);
}
}
}
catch (AmazonServiceException se) {
throw new S3Exception(se.getErrorCode() + ";could not copy [" + srcBucketName + "/" + srcObjectName + "] to [" + trgBucketName + "/" + trgObjectName + "] ", se);
throw new S3Exception("could not copy [" + srcBucketName + "/" + srcObjectName + "] to [" + trgBucketName + "/" + trgObjectName + "] ", se);
}
finally {
client.release();
srcClient.release();
trgClient.release();
}
}

Expand Down

0 comments on commit 8157a1a

Please sign in to comment.