cmd: fix `files ls` to report hash and size for files
License: MIT Signed-off-by: Lucas Molas <schomatis@gmail.com>
Lucas Molas committed
May 29, 2018 at 10:37 UTC
dfe64980cef28b73965e85d2ef331c7cb5e855d1
2 files changed
+24
-1
core/commands/files.go
+18
-1
@@ -462,7 +462,24 @@ Examples:
462
return
463
case *mfs.File:
464
_, name := gopath.Split(path)
465
- out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{Name: name, Type: 1}}}
465
+ out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{Name: name}}}
466
+ if long {
467
+ out.Entries[0].Type = int(fsn.Type())
468
+
469
+ size, err := fsn.Size()
470
+ if err != nil {
471
+ res.SetError(err, cmdkit.ErrNormal)
472
+ return
473
+ }
474
+ out.Entries[0].Size = size
475
+
476
+ nd, err := fsn.GetNode()
477
+ if err != nil {
478
+ res.SetError(err, cmdkit.ErrNormal)
479
+ return
480
+ }
481
+ out.Entries[0].Hash = nd.Cid().String()
482
+ }
483
res.SetOutput(out)
484
return
485
default:
test/sharness/t0250-files-api.sh
+6
@@ -186,6 +186,12 @@ test_files_api() {
186
test_cmp ls_l_expected ls_l_actual
187
'
188
189
+ test_expect_success "file has correct hash and size listed with -l" '
190
+ echo "file1 $FILE1 4" > ls_l_expected &&
191
+ ipfs files ls -l /cats/file1 > ls_l_actual &&
192
+ test_cmp ls_l_expected ls_l_actual
193
+ '
194
+
195
test_expect_success "can stat file $EXTRA" '
196
ipfs files stat /cats/file1 > file1stat_orig
197
'