Skip to content

Commit 8eac540

Browse files
committed
Fix ls command to return links, and improve test
1 parent 4f9e87b commit 8eac540

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/main/java/io/ipfs/api/IPFS.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,13 @@ public List<MerkleNode> add(List<NamedStreamable> files, boolean wrap, boolean h
101101
}
102102

103103
public List<MerkleNode> ls(Multihash hash) throws IOException {
104-
Map res = retrieveMap("ls?arg=" + hash);
105-
return ((List<Object>) res.get("Objects")).stream().map(x -> MerkleNode.fromJSON((Map) x)).collect(Collectors.toList());
104+
Map reply = retrieveMap("ls?arg=" + hash);
105+
return ((List<Object>) reply.get("Objects"))
106+
.stream()
107+
.flatMap(x -> ((List<Object>)((Map) x).get("Links"))
108+
.stream()
109+
.map(MerkleNode::fromJSON))
110+
.collect(Collectors.toList());
106111
}
107112

108113
public byte[] cat(Multihash hash) throws IOException {

src/main/java/io/ipfs/api/MerkleNode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,9 @@ public Object toJSON() {
103103
public String toJSONString() {
104104
return JSONParser.toString(toJSON());
105105
}
106+
107+
@Override
108+
public String toString() {
109+
return hash + "-" + name.orElse("");
110+
}
106111
}

src/test/java/io/ipfs/api/APITest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ public void wrappedSingleFileTest() throws IOException {
102102

103103
@Test
104104
public void dirTest() throws IOException {
105-
NamedStreamable.DirWrapper dir = new NamedStreamable.DirWrapper("root", Arrays.asList());
106-
MerkleNode addResult = ipfs.add(dir).get(0);
105+
NamedStreamable dir = new NamedStreamable.FileWrapper(new File("java"));
106+
List<MerkleNode> add = ipfs.add(dir);
107+
MerkleNode addResult = add.get(add.size() - 1);
107108
List<MerkleNode> ls = ipfs.ls(addResult.hash);
108109
Assert.assertTrue(ls.size() > 0);
109110
}

0 commit comments

Comments
 (0)