Skip to content
Snippets Groups Projects
Commit 0bd2d5b3 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

reproducible leaf without duplicate

parent 04b2522c
No related branches found
No related tags found
No related merge requests found
...@@ -81,7 +81,12 @@ async function processInode(node: IndexInode, key: string, val: CID): Promise<CI ...@@ -81,7 +81,12 @@ async function processInode(node: IndexInode, key: string, val: CID): Promise<CI
} }
async function processLeaf(node: IndexLeaf, val: CID): Promise<CID> { async function processLeaf(node: IndexLeaf, val: CID): Promise<CID> {
if (!node.leaf.some((c) => c.toString() == val.toString())) {
// only insert if not already there (avoid duplicate)
node.leaf.push(val) node.leaf.push(val)
// ensure leaf order is predictible
node.leaf.sort((a, b) => (a.toString() < b.toString() ? -1 : 1))
}
const newCid = await kubo.dag.put(node) const newCid = await kubo.dag.put(node)
return newCid return newCid
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment