|
|
@ -59,6 +59,9 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
|
|
|
|
|
|
|
|
private final boolean preserveMetadata; |
|
|
|
private final boolean preserveMetadata; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 是否将创建a/b/c.txt时的a/b/识别成一个存在的目录
|
|
|
|
|
|
|
|
private final boolean openVirtualDirectory; |
|
|
|
|
|
|
|
|
|
|
|
private final AmazonS3 s3; |
|
|
|
private final AmazonS3 s3; |
|
|
|
private final String bucket; |
|
|
|
private final String bucket; |
|
|
|
|
|
|
|
|
|
|
@ -86,6 +89,7 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
this.s3 = amazonS3ClientBuilder.build(); |
|
|
|
this.s3 = amazonS3ClientBuilder.build(); |
|
|
|
this.bucket = config.getBucket(); |
|
|
|
this.bucket = config.getBucket(); |
|
|
|
this.preserveMetadata = config.isPreserveMetadata(); |
|
|
|
this.preserveMetadata = config.isPreserveMetadata(); |
|
|
|
|
|
|
|
this.openVirtualDirectory = config.isOpenVirtualDirectory(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -99,6 +103,7 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
ObjectMetadata metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
ObjectMetadata metadata = s3.getObjectMetadata(bucket, path); |
|
|
|
return s3Object2FileEntry(metadata, path); |
|
|
|
return s3Object2FileEntry(metadata, path); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
LogKit.error(e.getMessage(), e); |
|
|
|
LogKit.info("{} not exist!", path); |
|
|
|
LogKit.info("{} not exist!", path); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!path.endsWith(DELIMITER)) { |
|
|
|
if (!path.endsWith(DELIMITER)) { |
|
|
@ -330,7 +335,16 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean exist(String path) { |
|
|
|
public boolean exist(String path) { |
|
|
|
return fileExist(path) || (!path.endsWith(DELIMITER) && dirExist(path)) || isParentPathAbsent(path); |
|
|
|
if (fileExist(path)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if ((!path.endsWith(DELIMITER) && dirExist(path))) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (openVirtualDirectory) { |
|
|
|
|
|
|
|
return isVirtualDirectory(path); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean fileExist(String path) { |
|
|
|
private boolean fileExist(String path) { |
|
|
@ -352,9 +366,9 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 如果存在文件创建了,但是其父目录没有创建的场景,为其递归创建对象,返回创建结果 |
|
|
|
* 是否将创建对象的前缀(比如a/b/c.txt时的a/b/)识别成一个存在的目录. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private boolean isParentPathAbsent(String path) { |
|
|
|
private boolean isVirtualDirectory(String path) { |
|
|
|
if (path.startsWith(DELIMITER)) { |
|
|
|
if (path.startsWith(DELIMITER)) { |
|
|
|
path = path.substring(1); |
|
|
|
path = path.substring(1); |
|
|
|
} |
|
|
|
} |
|
|
@ -364,7 +378,8 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
ObjectListing objectListing = s3.listObjects( |
|
|
|
ObjectListing objectListing = s3.listObjects( |
|
|
|
new ListObjectsRequest() |
|
|
|
new ListObjectsRequest() |
|
|
|
.withBucketName(bucket) |
|
|
|
.withBucketName(bucket) |
|
|
|
.withPrefix(path)); |
|
|
|
.withPrefix(path) |
|
|
|
|
|
|
|
.withDelimiter(DELIMITER)); |
|
|
|
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { |
|
|
|
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { |
|
|
|
if (summary.getKey().startsWith(path + DELIMITER)) { |
|
|
|
if (summary.getKey().startsWith(path + DELIMITER)) { |
|
|
|
return createDirectory(path); |
|
|
|
return createDirectory(path); |
|
|
@ -416,7 +431,12 @@ public class S3ResourceRepository extends BaseResourceRepository { |
|
|
|
//是文件
|
|
|
|
//是文件
|
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return dirExist(path) || isParentPathAbsent(path); |
|
|
|
if (dirExist(path)) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// 是一个虚拟的目录
|
|
|
|
|
|
|
|
return openVirtualDirectory && isVirtualDirectory(path); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|