Browse Source

修复几个小问题

pull/1/head
richie 5 years ago
parent
commit
447c3c16a1
  1. 3
      plugin.xml
  2. 14
      src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java
  3. 2
      src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java
  4. 19
      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.2</version> <version>1.1.3</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-07-01]修复目录多了一个reportlets的问题。<br/>
[2020-06-30]修复定时调度无法使用的问题。<br/> [2020-06-30]修复定时调度无法使用的问题。<br/>
[2020-06-15]支持区域设置。<br/> [2020-06-15]支持区域设置。<br/>
[2020-06-12]初始化插件。<br/> [2020-06-12]初始化插件。<br/>

14
src/main/java/com/fanruan/fs/s3/repository/core/S3Config.java

@ -4,6 +4,7 @@ import com.fr.config.Identifier;
import com.fr.config.holder.Conf; import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders; import com.fr.config.holder.factory.Holders;
import com.fr.io.config.CommonRepoConfig; import com.fr.io.config.CommonRepoConfig;
import com.fr.io.context.ResourceModuleContext;
import com.fr.io.context.info.GetConfig; import com.fr.io.context.info.GetConfig;
import com.fr.io.context.info.SetConfig; import com.fr.io.context.info.SetConfig;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -84,6 +85,19 @@ public class S3Config extends CommonRepoConfig {
this.bucket.set(bucket); this.bucket.set(bucket);
} }
@Override
public void update(String key) {
super.update(key);
S3Config newConfig = ResourceModuleContext.getRepoConfig(S3RepositoryFactory.IDENTITY, key);
if (newConfig != null) {
this.setEndPoint(newConfig.getEndPoint());
this.setRegion(newConfig.getRegion());
this.setAccessKeyId(newConfig.getAccessKeyId());
this.setAccessKeySecret(newConfig.getAccessKeySecret());
this.setBucket(newConfig.getBucket());
}
}
@Override @Override
public S3Config clone() throws CloneNotSupportedException { public S3Config clone() throws CloneNotSupportedException {
S3Config cloned = (S3Config) super.clone(); S3Config cloned = (S3Config) super.clone();

2
src/main/java/com/fanruan/fs/s3/repository/core/S3RepositoryProfile.java

@ -30,6 +30,8 @@ public class S3RepositoryProfile extends RepositoryProfile<S3Config> {
this.s3Config.set(s3Config); this.s3Config.set(s3Config);
} }
@Override @Override
public RepositoryProfile<S3Config> clone() throws CloneNotSupportedException { public RepositoryProfile<S3Config> clone() throws CloneNotSupportedException {
S3RepositoryProfile cloned = (S3RepositoryProfile) super.clone(); S3RepositoryProfile cloned = (S3RepositoryProfile) super.clone();

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

@ -5,6 +5,8 @@ import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder; 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.GetObjectRequest;
import com.amazonaws.services.s3.model.ListObjectsRequest; import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing; import com.amazonaws.services.s3.model.ObjectListing;
@ -71,8 +73,10 @@ public class S3ResourceRepository extends BaseResourceRepository {
ObjectListing objectListing = s3.listObjects(listObjectsRequest); ObjectListing objectListing = s3.listObjects(listObjectsRequest);
for (S3ObjectSummary summary : objectListing.getObjectSummaries()) { for (S3ObjectSummary summary : objectListing.getObjectSummaries()) {
String key = summary.getKey(); String key = summary.getKey();
if (!key.endsWith(DELIMITER)) {
result.add(s3Object2FileEntry(summary, key)); result.add(s3Object2FileEntry(summary, key));
} }
}
for (String prefix : objectListing.getCommonPrefixes()) { for (String prefix : objectListing.getCommonPrefixes()) {
FineFileEntry entry = new FineFileEntry(prefix); FineFileEntry entry = new FineFileEntry(prefix);
entry.setDirectory(true); entry.setDirectory(true);
@ -224,6 +228,20 @@ public class S3ResourceRepository extends BaseResourceRepository {
return s3Object.getObjectMetadata().getContentLength(); return s3Object.getObjectMetadata().getContentLength();
} }
@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;
}
return true;
}
@Override @Override
public void shutDown() { public void shutDown() {
s3.shutdown(); s3.shutdown();
@ -233,4 +251,5 @@ public class S3ResourceRepository extends BaseResourceRepository {
public String getIdentity() { public String getIdentity() {
return S3RepositoryFactory.IDENTITY; return S3RepositoryFactory.IDENTITY;
} }
} }

Loading…
Cancel
Save