Commit a62acc82 authored by Łukasz Magiera's avatar Łukasz Magiera

coreapi: stream only ls, handle storting in command

License: MIT
Signed-off-by: default avatarŁukasz Magiera <magik6k@gmail.com>
parent fad4bd39
......@@ -43,8 +43,6 @@ type UnixfsAddSettings struct {
}
type UnixfsLsSettings struct {
Async bool
ResolveType bool
ResolveSize bool
}
......@@ -132,8 +130,6 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
func UnixfsLsOptions(opts ...UnixfsLsOption) (*UnixfsLsSettings, error) {
options := &UnixfsLsSettings{
Async: true,
ResolveSize: true,
ResolveType: true,
}
......@@ -317,16 +313,6 @@ func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
}
}
// Async tells ls to return results as soon as they are available, which can be
// useful for listing HAMT directories. When this option is set to true returned
// results won't be returned in order
func (unixfsOpts) Async(async bool) UnixfsLsOption {
return func(settings *UnixfsLsSettings) error {
settings.Async = async
return nil
}
}
func (unixfsOpts) ResolveSize(resolve bool) UnixfsLsOption {
return func(settings *UnixfsLsSettings) error {
settings.ResolveSize = resolve
......
......@@ -749,7 +749,7 @@ func (tp *provider) TestLs(t *testing.T) {
t.Error(err)
}
links, err := api.Unixfs().Ls(ctx, p, options.Unixfs.Async(false))
links, err := api.Unixfs().Ls(ctx, p)
if err != nil {
t.Error(err)
}
......@@ -767,25 +767,6 @@ func (tp *provider) TestLs(t *testing.T) {
if _, ok := <-links; ok {
t.Errorf("didn't expect a second link")
}
links, err = api.Unixfs().Ls(ctx, p, options.Unixfs.Async(true))
if err != nil {
t.Error(err)
}
link = (<-links).Link
if link.Size != 23 {
t.Fatalf("expected size = 23, got %d", link.Size)
}
if link.Name != "name-of-file" {
t.Fatalf("expected name = name-of-file, got %s", link.Name)
}
if link.Cid.String() != "QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr" {
t.Fatalf("expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s", link.Cid)
}
if _, ok := <-links; ok {
t.Errorf("didn't expect a second link")
}
}
func (tp *provider) TestEntriesExpired(t *testing.T) {
......
......@@ -38,6 +38,7 @@ type UnixfsAPI interface {
// to operations performed on the returned file
Get(context.Context, Path) (files.Node, error)
// Ls returns the list of links in a directory
// Ls returns the list of links in a directory. Links aren't guaranteed to be
// returned in order
Ls(context.Context, Path, ...options.UnixfsLsOption) (<-chan LsLink, error)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment