You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/06/27 15:23:20 UTC
[commons-vfs] 02/06: Refactor multiple API calls.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit 42fd5d7661e8dcd9ebdf40e9ae63bade25334672
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Jun 26 10:58:16 2019 -0400
Refactor multiple API calls.
---
.../commons/vfs2/filter/CanWriteFileFilter.java | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/CanWriteFileFilter.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/CanWriteFileFilter.java
index 60c71db..0d5df78 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/CanWriteFileFilter.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/CanWriteFileFilter.java
@@ -20,6 +20,7 @@ import java.io.Serializable;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileFilter;
+import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSelectInfo;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemException;
@@ -89,17 +90,19 @@ public class CanWriteFileFilter implements FileFilter, Serializable {
*/
@Override
public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException {
- final FileSystem fileSystem = fileInfo.getFile().getFileSystem();
- if (fileInfo.getFile().exists()) {
- if (!fileSystem.hasCapability(Capability.WRITE_CONTENT)) {
+ try (final FileObject file = fileInfo.getFile()) {
+ final FileSystem fileSystem = file.getFileSystem();
+ if (file.exists()) {
+ if (!fileSystem.hasCapability(Capability.WRITE_CONTENT)) {
+ return false;
+ }
+ return file.isWriteable();
+ }
+ if (!fileSystem.hasCapability(Capability.CREATE)) {
return false;
}
- return fileInfo.getFile().isWriteable();
- }
- if (!fileSystem.hasCapability(Capability.CREATE)) {
- return false;
+ return file.getParent().isWriteable();
}
- return fileInfo.getFile().getParent().isWriteable();
}
}