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

fix(unixfs): issue #5217 (Avoid use of pb.Data) #5505

Merged
merged 1 commit into from
Sep 24, 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
8 changes: 4 additions & 4 deletions core/commands/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,25 @@ func statNode(nd ipld.Node) (*statOutput, error) {

switch n := nd.(type) {
case *dag.ProtoNode:
d, err := ft.FromBytes(n.Data())
d, err := ft.FSNodeFromBytes(n.Data())
if err != nil {
return nil, err
}

var ndtype string
switch d.GetType() {
switch d.Type() {
case ft.TDirectory, ft.THAMTShard:
ndtype = "directory"
case ft.TFile, ft.TMetadata, ft.TRaw:
ndtype = "file"
default:
return nil, fmt.Errorf("unrecognized node type: %s", d.GetType())
return nil, fmt.Errorf("unrecognized node type: %s", d.Type())
}

return &statOutput{
Hash: c.String(),
Blocks: len(nd.Links()),
Size: d.GetFilesize(),
Size: d.FileSize(),
CumulativeSize: cumulsize,
Type: ndtype,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ The JSON output contains type information.
}

if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
d, err := unixfs.FromBytes(pn.Data())
d, err := unixfs.FSNodeFromBytes(pn.Data())
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
t = d.GetType()
t = d.Type()
}
}
output[i].Links[j] = LsLink{
Expand Down
12 changes: 6 additions & 6 deletions core/commands/unixfs/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ possible, please use 'ipfs ls' instead.
return
}

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

t := unixFSNode.GetType()
t := unixFSNode.Type()

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

switch t {
Expand All @@ -156,19 +156,19 @@ possible, please use 'ipfs ls' instead.
return
}

d, err := unixfs.FromBytes(lnpb.Data())
d, err := unixfs.FSNodeFromBytes(lnpb.Data())
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}
t := d.GetType()
t := d.Type()
lsLink := LsLink{
Name: link.Name,
Hash: link.Cid.String(),
Type: t.String(),
}
if t == unixfspb.Data_File {
lsLink.Size = d.GetFilesize()
lsLink.Size = d.FileSize()
} else {
lsLink.Size = link.Size
}
Expand Down