-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
d0021bb
to
0a2c877
Compare
core/coreunix/add.go
Outdated
@@ -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, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moderately icky...
There was a problem hiding this comment.
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.
core/coreunix/add.go
Outdated
err := adder.addFileNode(fpath, it.Node(), false) | ||
node := it.Node() | ||
err := adder.addFileNode(fpath, node) | ||
node.Close() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 == "" { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
0a2c877
to
376d9ff
Compare
There was a problem hiding this 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 👍
core/coreunix/add.go
Outdated
err := adder.addFileNode(fpath, it.Node(), false) | ||
node := it.Node() | ||
err := adder.addFileNode(fpath, node) | ||
node.Close() |
There was a problem hiding this comment.
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 == "" { |
There was a problem hiding this comment.
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
62e215d
to
1fc7096
Compare
|
||
fileAdder, err := coreunix.NewAdder(ctx, pinning, addblockstore, dserv) | ||
fileAdder, err := coreunix.NewAdder(pinning, addblockstore, dserv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR:
- 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.
- 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:
- 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.
- The old adder wasn't safely reusable (as far as I can tell).
So I refactored it into:
Adder
: A reusable, immutable "adder" to carry all the add options, dag/pin/gc services, etc.adderJob
: job for adding files/symlinks (embeds theAdder
).dirAdderJob
: job for adding directories (with mfs support) (embedsadderJob
).
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 } |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
810544b
to
79c12b2
Compare
becec73
to
2d96b4d
Compare
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>
cd5d6b4
to
831b765
Compare
There's still something wrong with this... |
(not worth debugging for now) |
I'm not sure if this is entirely correct but basically:
Thoughts? This would also require removing all wrap logic from the core interface.
Depends on ipfs/interface-go-ipfs-core#21.