Skip to content

fix: metadata on small files without raw leaves #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/ipfs-unixfs-exporter/test/importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,24 @@ strategies.forEach((strategy) => {
expect(child).to.have.property('unixfs')
expect(child).to.not.have.nested.property('unixfs.mtime')
})

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

const mode = 511

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

const root = await exporter(entries[0].cid, block)

expect(root).to.have.nested.property('unixfs.mode', 511)
})
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const reduce = (file, blockstore, options) => {
if (leaves.length === 1 && leaves[0].single && options.reduceSingleLeafToSelf) {
const leaf = leaves[0]

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