diff --git a/core/commands/ls.go b/core/commands/ls.go index bf16280cc35c..268229f6a9b6 100644 --- a/core/commands/ls.go +++ b/core/commands/ls.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "os" + "sort" "text/tabwriter" cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv" @@ -112,6 +113,10 @@ The JSON output contains type information. return nil }, func(i int) { // after each dir + sort.Slice(outputLinks, func(i, j int) bool { + return outputLinks[i].Name < outputLinks[j].Name + }) + output[i] = LsObject{ Hash: paths[i], Links: outputLinks, @@ -131,7 +136,6 @@ The JSON output contains type information. } results, err := api.Unixfs().Ls(req.Context, p, - options.Unixfs.Async(stream), options.Unixfs.ResolveType(resolveType), options.Unixfs.ResolveSize(resolveSize)) if err != nil { diff --git a/core/coreapi/interface/options/unixfs.go b/core/coreapi/interface/options/unixfs.go index 4ff5cdb3f817..7e77410bc60b 100644 --- a/core/coreapi/interface/options/unixfs.go +++ b/core/coreapi/interface/options/unixfs.go @@ -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 diff --git a/core/coreapi/interface/tests/unixfs.go b/core/coreapi/interface/tests/unixfs.go index b2b5a9ebb037..054461de1d86 100644 --- a/core/coreapi/interface/tests/unixfs.go +++ b/core/coreapi/interface/tests/unixfs.go @@ -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) { diff --git a/core/coreapi/interface/unixfs.go b/core/coreapi/interface/unixfs.go index 846b74629617..a77011988d5a 100644 --- a/core/coreapi/interface/unixfs.go +++ b/core/coreapi/interface/unixfs.go @@ -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) } diff --git a/core/coreapi/unixfs.go b/core/coreapi/unixfs.go index 5a3802fea44e..df0a58595ec4 100644 --- a/core/coreapi/unixfs.go +++ b/core/coreapi/unixfs.go @@ -167,10 +167,6 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path, opts ...options. return nil, err } - if !settings.Async { - return uses.lsFromDir(ctx, dir, settings) - } - return uses.lsFromLinksAsync(ctx, dir, settings) } @@ -234,14 +230,6 @@ func (api *UnixfsAPI) lsFromLinksAsync(ctx context.Context, dir uio.Directory, s return out, nil } -func (api *UnixfsAPI) lsFromDir(ctx context.Context, dir uio.Directory, settings *options.UnixfsLsSettings) (<-chan coreiface.LsLink, error) { - l, err := dir.Links(ctx) - if err != nil { - return nil, err - } - return api.lsFromLinks(ctx, l, settings) -} - func (api *UnixfsAPI) lsFromLinks(ctx context.Context, ndlinks []*ipld.Link, settings *options.UnixfsLsSettings) (<-chan coreiface.LsLink, error) { links := make(chan coreiface.LsLink, len(ndlinks)) for _, l := range ndlinks {