[lxc-devel] [lxd/master] shared/util: Fix unit parsing (metric vs iec)
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Jul 19 20:55:52 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180719/f8049000/attachment.bin>
-------------- next part --------------
From 6ca1e6026bc2f8f01c2499246c8ab5dadf8640d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 19 Jul 2018 16:54:37 -0400
Subject: [PATCH] shared/util: Fix unit parsing (metric vs iec)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/util.go | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/shared/util.go b/shared/util.go
index af03ed5b9..3ff052668 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -787,16 +787,28 @@ func ParseByteSizeString(input string) (int64, error) {
multiplicator := int64(0)
switch suffix {
case "kB":
- multiplicator = 1024
+ multiplicator = 1000
case "MB":
- multiplicator = 1024 * 1024
+ multiplicator = 1000 * 1000
case "GB":
- multiplicator = 1024 * 1024 * 1024
+ multiplicator = 1000 * 1000 * 1000
case "TB":
- multiplicator = 1024 * 1024 * 1024 * 1024
+ multiplicator = 1000 * 1000 * 1000 * 1000
case "PB":
- multiplicator = 1024 * 1024 * 1024 * 1024 * 1024
+ multiplicator = 1000 * 1000 * 1000 * 1000 * 1000
case "EB":
+ multiplicator = 1000 * 1000 * 1000 * 1000 * 1000 * 1000
+ case "KiB":
+ multiplicator = 1024
+ case "MiB":
+ multiplicator = 1024 * 1024
+ case "GiB":
+ multiplicator = 1024 * 1024 * 1024
+ case "TiB":
+ multiplicator = 1024 * 1024 * 1024 * 1024
+ case "PiB":
+ multiplicator = 1024 * 1024 * 1024 * 1024 * 1024
+ case "EiB":
multiplicator = 1024 * 1024 * 1024 * 1024 * 1024 * 1024
default:
return -1, fmt.Errorf("Unsupported suffix: %s", suffix)
More information about the lxc-devel
mailing list