From a46be0ca5607d47daf64f63b6558bf70e6084951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Barotin?= Date: Fri, 7 May 2021 09:24:24 +0200 Subject: [PATCH 1/2] Add exists() to java client --- .../src/main/java/seaweedfs/client/FilerClient.java | 5 +++++ .../src/test/java/seaweedfs/client/SeaweedFilerTest.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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..de03efbb4 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 eaf17e5c6..c45ce7a9d 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"); + } } } From 89b2ef8d055866933f72c8b4d4480585df0339ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Barotin?= Date: Fri, 7 May 2021 10:05:48 +0200 Subject: [PATCH 2/2] handle "/" in exist --- .../src/main/java/seaweedfs/client/FilerClient.java | 9 ++++++++- .../src/test/java/seaweedfs/client/SeaweedFilerTest.java | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 de03efbb4..0a8356258 100644 --- a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java +++ b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java @@ -128,7 +128,14 @@ public class FilerClient extends FilerGrpcClient { public boolean exists(String path){ File pathFile = new File(path); - return lookupEntry(pathFile.getParent(), pathFile.getName()) != null; + 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) { 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 c45ce7a9d..f9a2c3f76 100644 --- a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java +++ b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java @@ -25,5 +25,8 @@ public class SeaweedFilerTest { 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"); + } } }