Browse Source

定时调度使用的问题

pull/1/head
richie 5 years ago
parent
commit
6848d2f190
  1. 3
      plugin.xml
  2. 30
      src/main/java/com/fanruan/fs/s3/repository/core/S3ResourceRepository.java

3
plugin.xml

@ -5,12 +5,13 @@
<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.1.1</version> <version>1.1.2</version>
<env-version>10.0</env-version> <env-version>10.0</env-version>
<jartime>2020-01-27</jartime> <jartime>2020-01-27</jartime>
<vendor>richie</vendor> <vendor>richie</vendor>
<description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description> <description><![CDATA[使用支持S3协议的云存储文件系统作为文件服务器。]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
[2020-06-30]修复定时调度无法使用的问题。<br/>
[2020-06-15]支持区域设置。<br/> [2020-06-15]支持区域设置。<br/>
[2020-06-12]初始化插件。<br/> [2020-06-12]初始化插件。<br/>
]]></change-notes> ]]></change-notes>

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

@ -19,8 +19,10 @@ import com.fr.stable.Filter;
import com.fr.workspace.resource.ResourceIOException; import com.fr.workspace.resource.ResourceIOException;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream; import java.io.InputStream;
import java.net.URL; import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -159,7 +161,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public boolean exist(String path) { public boolean exist(String path) {
try { try {
return s3.doesObjectExist(bucket, path); return s3.listObjectsV2(bucket, path).getKeyCount() > 0;
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
@ -175,13 +177,25 @@ public class S3ResourceRepository extends BaseResourceRepository {
.withPrefix(dir).withDelimiter(DELIMITER); .withPrefix(dir).withDelimiter(DELIMITER);
ObjectListing objectListing = s3.listObjects(listObjectsRequest); ObjectListing objectListing = s3.listObjects(listObjectsRequest);
for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) { for (S3ObjectSummary objectSummary : objectListing.getObjectSummaries()) {
if (filter.accept(objectSummary.getKey())) { String[] arr = objectSummary.getKey().split(DELIMITER);
result.add(objectSummary.getKey()); String name = arr[arr.length - 1];
if (filter == null) {
result.add(name);
} else {
if (filter.accept(name)) {
result.add(name);
}
} }
} }
for (String prefix : objectListing.getCommonPrefixes()) { for (String prefix : objectListing.getCommonPrefixes()) {
if (filter.accept(prefix)) { String[] arr = prefix.split(DELIMITER);
result.add(prefix); String name = arr[arr.length - 1] + DELIMITER;
if (filter == null) {
result.add(name);
} else {
if (filter.accept(name)) {
result.add(name);
}
} }
} }
return result.toArray(new String[0]); return result.toArray(new String[0]);
@ -189,11 +203,7 @@ public class S3ResourceRepository extends BaseResourceRepository {
@Override @Override
public boolean isDirectory(String path) { public boolean isDirectory(String path) {
S3Object s3Object = s3.getObject(bucket, path); return path.endsWith(DELIMITER);
if (s3Object == null) {
return false;
}
return s3Object.getKey().endsWith("/");
} }
@Override @Override

Loading…
Cancel
Save