Skip to content

Commit 0b0a0c7

Browse files
committed
<feat>(precompiled): add BFS isExist interface.
1 parent ffda87c commit 0b0a0c7

File tree

1 file changed

+50
-0
lines changed
  • src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/bfs

1 file changed

+50
-0
lines changed

src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/bfs/BFSService.java

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ public RetCode mkdir(String path) throws ContractException {
4646
transactionReceipt, tr -> bfsPrecompiled.getMkdirOutput(tr).getValue1());
4747
}
4848

49+
// deprecated, use list(String absolutePath, BigInteger offset, BigInteger limit)
50+
51+
/**
52+
* @param path absolute path
53+
* @return If path is a directory, then return sub files; if path is a link, then return
54+
* fileName and link-address in ext.
55+
* @deprecated use {@link #list(String, BigInteger, BigInteger)} instead.
56+
*/
57+
@Deprecated
4958
public List<BFSPrecompiled.BfsInfo> list(String path) throws ContractException {
5059
Tuple2<BigInteger, DynamicArray<BFSPrecompiled.BfsInfo>> listOutput =
5160
bfsPrecompiled.list(path);
@@ -63,6 +72,13 @@ public List<BFSPrecompiled.BfsInfo> list(String path) throws ContractException {
6372
return listOutput.getValue2().getValue();
6473
}
6574

75+
/**
76+
* @param path absolute path
77+
* @return If path is a directory, then return sub files; if path is a link, then return
78+
* fileName and link-address in ext.
79+
* @deprecated use {@link #list(String, BigInteger, BigInteger)} instead.
80+
*/
81+
@Deprecated
6682
public List<BFSInfo> listBFSInfo(String path) throws ContractException {
6783
Tuple2<BigInteger, DynamicArray<BFSPrecompiled.BfsInfo>> listOutput =
6884
bfsPrecompiled.list(path);
@@ -102,6 +118,40 @@ public Tuple2<BigInteger, List<BFSInfo>> listBFSInfo(
102118
.collect(Collectors.toList()));
103119
}
104120

121+
/**
122+
* check the path file is exist in BFS
123+
*
124+
* @param absolutePath absolute path in BFS
125+
* @return if file exist, then return a BFSInfo; if not exist, then return null
126+
*/
127+
public BFSInfo isExist(String absolutePath) throws ContractException {
128+
PrecompiledVersionCheck.LS_PAGE_VERSION.checkVersion(currentVersion);
129+
if (absolutePath.endsWith("/")) {
130+
absolutePath = absolutePath.substring(0, absolutePath.length() - 1);
131+
}
132+
int index = absolutePath.lastIndexOf('/');
133+
String parent = absolutePath.substring(0, index);
134+
String child = absolutePath.substring(index + 1);
135+
int offset = 0;
136+
int limit = 500;
137+
while (true) {
138+
Tuple2<BigInteger, DynamicArray<BFSPrecompiled.BfsInfo>> listOutput =
139+
bfsPrecompiled.list(
140+
parent, BigInteger.valueOf(offset), BigInteger.valueOf(limit));
141+
if (!listOutput.getValue1().equals(BigInteger.ZERO)) {
142+
break;
143+
}
144+
for (BFSPrecompiled.BfsInfo bfsInfo : listOutput.getValue2().getValue()) {
145+
if (bfsInfo.fileName.equals(child)) {
146+
return BFSInfo.fromPrecompiledBfs(bfsInfo);
147+
}
148+
}
149+
offset += limit + 1;
150+
limit = listOutput.getValue1().intValue();
151+
}
152+
return null;
153+
}
154+
105155
public RetCode link(String name, String version, String contractAddress, String abi)
106156
throws ContractException {
107157
TransactionReceipt transactionReceipt =

0 commit comments

Comments
 (0)