Skip to content

Commit

Permalink
core/commands/unixfs/ls.go: Fix (and test) single-directory listing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wking committed Jun 19, 2015
1 parent faf83f6 commit a891b30
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 5 additions & 3 deletions core/commands/unixfs/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions test/sharness/t0200-unixfs-ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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" '
Expand Down

0 comments on commit a891b30

Please sign in to comment.