Browse Source

REPORT-146048 fix:测试连接及目录识别问题修改

release/11.0
Afly 2 weeks ago
parent
commit
44a345b372
  1. 5
      plugin.xml
  2. 7
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryFactory.java
  3. 18
      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>
<active>yes</active>
<hidden>no</hidden>
<version>1.4.5</version>
<version>1.4.6</version>
<env-version>11.0~11.0</env-version>
<jartime>2023-03-14</jartime>
<vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[
[2023-07-25]第三方组件升级。 <br/>
[2025-01-04]测试连接逻辑修改、判断虚拟目录问题修复。 <br/>
[2024-07-25]第三方组件升级。 <br/>
[2024-03-13]国际化更新 <br/>
[2024-03-13]国际化更新 <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.stable.StringUtils;
import java.util.UUID;
import static com.fanruan.fs.s3.repository.core.S3ResourceRepository.HTTP;
/**
@ -59,7 +61,10 @@ public class S3RepositoryFactory extends ConfigRepositoryFactory<S3Config> {
}
amazonS3ClientBuilder = amazonS3ClientBuilder.withClientConfiguration(clientConfiguration);
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) {
LogKit.error(e.getMessage(), e);
return false;

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

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

Loading…
Cancel
Save