@cryptotaxi247 / kubo / commits / 37f6a1bb8

"repo stat": Make special value to represent NoLimit a constant.

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

Kevin Atkinson committed Sep 18, 2017 at 19:26 UTC 37f6a1bb86f9bf54a5e945cba959c5a9e72dcd50
2 files changed +5 -3
core/commands/repo.go
+1 -2
@@ -4,7 +4,6 @@ import (
4 "bytes"
5 "fmt"
6 "io"
7 - "math"
7 "os"
8 "path/filepath"
9 "strings"
@@ -192,7 +191,7 @@ Version string The repo version.
191 } else {
192 fmt.Fprintf(wtr, "RepoSize:\t%d\n", stat.RepoSize)
193 }
195 - if stat.StorageMax != math.MaxUint64 {
194 + if stat.StorageMax != corerepo.NoLimit {
195 maxSizeInMiB := stat.StorageMax / (1024 * 1024)
196 if human && maxSizeInMiB > 0 {
197 fmt.Fprintf(wtr, "StorageMax (MiB):\t%d\n", maxSizeInMiB)
core/corerepo/stat.go
+4 -1
@@ -19,6 +19,9 @@ type Stat struct {
19 StorageMax uint64 // size in bytes
20 }
21
22 +// NoLimit represents the value for unlimited storage
23 +const NoLimit uint64 = math.MaxUint64
24 +
25 func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
26 r := n.Repo
27
@@ -47,7 +50,7 @@ func RepoStat(n *core.IpfsNode, ctx context.Context) (*Stat, error) {
50 return nil, err
51 }
52
50 - var storageMax uint64 = math.MaxUint64
53 + storageMax := NoLimit
54 if cfg.Datastore.StorageMax != "" {
55 storageMax, err = humanize.ParseBytes(cfg.Datastore.StorageMax)
56 if err != nil {