Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

feat: files (mfs) api #54

Closed
wants to merge 5 commits into from
Closed

feat: files (mfs) api #54

wants to merge 5 commits into from

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Dec 6, 2019

This adds support for Files API.

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Thanks! For some context, I think we punted on this as we wanted a unified interface for unixfs/files. However, given that we haven't made much progress on that, I'm happy to move this forward in the meantime and refactor later.


  1. Could you add some documentation to the interface?
    • Document that it's incomplete.
    • Document that that /ipfs and /ipns files can be copied in Copy.
  2. Could you also add a Remove method? That'll cover the key methods we actually need.

@hacdias
Copy link
Member Author

hacdias commented Dec 6, 2019

@Stebalien oh, this is a WIP, I haven't yet added all methods I'm thinking of adding 😄 nor the comments! I will do that and ping you again!

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias hacdias changed the title feat: files api feat: files (mfs) api Dec 7, 2019
@hacdias hacdias marked this pull request as ready for review December 7, 2019 12:40
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias
Copy link
Member Author

hacdias commented Dec 7, 2019

@Stebalien I actually implemented almost everything from the API as far as I know! Please take a look!

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

First pass.

If possible, could we pare down the scope of this? Move, Rename, and Remove are likely to make the final cut but the rest of the functions (read, write, etc.) were designed as a CLI API, not a programmatic API. Users should be able to open file-like objects with this API.

If necessary, we can try to tackle that right now but we'll have to sit down and try to figure out the right API.

// FilesAPI specifies an interface to interact with the Mutable File System
// layer.
type FilesAPI interface {
Copy(ctx context.Context, src, dst string, opts *FilesCopyOptions) error
Copy link
Member

Choose a reason for hiding this comment

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

This should use the functional options pattern we use in the other APIs. It allows us to add new complicated options (with logic) while retaining backwards compatibility.

See: https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis

type FilesAPI interface {
Copy(ctx context.Context, src, dst string, opts *FilesCopyOptions) error
Move(ctx context.Context, src, dst string, opts *FilesMoveOptions) error
List(ctx context.Context, path string, opts *FilesListOptions) ([]mfs.NodeListing, error)
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this streaming from the start. See #49

Copy link
Member

Choose a reason for hiding this comment

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

Let's re-use the return type from Unixfs().Ls(). I'd rather not expose internal mfs types in this API.

files.go Outdated Show resolved Hide resolved
files.go Outdated Show resolved Hide resolved
CidBuilder cid.Builder
}

type FileInfo struct {
Copy link
Member

Choose a reason for hiding this comment

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

docs

Size uint64
CumulativeSize uint64
Blocks int
Type string
Copy link
Member

Choose a reason for hiding this comment

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

Please use the file types from unixfs.go.

files.go Outdated Show resolved Hide resolved
Type string
WithLocality bool `json:",omitempty"`
Local bool `json:",omitempty"`
SizeLocal uint64 `json:",omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

Hm. I remember not liking this when it first came up. Can we come up with a better (internal) API and translate back at the edges? I'll think about this a bit but proposals are very welcome. For historical context: ipfs/kubo#4638

Hash string
Size uint64
CumulativeSize uint64
Blocks int
Copy link
Member

Choose a reason for hiding this comment

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

I have no idea why we called this "blocks". Let's call it what it is, Children (NumChildren?).

"github.com/ipfs/go-mfs"
)

type FilesCopyOptions struct {
Copy link
Member

Choose a reason for hiding this comment

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

Docs. Lots of docs.

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias
Copy link
Member Author

hacdias commented Dec 9, 2019

@Stebalien before continuing, I think it's best to define which functions to keep 😄 You said Move, Rename (one of these should be copy I presume) and Remove.

What if we keep:

  1. Copy
  2. Move or Rename (which name is better?)
  3. List
  4. Remove
  5. Stat
  6. Make Dir

With that, we would remove Flush (all operations would simply flush), Read (we get Stat and then get the Cid and use Unixfs API for now) and Write (Unixfs + Copy).

What do you think?

This was referenced Dec 11, 2019
@Stebalien
Copy link
Member

Status update: I believe we paused this in favor of trying to revive #19.

Closing for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to add files to MFS?
2 participants