From 5fd4812b2087bc634b33e3798b4d128854df5914 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" <wking@tremily.us> Date: Thu, 18 Jun 2015 16:31:18 -0700 Subject: [PATCH] core/commands/unixfs/ls.go: Fix (and test) single-directory listing We don't want to prefix these results with the argument. If there was only one argument, the unprefixed results are still explicit. License: MIT Signed-off-by: W. Trevor King <wking@tremily.us> --- core/commands/unixfs/ls.go | 8 +++++--- test/sharness/t0200-unixfs-ls.sh | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/commands/unixfs/ls.go b/core/commands/unixfs/ls.go index ed1f70a88..ed2c0b133 100644 --- a/core/commands/unixfs/ls.go +++ b/core/commands/unixfs/ls.go @@ -184,9 +184,11 @@ directories, the child size is the IPFS link size. if i > 0 || len(nonDirectories) > 0 { fmt.Fprintln(w) } - for _, arg := range directories[i:] { - if output.Arguments[arg] == hash { - fmt.Fprintf(w, "%s:\n", arg) + if len(output.Arguments) > 1 { + for _, arg := range directories[i:] { + if output.Arguments[arg] == hash { + fmt.Fprintf(w, "%s:\n", arg) + } } } for _, link := range object.Links { diff --git a/test/sharness/t0200-unixfs-ls.sh b/test/sharness/t0200-unixfs-ls.sh index 51ba0614b..a79c098a4 100755 --- a/test/sharness/t0200-unixfs-ls.sh +++ b/test/sharness/t0200-unixfs-ls.sh @@ -38,12 +38,24 @@ test_ls_cmd() { test_cmp expected_add actual_add ' + test_expect_success "'ipfs file ls <dir>' succeeds" ' + ipfs file ls QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy >actual_ls_one_directory + ' + + test_expect_success "'ipfs file ls <dir>' output looks good" ' + cat <<-\EOF >expected_ls_one_directory && + 1024 + a + EOF + test_cmp expected_ls_one_directory actual_ls_one_directory + ' + test_expect_success "'ipfs file ls <three dir hashes>' succeeds" ' - ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls + ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls_three_directories ' test_expect_success "'ipfs file ls <three dir hashes>' output looks good" ' - cat <<-\EOF >expected_ls && + cat <<-\EOF >expected_ls_three_directories && QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy: 1024 a @@ -58,7 +70,7 @@ test_ls_cmd() { f1 f2 EOF - test_cmp expected_ls actual_ls + test_cmp expected_ls_three_directories actual_ls_three_directories ' test_expect_success "'ipfs file ls <file hashes>' succeeds" ' -- GitLab