mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
build(deps): bump github.com/docker/go-units from 0.4.0 to 0.5.0
Bumps [github.com/docker/go-units](https://github.com/docker/go-units) from 0.4.0 to 0.5.0. - [Release notes](https://github.com/docker/go-units/releases) - [Commits](https://github.com/docker/go-units/compare/v0.4.0...v0.5.0) --- updated-dependencies: - dependency-name: github.com/docker/go-units dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
@@ -8,7 +8,7 @@ require (
|
|||||||
github.com/containerd/console v1.0.3
|
github.com/containerd/console v1.0.3
|
||||||
github.com/coreos/go-systemd/v22 v22.3.2
|
github.com/coreos/go-systemd/v22 v22.3.2
|
||||||
github.com/cyphar/filepath-securejoin v0.2.3
|
github.com/cyphar/filepath-securejoin v0.2.3
|
||||||
github.com/docker/go-units v0.4.0
|
github.com/docker/go-units v0.5.0
|
||||||
github.com/godbus/dbus/v5 v5.1.0
|
github.com/godbus/dbus/v5 v5.1.0
|
||||||
github.com/moby/sys/mountinfo v0.6.2
|
github.com/moby/sys/mountinfo v0.6.2
|
||||||
github.com/mrunalp/fileutils v0.5.0
|
github.com/mrunalp/fileutils v0.5.0
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxG
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
|
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
|
||||||
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||||
github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss=
|
github.com/frankban/quicktest v1.14.0 h1:+cqqvzZV87b4adx/5ayVOaYZ2CrvM4ejQvUdBzPPUss=
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
|
||||||
|
|||||||
+58
-12
@@ -2,7 +2,6 @@ package units
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -26,16 +25,17 @@ const (
|
|||||||
PiB = 1024 * TiB
|
PiB = 1024 * TiB
|
||||||
)
|
)
|
||||||
|
|
||||||
type unitMap map[string]int64
|
type unitMap map[byte]int64
|
||||||
|
|
||||||
var (
|
var (
|
||||||
decimalMap = unitMap{"k": KB, "m": MB, "g": GB, "t": TB, "p": PB}
|
decimalMap = unitMap{'k': KB, 'm': MB, 'g': GB, 't': TB, 'p': PB}
|
||||||
binaryMap = unitMap{"k": KiB, "m": MiB, "g": GiB, "t": TiB, "p": PiB}
|
binaryMap = unitMap{'k': KiB, 'm': MiB, 'g': GiB, 't': TiB, 'p': PiB}
|
||||||
sizeRegex = regexp.MustCompile(`^(\d+(\.\d+)*) ?([kKmMgGtTpP])?[iI]?[bB]?$`)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
|
var (
|
||||||
var binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
|
decimapAbbrs = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"}
|
||||||
|
binaryAbbrs = []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"}
|
||||||
|
)
|
||||||
|
|
||||||
func getSizeAndUnit(size float64, base float64, _map []string) (float64, string) {
|
func getSizeAndUnit(size float64, base float64, _map []string) (float64, string) {
|
||||||
i := 0
|
i := 0
|
||||||
@@ -89,20 +89,66 @@ func RAMInBytes(size string) (int64, error) {
|
|||||||
|
|
||||||
// Parses the human-readable size string into the amount it represents.
|
// Parses the human-readable size string into the amount it represents.
|
||||||
func parseSize(sizeStr string, uMap unitMap) (int64, error) {
|
func parseSize(sizeStr string, uMap unitMap) (int64, error) {
|
||||||
matches := sizeRegex.FindStringSubmatch(sizeStr)
|
// TODO: rewrite to use strings.Cut if there's a space
|
||||||
if len(matches) != 4 {
|
// once Go < 1.18 is deprecated.
|
||||||
|
sep := strings.LastIndexAny(sizeStr, "01234567890. ")
|
||||||
|
if sep == -1 {
|
||||||
|
// There should be at least a digit.
|
||||||
return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
|
return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
|
||||||
}
|
}
|
||||||
|
var num, sfx string
|
||||||
|
if sizeStr[sep] != ' ' {
|
||||||
|
num = sizeStr[:sep+1]
|
||||||
|
sfx = sizeStr[sep+1:]
|
||||||
|
} else {
|
||||||
|
// Omit the space separator.
|
||||||
|
num = sizeStr[:sep]
|
||||||
|
sfx = sizeStr[sep+1:]
|
||||||
|
}
|
||||||
|
|
||||||
size, err := strconv.ParseFloat(matches[1], 64)
|
size, err := strconv.ParseFloat(num, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
// Backward compatibility: reject negative sizes.
|
||||||
|
if size < 0 {
|
||||||
|
return -1, fmt.Errorf("invalid size: '%s'", sizeStr)
|
||||||
|
}
|
||||||
|
|
||||||
unitPrefix := strings.ToLower(matches[3])
|
if len(sfx) == 0 {
|
||||||
if mul, ok := uMap[unitPrefix]; ok {
|
return int64(size), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the suffix.
|
||||||
|
|
||||||
|
if len(sfx) > 3 { // Too long.
|
||||||
|
goto badSuffix
|
||||||
|
}
|
||||||
|
sfx = strings.ToLower(sfx)
|
||||||
|
// Trivial case: b suffix.
|
||||||
|
if sfx[0] == 'b' {
|
||||||
|
if len(sfx) > 1 { // no extra characters allowed after b.
|
||||||
|
goto badSuffix
|
||||||
|
}
|
||||||
|
return int64(size), nil
|
||||||
|
}
|
||||||
|
// A suffix from the map.
|
||||||
|
if mul, ok := uMap[sfx[0]]; ok {
|
||||||
size *= float64(mul)
|
size *= float64(mul)
|
||||||
|
} else {
|
||||||
|
goto badSuffix
|
||||||
|
}
|
||||||
|
|
||||||
|
// The suffix may have extra "b" or "ib" (e.g. KiB or MB).
|
||||||
|
switch {
|
||||||
|
case len(sfx) == 2 && sfx[1] != 'b':
|
||||||
|
goto badSuffix
|
||||||
|
case len(sfx) == 3 && sfx[1:] != "ib":
|
||||||
|
goto badSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
return int64(size), nil
|
return int64(size), nil
|
||||||
|
|
||||||
|
badSuffix:
|
||||||
|
return -1, fmt.Errorf("invalid suffix: '%s'", sfx)
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -24,7 +24,7 @@ github.com/cpuguy83/go-md2man/v2/md2man
|
|||||||
# github.com/cyphar/filepath-securejoin v0.2.3
|
# github.com/cyphar/filepath-securejoin v0.2.3
|
||||||
## explicit; go 1.13
|
## explicit; go 1.13
|
||||||
github.com/cyphar/filepath-securejoin
|
github.com/cyphar/filepath-securejoin
|
||||||
# github.com/docker/go-units v0.4.0
|
# github.com/docker/go-units v0.5.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/docker/go-units
|
github.com/docker/go-units
|
||||||
# github.com/godbus/dbus/v5 v5.1.0
|
# github.com/godbus/dbus/v5 v5.1.0
|
||||||
|
|||||||
Reference in New Issue
Block a user