Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

rawLeaves may be broken #44

Closed
mikeal opened this issue Jan 10, 2020 · 7 comments
Closed

rawLeaves may be broken #44

mikeal opened this issue Jan 10, 2020 · 7 comments

Comments

@mikeal
Copy link

mikeal commented Jan 10, 2020

I don’t think rawLeaves works as intended.

Here’s the output of jsipfs:

echo 'asdf' | jsipfs add --raw-leaves
added bafkreigrxsgtxjfpy7qqsyjmw45mxxo2ybjmsmbfvipyffbo3k5x324cue bafkreigrxsgtxjfpy7qqsyjmw45mxxo2ybjmsmbfvipyffbo3k5x324cue

Note that it prints the same CID twice, both of which are just the raw block created from the input. I believe the intended output is the raw block and a UnixFSv1 dag-pb node.

@mikeal
Copy link
Author

mikeal commented Jan 11, 2020

I think I figured it out. When I was writing the fromParts code I realized that files that are using rawLeaves also need to disable reduceSingleLeafToSelf https://github.com/ipfs/js-ipfs-unixfs-importer/pull/46/files#diff-f3029438ce98a6fe360f16e5abce50d5R36 .

Not sure where the best place to fix this would be, but if someone wants to point me to the right place I can send another patch.

@achingbrain
Copy link
Collaborator

If you have rawLeaves: true and reduceSingleLeafToSelf: true and your file would fit in a single node, the final CID will point to a ipld-raw node and not a dag-pb node.

If you have rawLeaves: true and reduceSingleLeafToSelf: false you'll get a dag-pb node as the root, with one leaf that's a ipld-raw node.

This behaviour is consistent with go-IPFS but I'm not sure the first instance is correct for two reasons:

  1. The output from a unixfs-importer should be UnixFS things, not ipld-raw nodes
  2. You can't add metadata to a ipld-raw node as it has no dag-pb wrapper to store the metadata on

My suggestion would be to ignore reduceSingleLeafToSelf when rawLeaves is true. Or maybe ignore rawLeaves when the file would fit into a single node?

What do you think @Stebalien @alanshaw ?

@Stebalien
Copy link

Stebalien commented Jan 13, 2020 via email

@mikeal
Copy link
Author

mikeal commented Jan 13, 2020

One thing that makes that override odd is that reduceSingleLeafToSelf defaults to true and rawLeaves defaults to false. If a user goes out of their way to override a default, it’s very odd to have another default option override their stated option. If reduceSingleLeafToSelf wasn’t defaulted to true I’d totally agree with its behavior overwriting rawLeaves when also set by the user to true, but in this case it feels wrong.

@achingbrain
Copy link
Collaborator

You're right, the ergonomics are a little wonky but reduceSingleLeafToSelf isn't exposed to the user via ipfs.add so it'll only affect people using the importer directly.

In this case I think we should override rawLeaves because a unixfs-importer should produce unixfs things. It not doing that, I think, is more wonky.

Also rawLeaves should really default to true.

@mikeal
Copy link
Author

mikeal commented Jan 13, 2020

With rawLeaves defaulting to true the behavior described feels correct.

@achingbrain
Copy link
Collaborator

Fixed by #49

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants