Commit 5fd4812b authored by W. Trevor King's avatar W. Trevor King

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: default avatarW. Trevor King <wking@tremily.us>
parent 7fc2410d
...@@ -184,11 +184,13 @@ directories, the child size is the IPFS link size. ...@@ -184,11 +184,13 @@ directories, the child size is the IPFS link size.
if i > 0 || len(nonDirectories) > 0 { if i > 0 || len(nonDirectories) > 0 {
fmt.Fprintln(w) fmt.Fprintln(w)
} }
if len(output.Arguments) > 1 {
for _, arg := range directories[i:] { for _, arg := range directories[i:] {
if output.Arguments[arg] == hash { if output.Arguments[arg] == hash {
fmt.Fprintf(w, "%s:\n", arg) fmt.Fprintf(w, "%s:\n", arg)
} }
} }
}
for _, link := range object.Links { for _, link := range object.Links {
fmt.Fprintf(w, "%s\n", link.Name) fmt.Fprintf(w, "%s\n", link.Name)
} }
......
...@@ -38,12 +38,24 @@ test_ls_cmd() { ...@@ -38,12 +38,24 @@ test_ls_cmd() {
test_cmp expected_add actual_add 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" ' 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" ' test_expect_success "'ipfs file ls <three dir hashes>' output looks good" '
cat <<-\EOF >expected_ls && cat <<-\EOF >expected_ls_three_directories &&
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy: QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy:
1024 1024
a a
...@@ -58,7 +70,7 @@ test_ls_cmd() { ...@@ -58,7 +70,7 @@ test_ls_cmd() {
f1 f1
f2 f2
EOF 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" ' test_expect_success "'ipfs file ls <file hashes>' succeeds" '
......
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