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

Allow files to be wrapped with a mutator during add #5184

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,27 @@ func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds ipld

// Adder holds the switches passed to the `add` command.
type Adder struct {
ctx context.Context
pinning pin.Pinner
blockstore bstore.GCBlockstore
dagService ipld.DAGService
Out chan interface{}
Progress bool
Hidden bool
Pin bool
Trickle bool
RawLeaves bool
Silent bool
Wrap bool
NoCopy bool
Chunker string
root ipld.Node
mroot *mfs.Root
unlocker bstore.Unlocker
tempRoot *cid.Cid
Prefix *cid.Prefix
liveNodes uint64
ctx context.Context
pinning pin.Pinner
blockstore bstore.GCBlockstore
dagService ipld.DAGService
Out chan interface{}
Progress bool
Hidden bool
Pin bool
Trickle bool
RawLeaves bool
Silent bool
Wrap bool
NoCopy bool
Chunker string
FileWrapper func(io.Reader) (io.Reader, error)
Copy link
Contributor

@schomatis schomatis Jul 6, 2018

Choose a reason for hiding this comment

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

Why are all the field listed as modified? The FileWrapper is the only new field right? Also, just to be extra annoying, could we add a comment explaining the function of the newly added field? I'm a strong believer in the broken windows theory :)

Copy link
Member

Choose a reason for hiding this comment

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

That's gofmt. It aligns everything.

root ipld.Node
mroot *mfs.Root
unlocker bstore.Unlocker
tempRoot *cid.Cid
Prefix *cid.Prefix
liveNodes uint64
}

func (adder *Adder) mfsRoot() (*mfs.Root, error) {
Expand All @@ -114,6 +115,14 @@ func (adder *Adder) SetMfsRoot(r *mfs.Root) {

// Constructs a node from reader's data, and adds it. Doesn't pin.
func (adder *Adder) add(reader io.Reader) (ipld.Node, error) {
if adder.FileWrapper != nil {
wr, err := adder.FileWrapper(reader)
Copy link
Contributor

Choose a reason for hiding this comment

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

So, this is the single point of entry of a reader to the chunker right? (The other similar calls I'm finding in the code are for testing purposes only.)

if err != nil {
return nil, err
}
reader = wr
}

chnk, err := chunker.FromString(reader, adder.Chunker)
if err != nil {
return nil, err
Expand Down