Skip to content

Commit

Permalink
fix: do not add metadata to leaves (#193)
Browse files Browse the repository at this point in the history
When an imported file is big enough to need leaf nodes, and that
file is imported with metadata, we should only add that metadata
to the root of the file DAG and not to every leaf in the graph.
  • Loading branch information
achingbrain authored Feb 4, 2022
1 parent 273a141 commit f5d3a67
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
28 changes: 28 additions & 0 deletions packages/ipfs-unixfs-exporter/test/importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,34 @@ strategies.forEach((strategy) => {
const node2 = await exporter(entries[1].cid, block)
expect(node2).to.have.nested.property('unixfs.mode', 0o0755)
})

it('should only add metadata to the root node of a file', async () => {
this.timeout(60 * 1000)

const mtime = { secs: 5000, nsecs: 0 }

const entries = await all(importer([{
path: '/foo/file1.txt',
content: asAsyncIterable(bigFile),
mtime
}], block))

const root = await exporter(entries[0].cid, block)
expect(root).to.have.deep.nested.property('unixfs.mtime', mtime)

if (root.node instanceof Uint8Array) {
throw new Error('Root node was not large enough to have children')
}

const child = await exporter(root.node.Links[0].Hash, block)

if (child.type !== 'file') {
throw new Error('Child node was wrong type')
}

expect(child).to.have.property('unixfs')
expect(child).to.not.have.nested.property('unixfs.mtime')
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ async function * bufferImporter (file, block, options) {
} else {
unixfs = new UnixFS({
type: options.leafType,
data: buffer,
mtime: file.mtime,
mode: file.mode
data: buffer
})

buffer = dagPb.encode({
Expand Down

0 comments on commit f5d3a67

Please sign in to comment.