From dfe64980cef28b73965e85d2ef331c7cb5e855d1 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Tue, 29 May 2018 10:37:06 -0300 Subject: [PATCH 1/2] cmd: fix `files ls` to report hash and size for files License: MIT Signed-off-by: Lucas Molas --- core/commands/files.go | 19 ++++++++++++++++++- test/sharness/t0250-files-api.sh | 6 ++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/commands/files.go b/core/commands/files.go index cf29b568158..8d2112cde03 100644 --- a/core/commands/files.go +++ b/core/commands/files.go @@ -462,7 +462,24 @@ Examples: return case *mfs.File: _, name := gopath.Split(path) - out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{Name: name, Type: 1}}} + out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{Name: name}}} + if long { + out.Entries[0].Type = int(fsn.Type()) + + size, err := fsn.Size() + if err != nil { + res.SetError(err, cmdkit.ErrNormal) + return + } + out.Entries[0].Size = size + + nd, err := fsn.GetNode() + if err != nil { + res.SetError(err, cmdkit.ErrNormal) + return + } + out.Entries[0].Hash = nd.Cid().String() + } res.SetOutput(out) return default: diff --git a/test/sharness/t0250-files-api.sh b/test/sharness/t0250-files-api.sh index adf72efdc1d..ef2254a9368 100755 --- a/test/sharness/t0250-files-api.sh +++ b/test/sharness/t0250-files-api.sh @@ -186,6 +186,12 @@ test_files_api() { test_cmp ls_l_expected ls_l_actual ' + test_expect_success "file has correct hash and size listed with -l" ' + echo "file1 $FILE1 4" > ls_l_expected && + ipfs files ls -l /cats/file1 > ls_l_actual && + test_cmp ls_l_expected ls_l_actual + ' + test_expect_success "can stat file $EXTRA" ' ipfs files stat /cats/file1 > file1stat_orig ' From cbc239ce44ab79f3b33d56cafb1906bfe47e5857 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Sun, 1 Jul 2018 10:35:23 -0300 Subject: [PATCH 2/2] sharness: add `files ls` test (without `-l`) License: MIT Signed-off-by: Lucas Molas --- test/sharness/t0250-files-api.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/sharness/t0250-files-api.sh b/test/sharness/t0250-files-api.sh index ef2254a9368..61f52c2bf57 100755 --- a/test/sharness/t0250-files-api.sh +++ b/test/sharness/t0250-files-api.sh @@ -192,6 +192,12 @@ test_files_api() { test_cmp ls_l_expected ls_l_actual ' + test_expect_success "file shows up with the correct name" ' + echo "file1" > ls_l_expected && + ipfs files ls /cats/file1 > ls_l_actual && + test_cmp ls_l_expected ls_l_actual + ' + test_expect_success "can stat file $EXTRA" ' ipfs files stat /cats/file1 > file1stat_orig '