diff --git a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java index 341bd25..f754762 100644 --- a/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java +++ b/src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java @@ -5,8 +5,6 @@ import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.amazonaws.services.s3.model.CopyObjectRequest; -import com.amazonaws.services.s3.model.DeleteObjectRequest; import com.amazonaws.services.s3.model.GetObjectRequest; import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ObjectListing; @@ -299,16 +297,15 @@ public class S3ResourceRepository extends BaseResourceRepository { @Override public boolean rename(String path, String newPath) throws ResourceIOException { - try { - CopyObjectRequest copyObjRequest = new CopyObjectRequest(bucket, - path, bucket, newPath); - s3.copyObject(copyObjRequest); - s3.deleteObject(new DeleteObjectRequest(bucket, path)); - } catch (Exception e) { - LogKit.error(e.getMessage(), e); - return false; + + if (copy(path, newPath) && delete(path)) { + if (LogKit.isDebugEnabled()) { + LogKit.debug("[S3] rename {} to {} success.", path, newPath); + } + return true; } - return true; + LogKit.error("[S3] rename {} to {} failed.", path, newPath); + return false; } @Override