Browse Source
Merge pull request #2052 from jbarotin/master
Add exists() to java client
pull/2063/head
Chris Lu
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
22 additions and
1 deletions
-
other/java/client/src/main/java/seaweedfs/client/FilerClient.java
-
other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.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); |
|
|
|
|
|
@ -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"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |