Skip to content

Commit

Permalink
Limit block types in TypeLimitedBlockstore.refs()
Browse files Browse the repository at this point in the history
Filter 0 size blocks in refs
  • Loading branch information
ianopolous committed Nov 11, 2023
1 parent 91c71d1 commit ccec664
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/peergos/blockstore/FileBlockstore.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public CompletableFuture<Boolean> bloomAdd(Cid cid) {
public CompletableFuture<List<Cid>> refs(boolean useBlockstore) {
List<Path> result = new ArrayList<>();
try (Stream<Path> walk = Files.walk(blocksRoot)) {
result = walk.filter(f -> Files.isRegularFile(f) && f.getFileName().toString().endsWith(BLOCK_FILE_SUFFIX))
result = walk.filter(f -> Files.isRegularFile(f) &&
f.toFile().length() > 0 &&
f.getFileName().toString().endsWith(BLOCK_FILE_SUFFIX))
.collect(Collectors.toList());
} catch (IOException ioe) {
LOG.log(Level.WARNING, "Unable to retrieve local refs: " + ioe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.stream.*;

public class TypeLimitedBlockstore implements Blockstore {

Expand Down Expand Up @@ -70,7 +71,9 @@ public CompletableFuture<Boolean> rm(Cid cid) {

@Override
public CompletableFuture<List<Cid>> refs(boolean useBlockstore) {
return blocks.refs(useBlockstore);
return blocks.refs(useBlockstore).thenApply(res -> res.stream()
.filter(c -> allowedCodecs.contains(c.codec))
.collect(Collectors.toList()));
}

@Override
Expand Down

0 comments on commit ccec664

Please sign in to comment.