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>
W. Trevor King committed
Jun 18, 2015 at 16:31 UTC
5fd4812b2087bc634b33e3798b4d128854df5914
2 files changed
+20
-6
core/commands/unixfs/ls.go
+5
-3
@@ -184,9 +184,11 @@ directories, the child size is the IPFS link size.
184
if i > 0 || len(nonDirectories) > 0 {
185
fmt.Fprintln(w)
186
}
187
- for _, arg := range directories[i:] {
188
- if output.Arguments[arg] == hash {
189
- fmt.Fprintf(w, "%s:\n", arg)
187
+ if len(output.Arguments) > 1 {
188
+ for _, arg := range directories[i:] {
189
+ if output.Arguments[arg] == hash {
190
+ fmt.Fprintf(w, "%s:\n", arg)
191
+ }
192
}
193
}
194
for _, link := range object.Links {
test/sharness/t0200-unixfs-ls.sh
+15
-3
@@ -38,12 +38,24 @@ test_ls_cmd() {
38
test_cmp expected_add actual_add
39
'
40
41
+ test_expect_success "'ipfs file ls <dir>' succeeds" '
42
+ ipfs file ls QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy >actual_ls_one_directory
43
+ '
44
+
45
+ test_expect_success "'ipfs file ls <dir>' output looks good" '
46
+ cat <<-\EOF >expected_ls_one_directory &&
47
+ 1024
48
+ a
49
+ EOF
50
+ test_cmp expected_ls_one_directory actual_ls_one_directory
51
+ '
52
+
53
test_expect_success "'ipfs file ls <three dir hashes>' succeeds" '
42
- ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls
54
+ ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls_three_directories
55
'
56
57
test_expect_success "'ipfs file ls <three dir hashes>' output looks good" '
46
- cat <<-\EOF >expected_ls &&
58
+ cat <<-\EOF >expected_ls_three_directories &&
59
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy:
60
1024
61
a
@@ -58,7 +70,7 @@ test_ls_cmd() {
70
f1
71
f2
72
EOF
61
- test_cmp expected_ls actual_ls
73
+ test_cmp expected_ls_three_directories actual_ls_three_directories
74
'
75
76
test_expect_success "'ipfs file ls <file hashes>' succeeds" '