Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd: fix files ls to report hash and size for files #5045

Merged
merged 2 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ 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
'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test for the ls output without -l is unchanged when used on a file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

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
'
Expand Down