ipfs files ls without -l is faster
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Nov 25, 2015 at 10:28 UTC
a961b1f7acdb4fc853fec5456e6d7bf2808ceca1
1 file changed
+24
-5
core/commands/files/files.go
+24
-5
@@ -235,14 +235,33 @@ Examples:
235
return
236
}
237
238
+ long, _, _ := req.Option("l").Bool()
239
+
240
switch fsn := fsn.(type) {
241
case *mfs.Directory:
240
- listing, err := fsn.List()
241
- if err != nil {
242
- res.SetError(err, cmds.ErrNormal)
243
- return
242
+ if !long {
243
+ mdnd, err := fsn.GetNode()
244
+ if err != nil {
245
+ res.SetError(err, cmds.ErrNormal)
246
+ return
247
+ }
248
+
249
+ var output []mfs.NodeListing
250
+ for _, lnk := range mdnd.Links {
251
+ output = append(output, mfs.NodeListing{
252
+ Name: lnk.Name,
253
+ Hash: lnk.Hash.B58String(),
254
+ })
255
+ }
256
+ res.SetOutput(&FilesLsOutput{output})
257
+ } else {
258
+ listing, err := fsn.List()
259
+ if err != nil {
260
+ res.SetError(err, cmds.ErrNormal)
261
+ return
262
+ }
263
+ res.SetOutput(&FilesLsOutput{listing})
264
}
245
- res.SetOutput(&FilesLsOutput{listing})
265
return
266
case *mfs.File:
267
_, name := gopath.Split(path)