Browse Source

Pull request #15: DEC-17012 fix: 【S3插件】备份文件删除后,实际文件服务器上文件未删除

Merge in PG/plugin-repository-s3 from ~FENG/plugin-repository-s3:release/10.0 to release/10.0

* commit '3c1eb94de7862c1fc86b91caf0c99cd3ec1e08f4':
  DEC-17012 fix: 【S3插件】备份文件删除后,实际文件服务器上文件未删除
persist/10.0
Feng 4 years ago
parent
commit
7d2a958e8a
  1. 19
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

19
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

Loading…
Cancel
Save