Skip to content
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

Add unixfs to UnixFS path selector tail #28

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

hannahhoward
Copy link
Collaborator

Goals

At the end of pathing into a UnixFS directory, you encounter a UnixFS object (whether file, directory, symlink, etc). You almost always want to reify that node, rather than work with the base protobuf type. This has no effect on single block unixfs files, but for multiblock files and directories, this is the only way you can work with the resulting object properly for the visitor function.

Implementation

fix the selector for paths, wrapping the last matcher node in an ExploreInterpretAs, since the tail
end of a path into a unixfs dir is itself a unixfsnode

fix the selector for paths, wrapping the last matcher node in an ExploreInterpretAs, since the tail
end of a path into a unixfs dir is itself a unixfsnode
@willscott
Copy link
Collaborator

Once unixfs reifier has been run on the outer traversal, wont it still be in effect at the point of matching? do you have an example of where the additional interpretAs is missing / would have an effect here?

I think it's only applicable in the degenerate case where there's only a single matcher with no path above it.

@hannahhoward
Copy link
Collaborator Author

hannahhoward commented Mar 7, 2022

@willscott see the surrounding code -- ExploreInterpretAs only lasts as long as you don't exit the immediate ADL instance you're working with. You have to apply it at each level of the path. So for example if you're in a UnixFS directory, ExploreInterpretAs will last only until you go to a sub directory or a file. This is cause UnixFS directories don't automatically load links at their edges. Rather they return a node of type link that the selector traversal loads -- the problem is when the selector traversal loads the link, it loses the reification.

The code in question can be found here -- I believe at minimum go-path is expecting go-unixfsnode to behave this way -- https://github.com/ipfs/go-unixfsnode/blob/main/directory/basicdir.go#L36

I discovered this in the real world when I was working with the graphsync PR -- the last node was just being left an ordinairy DagPB.

@hannahhoward hannahhoward merged commit 54ec979 into main Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants