mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 19:44:01 +08:00
Fix "files stat" to work on raw nodes.
License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>
This commit is contained in:
@ -168,38 +168,46 @@ func statNode(ds dag.DAGService, fsn mfs.FSNode) (*Object, error) {
|
||||
|
||||
c := nd.Cid()
|
||||
|
||||
pbnd, ok := nd.(*dag.ProtoNode)
|
||||
if !ok {
|
||||
return nil, dag.ErrNotProtobuf
|
||||
}
|
||||
|
||||
d, err := ft.FromBytes(pbnd.Data())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cumulsize, err := nd.Size()
|
||||
if err != nil {
|
||||
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())
|
||||
}
|
||||
switch n := nd.(type) {
|
||||
case *dag.ProtoNode:
|
||||
d, err := ft.FromBytes(n.Data())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Object{
|
||||
Hash: c.String(),
|
||||
Blocks: len(nd.Links()),
|
||||
Size: d.GetFilesize(),
|
||||
CumulativeSize: cumulsize,
|
||||
Type: ndtype,
|
||||
}, nil
|
||||
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: c.String(),
|
||||
Blocks: len(nd.Links()),
|
||||
Size: d.GetFilesize(),
|
||||
CumulativeSize: cumulsize,
|
||||
Type: ndtype,
|
||||
}, nil
|
||||
case *dag.RawNode:
|
||||
return &Object{
|
||||
Hash: c.String(),
|
||||
Blocks: 0,
|
||||
Size: cumulsize,
|
||||
CumulativeSize: cumulsize,
|
||||
Type: "file",
|
||||
}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("not unixfs node (proto or raw)")
|
||||
}
|
||||
}
|
||||
|
||||
var FilesCpCmd = &cmds.Command{
|
||||
|
@ -177,6 +177,19 @@ test_files_api() {
|
||||
test_cmp ls_l_expected ls_l_actual
|
||||
'
|
||||
|
||||
test_expect_success "can stat file $EXTRA" '
|
||||
ipfs files stat /cats/file1 > file1stat_orig
|
||||
'
|
||||
|
||||
test_expect_success "stat output looks good" '
|
||||
grep -v CumulativeSize: file1stat_orig > file1stat_actual &&
|
||||
echo "$FILE1" > file1stat_expect &&
|
||||
echo "Size: 4" >> file1stat_expect &&
|
||||
echo "ChildBlocks: 0" >> file1stat_expect &&
|
||||
echo "Type: file" >> file1stat_expect &&
|
||||
test_cmp file1stat_expect file1stat_actual
|
||||
'
|
||||
|
||||
test_expect_success "can read file $EXTRA" '
|
||||
ipfs files read /cats/file1 > file1out
|
||||
'
|
||||
|
Reference in New Issue
Block a user