Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/kubo
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0e4917729365
Choose a base ref
...
head repository: ipfs/kubo
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ebdd94897117
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 18, 2015

  1. 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>
    wking committed Jun 18, 2015
    Copy the full SHA
    fda0307 View commit details

Commits on Jun 19, 2015

  1. core/commands/unixfs/ls: Explicitily record stat in LsObject

    Instead of abusing a LsLink for non-directory objects [1].
    
    [1]: #1348 (comment)
    
    License: MIT
    Signed-off-by: W. Trevor King <wking@tremily.us>
    wking committed Jun 19, 2015
    Copy the full SHA
    ebdd948 View commit details
Showing with 45 additions and 38 deletions.
  1. +19 −19 core/commands/unixfs/ls.go
  2. +26 −19 test/sharness/t0200-unixfs-ls.sh
38 changes: 19 additions & 19 deletions core/commands/unixfs/ls.go
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ type LsLink struct {
}

type LsObject struct {
Hash string
Size uint64
Type string
Links []LsLink
}

@@ -85,31 +88,26 @@ directories, the child size is the IPFS link size.
continue
}

output.Objects[hash] = &LsObject{}

unixFSNode, err := unixfs.FromBytes(merkleNode.Data)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

t := unixFSNode.GetType()

output.Objects[hash] = &LsObject{
Hash: key.String(),
Type: t.String(),
Size: unixFSNode.GetFilesize(),
}

switch t {
default:
res.SetError(fmt.Errorf("unrecognized type: %s", t), cmds.ErrImplementation)
return
case unixfspb.Data_File:
key, err := merkleNode.Key()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
output.Objects[hash].Links = []LsLink{LsLink{
Name: fpath,
Hash: key.String(),
Type: t.String(),
Size: unixFSNode.GetFilesize(),
}}
break
case unixfspb.Data_Directory:
links := make([]LsLink, len(merkleNode.Links))
output.Objects[hash].Links = links
@@ -156,10 +154,10 @@ directories, the child size is the IPFS link size.
for argument := range output.Arguments {
hash := output.Arguments[argument]
object := output.Objects[hash]
if len(object.Links) == 1 && object.Links[0].Hash == hash {
nonDirectories = append(nonDirectories, argument)
} else {
if object.Type == "Directory" {
directories = append(directories, argument)
} else {
nonDirectories = append(nonDirectories, argument)
}
}
sort.Strings(nonDirectories)
@@ -181,9 +179,11 @@ directories, the child size is the IPFS link size.
if i > 0 || len(nonDirectories) > 0 {
fmt.Fprintln(w)
}
for _, arg := range directories[i:] {
if output.Arguments[arg] == hash {
fmt.Fprintf(w, "%s:\n", arg)
if len(output.Arguments) > 1 {
for _, arg := range directories[i:] {
if output.Arguments[arg] == hash {
fmt.Fprintf(w, "%s:\n", arg)
}
}
}
for _, link := range object.Links {
45 changes: 26 additions & 19 deletions test/sharness/t0200-unixfs-ls.sh
Original file line number Diff line number Diff line change
@@ -38,12 +38,24 @@ test_ls_cmd() {
test_cmp expected_add actual_add
'

test_expect_success "'ipfs file ls <dir>' succeeds" '
ipfs file ls QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy >actual_ls_one_directory
'

test_expect_success "'ipfs file ls <dir>' output looks good" '
cat <<-\EOF >expected_ls_one_directory &&
1024
a
EOF
test_cmp expected_ls_one_directory actual_ls_one_directory
'

test_expect_success "'ipfs file ls <three dir hashes>' succeeds" '
ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls
ipfs file ls QmfNy183bXiRVyrhyWtq3TwHn79yHEkiAGFr18P7YNzESj QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss >actual_ls_three_directories
'

test_expect_success "'ipfs file ls <three dir hashes>' output looks good" '
cat <<-\EOF >expected_ls &&
cat <<-\EOF >expected_ls_three_directories &&
QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy:
1024
a
@@ -58,7 +70,7 @@ test_ls_cmd() {
f1
f2
EOF
test_cmp expected_ls actual_ls
test_cmp expected_ls_three_directories actual_ls_three_directories
'

test_expect_success "'ipfs file ls <file hashes>' succeeds" '
@@ -102,14 +114,10 @@ test_ls_cmd() {
},
"Objects": {
"QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd": {
"Links": [
{
"Name": "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024",
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": "File"
}
]
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": "File",
"Links": null
}
}
}
@@ -133,6 +141,9 @@ test_ls_cmd() {
},
"Objects": {
"QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss": {
"Hash": "QmSix55yz8CzWXf5ZVM9vgEvijnEeeXiTSarVtsqiiCJss",
"Size": 0,
"Type": "Directory",
"Links": [
{
"Name": "128",
@@ -149,14 +160,10 @@ test_ls_cmd() {
]
},
"QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd": {
"Links": [
{
"Name": "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024",
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": "File"
}
]
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": "File",
"Links": null
}
}
}