1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-29 01:12:24 +08:00

Merge pull request #2209 from ipfs/feat/stat-type

make files stat print out node type
This commit is contained in:
Juan Benet
2016-01-16 19:38:50 -05:00

View File

@ -87,6 +87,7 @@ var FilesStatCmd = &cmds.Command{
fmt.Fprintf(buf, "Size: %d\n", out.Size) fmt.Fprintf(buf, "Size: %d\n", out.Size)
fmt.Fprintf(buf, "CumulativeSize: %d\n", out.CumulativeSize) fmt.Fprintf(buf, "CumulativeSize: %d\n", out.CumulativeSize)
fmt.Fprintf(buf, "ChildBlocks: %d\n", out.Blocks) fmt.Fprintf(buf, "ChildBlocks: %d\n", out.Blocks)
fmt.Fprintf(buf, "Type: %s\n", out.Type)
return buf, nil return buf, nil
}, },
}, },
@ -115,11 +116,22 @@ func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
return nil, err return nil, err
} }
var ndtype string
switch fsn.Type() {
case mfs.TDir:
ndtype = "directory"
case mfs.TFile:
ndtype = "file"
default:
return nil, fmt.Errorf("unrecognized node type: %s", fsn.Type())
}
return &Object{ return &Object{
Hash: k.B58String(), Hash: k.B58String(),
Blocks: len(nd.Links), Blocks: len(nd.Links),
Size: d.GetFilesize(), Size: d.GetFilesize(),
CumulativeSize: cumulsize, CumulativeSize: cumulsize,
Type: ndtype,
}, nil }, nil
} }
@ -187,6 +199,7 @@ type Object struct {
Size uint64 Size uint64
CumulativeSize uint64 CumulativeSize uint64
Blocks int Blocks int
Type string
} }
type FilesLsOutput struct { type FilesLsOutput struct {