Skip to content

Commit

Permalink
Add MaxStorage field to output of "repo stat".
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <k@kevina.org>
  • Loading branch information
kevina committed May 11, 2017
1 parent a6e96e6 commit 5abc198
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 14 additions & 0 deletions core/corerepo/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ 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 {
NumObjects uint64
RepoSize uint64 // size in bytes
RepoPath string
Version string
StorageMax uint64 // size in bytes
}

func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
Expand All @@ -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
}
5 changes: 3 additions & 2 deletions test/sharness/t0080-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "MaxStorage" repo-stats
'

test_expect_success "'ipfs repo stat' after adding a file" '
Expand Down

0 comments on commit 5abc198

Please sign in to comment.