mirror of
https://github.com/ipfs/kubo.git
synced 2025-07-01 02:30:39 +08:00
fix panic in offline calls of 'ipfs object stat'
This commit is contained in:
@ -122,7 +122,7 @@ func SubtestNodeStat(t *testing.T, n *Node) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if expected != actual {
|
if expected != *actual {
|
||||||
t.Error("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
|
t.Error("n.Stat incorrect.\nexpect: %s\nactual: %s", expected, actual)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("n.Stat correct: %s\n", actual)
|
fmt.Printf("n.Stat correct: %s\n", actual)
|
||||||
|
@ -160,18 +160,18 @@ func (n *Node) Size() (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stat returns statistics on the node.
|
// Stat returns statistics on the node.
|
||||||
func (n *Node) Stat() (NodeStat, error) {
|
func (n *Node) Stat() (*NodeStat, error) {
|
||||||
enc, err := n.Encoded(false)
|
enc, err := n.Encoded(false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NodeStat{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cumSize, err := n.Size()
|
cumSize, err := n.Size()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NodeStat{}, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NodeStat{
|
return &NodeStat{
|
||||||
NumLinks: len(n.Links),
|
NumLinks: len(n.Links),
|
||||||
BlockSize: len(enc),
|
BlockSize: len(enc),
|
||||||
LinksSize: len(enc) - len(n.Data), // includes framing.
|
LinksSize: len(enc) - len(n.Data), // includes framing.
|
||||||
|
Reference in New Issue
Block a user