Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Add exists() to java client

Jérôme Barotina46be0ca5607
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 91e7cba57c..de03efbb41 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,11 @@ public class FilerClient extends FilerGrpcClient {
}
+ public boolean exists(String path){
+ File pathFile = new File(path);
+ return lookupEntry(pathFile.getParent(), pathFile.getName()) != 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 eaf17e5c63..c45ce7a9dc 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,14 @@ 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");
+ }
}
}