@cryptotaxi247 / kubo / commits / 0f46a34f5

Add MaxStorage field to output of "repo stat".

License: MIT Signed-off-by: Kevin Atkinson <k@kevina.org>

Kevin Atkinson committed May 10, 2017 at 23:41 UTC 0f46a34f598378ad51b22afe0f92846ba4759a98
3 files changed +23 -2
core/commands/repo.go
+6
@@ -189,6 +189,12 @@ Version string The repo version.
189 } else {
190 fmt.Fprintf(buf, "RepoSize \t %d\n", stat.RepoSize)
191 }
192 + maxSizeInMiB := stat.StorageMax / (1024 * 1024)
193 + if human && maxSizeInMiB > 0 {
194 + fmt.Fprintf(buf, "StorageMax (MiB) \t %d\n", maxSizeInMiB)
195 + } else {
196 + fmt.Fprintf(buf, "StorageMax \t %d\n", stat.StorageMax)
197 + }
198 fmt.Fprintf(buf, "RepoPath \t %s\n", stat.RepoPath)
199 fmt.Fprintf(buf, "Version \t %s\n", stat.Version)
200
core/corerepo/stat.go
+14
@@ -6,6 +6,8 @@ import (
6 context "context"
7 "github.com/ipfs/go-ipfs/core"
8 fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
9 +
10 + humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
11 )
12
13 type Stat struct {
@@ -13,6 +15,7 @@ type Stat struct {
15 RepoSize uint64 // size in bytes
16 RepoPath string
17 Version string
18 + StorageMax uint64 // size in bytes
19 }
20
21 func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
@@ -38,10 +41,21 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
41 return nil, err
42 }
43
44 + cfg, err := r.Config()
45 + if err != nil {
46 + return nil, err
47 + }
48 +
49 + storageMax, err := humanize.ParseBytes(cfg.Datastore.StorageMax)
50 + if err != nil {
51 + return nil, err
52 + }
53 +
54 return &Stat{
55 NumObjects: count,
56 RepoSize: usage,
57 RepoPath: path,
58 Version: fmt.Sprintf("fs-repo@%d", fsrepo.RepoVersion),
59 + StorageMax: storageMax,
60 }, nil
61 }
test/sharness/t0080-repo.sh
+3 -2
@@ -232,8 +232,9 @@ test_expect_success "'ipfs repo stat' succeeds" '
232 test_expect_success "repo stats came out correct" '
233 grep "RepoPath" repo-stats &&
234 grep "RepoSize" repo-stats &&
235 - grep "NumObjects" repo-stats
236 - grep "Version" repo-stats
235 + grep "NumObjects" repo-stats &&
236 + grep "Version" repo-stats &&
237 + grep "StorageMax" repo-stats
238 '
239
240 test_expect_success "'ipfs repo stat' after adding a file" '