提交 0f46a34f 作者: Kevin Atkinson

Add MaxStorage field to output of "repo stat".

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 a6e96e6c
......@@ -189,6 +189,12 @@ Version string The repo version.
} else {
fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize)
}
maxSizeInMiB := stat.StorageMax / (1024 * 1024)
if human && maxSizeInMiB > 0 {
fmt.Fprintf(buf, "StorageMax (MiB) \t %d\n", maxSizeInMiB)
} else {
fmt.Fprintf(buf, "StorageMax \t %d\n", stat.StorageMax)
}
fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
fmt.Fprintf(buf, "Version \t %s\n", stat.Version)
......
......@@ -6,6 +6,8 @@ import (
context "context"
"github.com/ipfs/go-ipfs/core"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
)
type Stat struct {
......@@ -13,6 +15,7 @@ type Stat struct {
RepoSize uint64 // size in bytes
RepoPath string
Version string
StorageMax uint64 // size in bytes
}
func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
......@@ -38,10 +41,21 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
return nil, err
}
cfg, err := r.Config()
if err != nil {
return nil, err
}
storageMax, err := humanize.ParseBytes(cfg.Datastore.StorageMax)
if err != nil {
return nil, err
}
return &Stat{
NumObjects: count,
RepoSize: usage,
RepoPath: path,
Version: fmt.Sprintf("fs-repo@%d", fsrepo.RepoVersion),
StorageMax: storageMax,
}, nil
}
......@@ -232,8 +232,9 @@ test_expect_success "'ipfs repo stat' succeeds" '
test_expect_success "repo stats came out correct" '
grep "RepoPath" repo-stats &&
grep "RepoSize" repo-stats &&
grep "NumObjects" repo-stats
grep "Version" repo-stats
grep "NumObjects" repo-stats &&
grep "Version" repo-stats &&
grep "StorageMax" repo-stats
'
test_expect_success "'ipfs repo stat' after adding a file" '
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论