@cryptotaxi247 / kubo / commits / f156f63ee

"repo stat": Don't crash when Datastore.StorageMax is not defined

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

Kevin Atkinson committed Sep 18, 2017 at 15:44 UTC f156f63eed735dcc4ff10e8e196f92fdd2cf1dea
3 files changed +22 -8
core/commands/repo.go
+8 -5
@@ -4,6 +4,7 @@ import (
4 "bytes"
5 "fmt"
6 "io"
7 + "math"
8 "os"
9 "path/filepath"
10 "strings"
@@ -191,11 +192,13 @@ Version string The repo version.
192 } else {
193 fmt.Fprintf(wtr, "RepoSize:\t%d\n", stat.RepoSize)
194 }
194 - maxSizeInMiB := stat.StorageMax / (1024 * 1024)
195 - if human && maxSizeInMiB > 0 {
196 - fmt.Fprintf(wtr, "StorageMax (MiB):\t%d\n", maxSizeInMiB)
197 - } else {
198 - fmt.Fprintf(wtr, "StorageMax:\t%d\n", stat.StorageMax)
195 + if stat.StorageMax != math.MaxUint64 {
196 + maxSizeInMiB := stat.StorageMax / (1024 * 1024)
197 + if human && maxSizeInMiB > 0 {
198 + fmt.Fprintf(wtr, "StorageMax (MiB):\t%d\n", maxSizeInMiB)
199 + } else {
200 + fmt.Fprintf(wtr, "StorageMax:\t%d\n", stat.StorageMax)
201 + }
202 }
203 fmt.Fprintf(wtr, "RepoPath:\t%s\n", stat.RepoPath)
204 fmt.Fprintf(wtr, "Version:\t%s\n", stat.Version)
core/corerepo/stat.go
+7 -3
@@ -2,6 +2,7 @@ package corerepo
2
3 import (
4 "fmt"
5 + "math"
6
7 context "context"
8 "github.com/ipfs/go-ipfs/core"
@@ -46,9 +47,12 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
47 return nil, err
48 }
49
49 - storageMax, err := humanize.ParseBytes(cfg.Datastore.StorageMax)
50 - if err != nil {
51 - return nil, err
50 + var storageMax uint64 = math.MaxUint64
51 + if cfg.Datastore.StorageMax != "" {
52 + storageMax, err = humanize.ParseBytes(cfg.Datastore.StorageMax)
53 + if err != nil {
54 + return nil, err
55 + }
56 }
57
58 return &Stat{
test/sharness/t0080-repo.sh
+7
@@ -263,4 +263,11 @@ test_expect_success "repo version came out correct" '
263
264 test_kill_ipfs_daemon
265
266 +test_expect_success "remove Datastore.StorageMax from config" '
267 + ipfs config Datastore.StorageMax ""
268 +'
269 +test_expect_success "'ipfs repo stat' still succeeds" '
270 + ipfs repo stat > repo-stats
271 +'
272 +
273 test_done