Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(files): add slash for dir #5605

Merged
merged 2 commits into from
Oct 18, 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
5 changes: 4 additions & 1 deletion core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ Examples:
return
case *mfs.File:
_, name := gopath.Split(path)
out := &filesLsOutput{[]mfs.NodeListing{mfs.NodeListing{Name: name}}}
out := &filesLsOutput{[]mfs.NodeListing{{Name: name}}}
if long {
out.Entries[0].Type = int(fsn.Type())

Expand Down Expand Up @@ -527,6 +527,9 @@ Examples:
long, _, _ := res.Request().Option(longOptionName).Bool()
for _, o := range out.Entries {
if long {
if o.Type == int(mfs.TDir) {
o.Name += "/"
}
fmt.Fprintf(buf, "%s\t%s\t%d\n", o.Name, o.Hash, o.Size)
} else {
fmt.Fprintf(buf, "%s\n", o.Name)
Expand Down
7 changes: 7 additions & 0 deletions test/sharness/t0250-files-api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ test_files_api() {
verify_dir_contents /cats/this/is/a/dir
'

test_expect_success "dir has correct name" '
DIR_HASH=$(ipfs files stat /cats/this --hash) &&
echo "this/ $DIR_HASH 0" > ls_dir_expected &&
ipfs files ls -l /cats | grep this/ > ls_dir_actual &&
test_cmp ls_dir_expected ls_dir_actual
'

test_expect_success "can copy file into new dir $EXTRA" '
ipfs files cp /ipfs/$FILE3 /cats/this/is/a/dir/file3
'
Expand Down