Skip to content

Commit bef09cd

Browse files
authored
fix: metadata on small files without raw leaves (#212)
A file with metadata and without raw leaves should have the metadata preserved when the single leaf node is collapse to a root node.
1 parent 775a2dd commit bef09cd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,24 @@ strategies.forEach((strategy) => {
10731073
expect(child).to.have.property('unixfs')
10741074
expect(child).to.not.have.nested.property('unixfs.mtime')
10751075
})
1076+
1077+
it('should add metadata to the root node of a small file without raw leaves', async () => {
1078+
this.timeout(60 * 1000)
1079+
1080+
const mode = 511
1081+
1082+
const entries = await all(importer([{
1083+
path: '/foo/file1.txt',
1084+
content: asAsyncIterable(smallFile),
1085+
mode
1086+
}], block, {
1087+
rawLeaves: false
1088+
}))
1089+
1090+
const root = await exporter(entries[0].cid, block)
1091+
1092+
expect(root).to.have.nested.property('unixfs.mode', 511)
1093+
})
10761094
})
10771095
})
10781096

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const reduce = (file, blockstore, options) => {
7878
if (leaves.length === 1 && leaves[0].single && options.reduceSingleLeafToSelf) {
7979
const leaf = leaves[0]
8080

81-
if (leaf.cid.code === rawCodec.code && (file.mtime !== undefined || file.mode !== undefined)) {
81+
if (file.mtime !== undefined || file.mode !== undefined) {
8282
// only one leaf node which is a buffer - we have metadata so convert it into a
8383
// UnixFS entry otherwise we'll have nowhere to store the metadata
8484
let buffer = await blockstore.get(leaf.cid)

0 commit comments

Comments
 (0)