@cryptotaxi247 / kubo / commits / 48c3effac

fix(unixfs): issue #5217

License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>

Overbool committed Sep 21, 2018 at 13:21 UTC 48c3effac887614671d22d58f912f5e135a46f3c
3 files changed +12 -12
core/commands/files.go
+4 -4
@@ -223,25 +223,25 @@ func statNode(nd ipld.Node) (*statOutput, error) {
223
224 switch n := nd.(type) {
225 case *dag.ProtoNode:
226 - d, err := ft.FromBytes(n.Data())
226 + d, err := ft.FSNodeFromBytes(n.Data())
227 if err != nil {
228 return nil, err
229 }
230
231 var ndtype string
232 - switch d.GetType() {
232 + switch d.Type() {
233 case ft.TDirectory, ft.THAMTShard:
234 ndtype = "directory"
235 case ft.TFile, ft.TMetadata, ft.TRaw:
236 ndtype = "file"
237 default:
238 - return nil, fmt.Errorf("unrecognized node type: %s", d.GetType())
238 + return nil, fmt.Errorf("unrecognized node type: %s", d.Type())
239 }
240
241 return &statOutput{
242 Hash: c.String(),
243 Blocks: len(nd.Links()),
244 - Size: d.GetFilesize(),
244 + Size: d.FileSize(),
245 CumulativeSize: cumulsize,
246 Type: ndtype,
247 }, nil
core/commands/ls.go
+2 -2
@@ -150,12 +150,12 @@ The JSON output contains type information.
150 }
151
152 if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
153 - d, err := unixfs.FromBytes(pn.Data())
153 + d, err := unixfs.FSNodeFromBytes(pn.Data())
154 if err != nil {
155 res.SetError(err, cmdkit.ErrNormal)
156 return
157 }
158 - t = d.GetType()
158 + t = d.Type()
159 }
160 }
161 output[i].Links[j] = LsLink{
core/commands/unixfs/ls.go
+6 -6
@@ -120,18 +120,18 @@ possible, please use 'ipfs ls' instead.
120 return
121 }
122
123 - unixFSNode, err := unixfs.FromBytes(ndpb.Data())
123 + unixFSNode, err := unixfs.FSNodeFromBytes(ndpb.Data())
124 if err != nil {
125 res.SetError(err, cmdkit.ErrNormal)
126 return
127 }
128
129 - t := unixFSNode.GetType()
129 + t := unixFSNode.Type()
130
131 output.Objects[hash] = &LsObject{
132 Hash: c.String(),
133 Type: t.String(),
134 - Size: unixFSNode.GetFilesize(),
134 + Size: unixFSNode.FileSize(),
135 }
136
137 switch t {
@@ -156,19 +156,19 @@ possible, please use 'ipfs ls' instead.
156 return
157 }
158
159 - d, err := unixfs.FromBytes(lnpb.Data())
159 + d, err := unixfs.FSNodeFromBytes(lnpb.Data())
160 if err != nil {
161 res.SetError(err, cmdkit.ErrNormal)
162 return
163 }
164 - t := d.GetType()
164 + t := d.Type()
165 lsLink := LsLink{
166 Name: link.Name,
167 Hash: link.Cid.String(),
168 Type: t.String(),
169 }
170 if t == unixfspb.Data_File {
171 - lsLink.Size = d.GetFilesize()
171 + lsLink.Size = d.FileSize()
172 } else {
173 lsLink.Size = link.Size
174 }