aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chrislusf@users.noreply.github.com>2021-05-07 06:09:03 -0700
committerGitHub <noreply@github.com>2021-05-07 06:09:03 -0700
commit84397b814aaacac87ea1a83b788829928b85bae0 (patch)
tree24a59e8e1d289d73c23551f7e37f1bdaf63b444d
parent9b5f54e36733854fc8d6897808ce53349cf7b785 (diff)
parent89b2ef8d055866933f72c8b4d4480585df0339ac (diff)
downloadseaweedfs-84397b814aaacac87ea1a83b788829928b85bae0.tar.xz
seaweedfs-84397b814aaacac87ea1a83b788829928b85bae0.zip
Merge pull request #2052 from jbarotin/master
Add exists() to java client
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FilerClient.java12
-rw-r--r--other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java11
2 files changed, 22 insertions, 1 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
index 91e7cba57..0a8356258 100644
--- a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
+++ b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
@@ -126,6 +126,18 @@ public class FilerClient extends FilerGrpcClient {
}
+ public boolean exists(String path){
+ File pathFile = new File(path);
+ String parent = pathFile.getParent();
+ String entryName = pathFile.getName();
+ if(parent == null) {
+ parent = path;
+ entryName ="";
+ }
+ return lookupEntry(parent, entryName) != null;
+
+ }
+
public boolean rm(String path, boolean isRecursive, boolean ignoreRecusiveError) {
File pathFile = new File(path);
diff --git a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
index eaf17e5c6..f9a2c3f76 100644
--- a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
+++ b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
@@ -16,8 +16,17 @@ public class SeaweedFilerTest {
filerClient.mkdirs("/new_folder", 0755);
filerClient.touch("/new_folder/new_empty_file", 0755);
filerClient.touch("/new_folder/new_empty_file2", 0755);
+ if(!filerClient.exists("/new_folder/new_empty_file")){
+ System.out.println("/new_folder/new_empty_file should exists");
+ }
+
filerClient.rm("/new_folder/new_empty_file", false, true);
filerClient.rm("/new_folder", true, true);
-
+ if(filerClient.exists("/new_folder/new_empty_file")){
+ System.out.println("/new_folder/new_empty_file should not exists");
+ }
+ if(!filerClient.exists("/")){
+ System.out.println("/ should exists");
+ }
}
}