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

Simplify file wrapping logic #6121

Closed
wants to merge 8 commits into from
Closed

Conversation

Stebalien
Copy link
Member

@Stebalien Stebalien commented Mar 22, 2019

I'm not sure if this is entirely correct but basically:

  1. The adder now always adds files under a "root" file/directory.
  2. All wrap logic is handled outside the file adder.

Thoughts? This would also require removing all wrap logic from the core interface.

Depends on ipfs/interface-go-ipfs-core#21.

@Stebalien Stebalien requested a review from Kubuxu as a code owner March 22, 2019 21:53
@Stebalien Stebalien force-pushed the fix/unixfs-add-wrap-simplify branch from d0021bb to 0a2c877 Compare March 22, 2019 22:00
@ghost ghost assigned Stebalien Mar 22, 2019
@ghost ghost added the status/in-progress In progress label Mar 22, 2019
@@ -480,6 +403,9 @@ func outputDagnode(out chan<- interface{}, name string, dn ipld.Node) error {
return err
}

name = strings.TrimPrefix(name, rootFileName)
name = strings.TrimLeft(name, "/")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moderately icky...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this whole "rootFileName" thing is kind of broken (for now at least). Your point about not using MFS for a single file is probably the right way to go.

Otherwise, we'll need to correctly strip the root filename everywhere we send out an event.

err := adder.addFileNode(fpath, it.Node(), false)
node := it.Node()
err := adder.addFileNode(fpath, node)
node.Close()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we need to close this here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup (though I'd check errors here)

output.Name = path.Join(name, output.Name)
}

if !wrap && output.Name == "" {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched this to check the wrap flag instead of "is this a directory". Is that correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we allowed "" only for wrapping directories, so this seems correct

Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing on some event stuff, not sure why, but overall 👍

err := adder.addFileNode(fpath, it.Node(), false)
node := it.Node()
err := adder.addFileNode(fpath, node)
node.Close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup (though I'd check errors here)

output.Name = path.Join(name, output.Name)
}

if !wrap && output.Name == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we allowed "" only for wrapping directories, so this seems correct

@Stebalien Stebalien force-pushed the fix/unixfs-add-wrap-simplify branch from 62e215d to 1fc7096 Compare March 23, 2019 02:56

fileAdder, err := coreunix.NewAdder(ctx, pinning, addblockstore, dserv)
fileAdder, err := coreunix.NewAdder(pinning, addblockstore, dserv)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TL;DR:

  1. We can now pass a nil dagservice to "only hash". I needed to move this functionality down into the adder because I removed the SetMfsRoot function.
  2. Instead of setting adder.Pin, we now just pass a nil pinner to disable pinning. Really, I only needed 1 (see below) but I figured I'd make these consistent.

Alternatively, I could have added an OnlyHash option to the file adder.

Background:

  1. I wanted to move away from MFS for adding single files to get away from all the directory wrapping issues. However, the old adder kind of assumed MFS everywhere. It was technically possible to just not use it but I was worried about leaving the adder in an inconsistent state.
  2. The old adder wasn't safely reusable (as far as I can tell).

So I refactored it into:

  1. Adder: A reusable, immutable "adder" to carry all the add options, dag/pin/gc services, etc.
  2. adderJob: job for adding files/symlinks (embeds the Adder).
  3. dirAdderJob: job for adding directories (with mfs support) (embeds adderJob).

How does that relate to the changes above? Well, Adder no longer stores the MFS root (because adder is immutable/reusable). That meant SetMfsRoot had to go.


Really, we probably shouldn't be using MFS for importing files at all. I'm not sure why we are but we can fix that later.

return ch
}
func (noopDagService) Remove(_ context.Context, _ cid.Cid) error { return nil }
func (noopDagService) RemoveMany(_ context.Context, _ []cid.Cid) error { return nil }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably go elsewhere but I don't feel like bubbling go-ipld-format.

rnode.SetCidBuilder(job.CidBuilder)
ds := job.dagService
if ds == nil {
ds = mdutils.Mock()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mock dag should also go in go-ipld-format.

@Stebalien Stebalien force-pushed the fix/unixfs-add-wrap-simplify branch from 810544b to 79c12b2 Compare March 23, 2019 04:20
@Stebalien Stebalien changed the base branch from fix/unixfs-add-wrap to master March 23, 2019 04:52
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This makes it a bit easier to reason about the state of the adder.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
This way, we can entirely avoid MFS when adding single files.

This patch also changes how Pin/OnlyHash works. Instead of having a Pin option,
just construct the adder with a `nil` pinner to not pin. Likewise, we handle
"only hash" by passing a nil dagservice.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
@Stebalien Stebalien force-pushed the fix/unixfs-add-wrap-simplify branch from cd5d6b4 to 831b765 Compare March 23, 2019 05:09
@Stebalien
Copy link
Member Author

There's still something wrong with this...

@Stebalien Stebalien closed this Mar 25, 2019
@ghost ghost removed the status/in-progress In progress label Mar 25, 2019
@Stebalien
Copy link
Member Author

(not worth debugging for now)

@hacdias hacdias deleted the fix/unixfs-add-wrap-simplify branch May 9, 2023 10:56
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