importer: fillNodeRec: pass UnixfsNode
structure, not its pointer
#5109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modify
fillNodeRec
of the balanced importer to pass theUnixfsNode
structureinstead of its pointer. The pointer was used as a channel to return information
from the recursive callee function which was obscuring the code information
flow. This returned information is now explicitly added to the return values of
fillNodeRec
that now include the IPLD node to be added and its (UnixFS) filesize (that depends on the type of node and is handled by the encapsulating
UnixfsNode
structure).As a consequence of this, IPLD nodes can now be used instead of the composite
UnixfsNode
in some parts of the code (which helps clarifying what type of nodeis being manipulated in each case). Some of the functions that used
UnixfsNode
as arguments were substituted with analogous functions that receive
ipld.Node
,the original functions cannot be replaced (at the moment) because they are still
being used by the trickle builder.
The indirect modification of the passed
UnixfsNode
through its pointer wasused in the corner case of the
Layout
function when the loop is iterated onlyonce, i.e., the generated DAG is a single node with data and
AddChildNode
isnever called. In that case the
root
was converted through its pointer to aleaf node with data in
fillNodeRec
which could later be added to the DAG(
db.Add()
). This indirect modification is not allowed now so that corner caseneeds to be handled separately by explicitly adding the
filledRoot
nodereturned by
fillNodeRec
which wasn't added toroot
(instead of addingroot
itself).
The priority of this commit is to respect the structure and code flow of the
importer to still make evident how a balanced DAG is built.