Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs: Extend SizeSuffix to include TB and PB for rclone about

Nick Craig-Woodef3bcec76c5c
diff --git a/docs/content/docs.md b/docs/content/docs.md
index 363302353..133284da7 100644
--- a/docs/content/docs.md
+++ b/docs/content/docs.md
@@ -227,9 +227,9 @@ fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid
time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Options which use SIZE use kByte by default. However, a suffix of `b`
-for bytes, `k` for kBytes, `M` for MBytes and `G` for GBytes may be
-used. These are the binary units, eg 1, 2\*\*10, 2\*\*20, 2\*\*30
-respectively.
+for bytes, `k` for kBytes, `M` for MBytes, `G` for GBytes, `T` for
+TBytes and `P` for PBytes may be used. These are the binary units, eg
+1, 2\*\*10, 2\*\*20, 2\*\*30 respectively.
### --backup-dir=DIR ###
diff --git a/fs/sizesuffix.go b/fs/sizesuffix.go
index 14652c3d5..adf2493fe 100644
--- a/fs/sizesuffix.go
+++ b/fs/sizesuffix.go
@@ -22,18 +22,24 @@ func (x SizeSuffix) string() (string, string) {
return "off", ""
case x == 0:
return "0", ""
- case x < 1024:
+ case x < 1<<10:
scaled = float64(x)
suffix = ""
- case x < 1024*1024:
- scaled = float64(x) / 1024
+ case x < 1<<20:
+ scaled = float64(x) / (1 << 10)
suffix = "k"
- case x < 1024*1024*1024:
- scaled = float64(x) / 1024 / 1024
+ case x < 1<<30:
+ scaled = float64(x) / (1 << 20)
suffix = "M"
- default:
- scaled = float64(x) / 1024 / 1024 / 1024
+ case x < 1<<40:
+ scaled = float64(x) / (1 << 30)
suffix = "G"
+ case x < 1<<50:
+ scaled = float64(x) / (1 << 40)
+ suffix = "T"
+ default:
+ scaled = float64(x) / (1 << 50)
+ suffix = "P"
}
if math.Floor(scaled) == scaled {
return fmt.Sprintf("%.0f", scaled), suffix
@@ -80,6 +86,10 @@ func (x *SizeSuffix) Set(s string) error {
multiplier = 1 << 20
case 'g', 'G':
multiplier = 1 << 30
+ case 't', 'T':
+ multiplier = 1 << 40
+ case 'p', 'P':
+ multiplier = 1 << 50
default:
return errors.Errorf("bad suffix %q", suffix)
}
diff --git a/fs/sizesuffix_test.go b/fs/sizesuffix_test.go
index 45f8baa15..25529f997 100644
--- a/fs/sizesuffix_test.go
+++ b/fs/sizesuffix_test.go
@@ -44,6 +44,9 @@ func TestSizeSuffixUnit(t *testing.T) {
{1024 * 1024 * 1024, "1 GBytes"},
{10 * 1024 * 1024 * 1024, "10 GBytes"},
{10.1 * 1024 * 1024 * 1024, "10.100 GBytes"},
+ {10 * 1024 * 1024 * 1024 * 1024, "10 TBytes"},
+ {10 * 1024 * 1024 * 1024 * 1024 * 1024, "10 PBytes"},
+ {1 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024, "1024 PBytes"},
{-1, "off"},
{-100, "off"},
} {
@@ -70,20 +73,22 @@ func TestSizeSuffixSet(t *testing.T) {
{"1M", 1024 * 1024, false},
{"1.g", 1024 * 1024 * 1024, false},
{"10G", 10 * 1024 * 1024 * 1024, false},
+ {"10T", 10 * 1024 * 1024 * 1024 * 1024, false},
+ {"10P", 10 * 1024 * 1024 * 1024 * 1024 * 1024, false},
{"off", -1, false},
{"OFF", -1, false},
{"", 0, true},
- {"1p", 0, true},
- {"1.p", 0, true},
- {"1p", 0, true},
+ {"1q", 0, true},
+ {"1.q", 0, true},
+ {"1q", 0, true},
{"-1K", 0, true},
} {
ss := SizeSuffix(0)
err := ss.Set(test.in)
if test.err {
- require.Error(t, err)
+ require.Error(t, err, test.in)
} else {
- require.NoError(t, err)
+ require.NoError(t, err, test.in)
}
assert.Equal(t, test.want, int64(ss))
}