-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
47 lines (38 loc) · 835 Bytes
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package corerepo
import (
"fmt"
"github.com/ipfs/go-ipfs/core"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
type Stat struct {
NumObjects uint64
RepoSize uint64 // size in bytes
RepoPath string
Version string
}
func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
r := n.Repo
usage, err := r.GetStorageUsage()
if err != nil {
return nil, err
}
allKeys, err := n.Blockstore.AllKeysChan(ctx)
if err != nil {
return nil, err
}
count := uint64(0)
for range allKeys {
count++
}
path, err := fsrepo.BestKnownPath()
if err != nil {
return nil, err
}
return &Stat{
NumObjects: count,
RepoSize: usage,
RepoPath: path,
Version: fmt.Sprintf("fs-repo@%d", fsrepo.RepoVersion),
}, nil
}