Skip to content

Commit

Permalink
Merge pull request #2209 from ipfs/feat/stat-type
Browse files Browse the repository at this point in the history
make files stat print out node type
  • Loading branch information
jbenet committed Jan 17, 2016
2 parents f89a915 + f485fa4 commit 75a63b7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/commands/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ var FilesStatCmd = &cmds.Command{
fmt.Fprintf(buf, "Size: %d\n", out.Size)
fmt.Fprintf(buf, "CumulativeSize: %d\n", out.CumulativeSize)
fmt.Fprintf(buf, "ChildBlocks: %d\n", out.Blocks)
fmt.Fprintf(buf, "Type: %s\n", out.Type)
return buf, nil
},
},
Expand Down Expand Up @@ -115,11 +116,22 @@ func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
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{
Hash: k.B58String(),
Blocks: len(nd.Links),
Size: d.GetFilesize(),
CumulativeSize: cumulsize,
Type: ndtype,
}, nil
}

Expand Down Expand Up @@ -187,6 +199,7 @@ type Object struct {
Size uint64
CumulativeSize uint64
Blocks int
Type string
}

type FilesLsOutput struct {
Expand Down

0 comments on commit 75a63b7

Please sign in to comment.