Skip to content

Commit f5d3a67

Browse files
authored
fix: do not add metadata to leaves (#193)
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.
1 parent 273a141 commit f5d3a67

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/ipfs-unixfs-exporter/test/importer.spec.js

+28
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,34 @@ strategies.forEach((strategy) => {
10451045
const node2 = await exporter(entries[1].cid, block)
10461046
expect(node2).to.have.nested.property('unixfs.mode', 0o0755)
10471047
})
1048+
1049+
it('should only add metadata to the root node of a file', async () => {
1050+
this.timeout(60 * 1000)
1051+
1052+
const mtime = { secs: 5000, nsecs: 0 }
1053+
1054+
const entries = await all(importer([{
1055+
path: '/foo/file1.txt',
1056+
content: asAsyncIterable(bigFile),
1057+
mtime
1058+
}], block))
1059+
1060+
const root = await exporter(entries[0].cid, block)
1061+
expect(root).to.have.deep.nested.property('unixfs.mtime', mtime)
1062+
1063+
if (root.node instanceof Uint8Array) {
1064+
throw new Error('Root node was not large enough to have children')
1065+
}
1066+
1067+
const child = await exporter(root.node.Links[0].Hash, block)
1068+
1069+
if (child.type !== 'file') {
1070+
throw new Error('Child node was wrong type')
1071+
}
1072+
1073+
expect(child).to.have.property('unixfs')
1074+
expect(child).to.not.have.nested.property('unixfs.mtime')
1075+
})
10481076
})
10491077
})
10501078

packages/ipfs-unixfs-importer/src/dag-builder/file/buffer-importer.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ async function * bufferImporter (file, block, options) {
3030
} else {
3131
unixfs = new UnixFS({
3232
type: options.leafType,
33-
data: buffer,
34-
mtime: file.mtime,
35-
mode: file.mode
33+
data: buffer
3634
})
3735

3836
buffer = dagPb.encode({

0 commit comments

Comments
 (0)