Browse Source

Pull request #1465: 11.0.32插件改动合并

Merge in PG/plugin-repository-s3 from release/11.0 to persist/11.0

* commit 'ebb561fd36db6848c87d6ef2410958b1268e9143':
  REPORT-146048 fix: 处理下每次只返回了部分对象的问题
  REPORT-146048 fix:测试连接及目录识别问题修改
persist/11.0
LyKay-王积凯 1 week ago
parent
commit
5a967e3edb
  1. 5
      plugin.xml
  2. 7
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  3. 21
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

5
plugin.xml

@ -5,13 +5,14 @@
<main-package>com.fanruan.fs</main-package> <main-package>com.fanruan.fs</main-package>
<active>yes</active> <active>yes</active>
<hidden>no</hidden> <hidden>no</hidden>
<version>1.4.5</version> <version>1.4.6</version>
<env-version>11.0~11.0</env-version> <env-version>11.0~11.0</env-version>
<jartime>2023-03-14</jartime> <jartime>2023-03-14</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description> <description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2023-07-25]第三方组件升级。 <br/> [2025-01-04]测试连接逻辑修改、判断虚拟目录问题修复。 <br/>
[2024-07-25]第三方组件升级。 <br/>
[2024-03-13]国际化更新 <br/> [2024-03-13]国际化更新 <br/>
[2024-03-13]国际化更新 <br/> [2024-03-13]国际化更新 <br/>
[2023-11-21]小文件不使用分片上传, 新增preserveMetadata后台配置。 <br/> [2023-11-21]小文件不使用分片上传, 新增preserveMetadata后台配置。 <br/>

7
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java

@ -13,6 +13,8 @@ import com.fr.io.context.info.RepositoryProfile;
import com.fr.io.repository.ResourceRepository; import com.fr.io.repository.ResourceRepository;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import java.util.UUID;
import static com.fanruan.fs.s3.repository.core.S3ResourceRepository.HTTP; import static com.fanruan.fs.s3.repository.core.S3ResourceRepository.HTTP;
/** /**
@ -59,7 +61,10 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
} }
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration); amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
s3 = amazonS3ClientBuilder.build(); s3 = amazonS3ClientBuilder.build();
s3.listObjects(config.getBucket()); String bucket = config.getBucket();
String testObject = "test_object_" + UUID.randomUUID();
s3.putObject(bucket, testObject, StringUtils.EMPTY);
s3.deleteObject(bucket, testObject);
} catch (Exception e) { } catch (Exception e) {
LogKit.error(e.getMessage(), e); LogKit.error(e.getMessage(), e);
return false; return false;

21
src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

@ -278,6 +278,10 @@ public class S3ResourceRepository extends BaseResourceRepository {
return false; return false;
} }
} }
return createDirectoryInternal(path);
}
private boolean createDirectoryInternal(String path) {
PutObjectRequest req = new PutObjectRequest(bucket, path, new ByteArrayInputStream(new byte[0]), buildEmptyMetadata()); PutObjectRequest req = new PutObjectRequest(bucket, path, new ByteArrayInputStream(new byte[0]), buildEmptyMetadata());
try { try {
s3.putObject(req); s3.putObject(req);
@ -380,11 +384,20 @@ public class S3ResourceRepository extends BaseResourceRepository {
.withBucketName(bucket) .withBucketName(bucket)
.withPrefix(path) .withPrefix(path)
.withDelimiter(DELIMITER)); .withDelimiter(DELIMITER));
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { String targetDir = path + DELIMITER;
if (summary.getKey().startsWith(path + DELIMITER)) { boolean firstSearch = true;
return createDirectory(path); do {
if (!firstSearch) {
objectListing = s3.listNextBatchOfObjects(objectListing);
} }
firstSearch = false;
if (objectListing.getCommonPrefixes().stream().anyMatch(s -> s.startsWith(targetDir)) ||
objectListing.getObjectSummaries().stream().anyMatch(s -> s.getKey().startsWith(targetDir))) {
createDirectoryInternal(targetDir);
return true;
} }
} while (objectListing.isTruncated());
return false; return false;
} }
@ -454,6 +467,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
} }
} }
} catch (Exception e) { } catch (Exception e) {
LogKit.error(e.getMessage(), e);
LogKit.info("{} not exist!", path); LogKit.info("{} not exist!", path);
} }
@ -466,6 +480,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
ObjectMetadata metadata = s3.getObjectMetadata(bucket, path); ObjectMetadata metadata = s3.getObjectMetadata(bucket, path);
return metadata.getContentLength(); return metadata.getContentLength();
} catch (Exception e) { } catch (Exception e) {
LogKit.error(e.getMessage(), e);
LogKit.info("{} not exist!", path); LogKit.info("{} not exist!", path);
} }

Loading…
Cancel
Save