mirror of
https://github.com/rclone/rclone.git
synced 2025-12-23 19:53:53 +00:00
fs: fix corruption of SizeSuffix with "B" suffix in config (eg --min-size)
Before this change, the config system round tripped fs.SizeSuffix
values through strings like this, corrupting them in the process.
"2B" -> 2 -> "2" -> 2048
This caused `--min-size 2B` to be interpreted as `--min-size 2k`.
This fix makes sure SizeSuffix values have a "B" suffix when turned
into a string where necessary, so it becomes
"2B" -> 2 -> "2B" -> 2
In rclone v2 we should probably declare unsuffixed SizeSuffix values
are in bytes not kBytes (done for rsync compatibility) but this would
be a backwards incompatible change which we don't want for v1.
Fixes #8437
Fixes #8212
Fixes #5169
This commit is contained in:
@@ -261,6 +261,34 @@ func TestOptionString(t *testing.T) {
|
||||
assert.Equal(t, "true", caseInsensitiveOption.String())
|
||||
}
|
||||
|
||||
func TestOptionStringStringArray(t *testing.T) {
|
||||
opt := Option{
|
||||
Name: "string_array",
|
||||
Default: []string(nil),
|
||||
}
|
||||
assert.Equal(t, "", opt.String())
|
||||
opt.Default = []string{}
|
||||
assert.Equal(t, "", opt.String())
|
||||
opt.Default = []string{"a", "b"}
|
||||
assert.Equal(t, "a,b", opt.String())
|
||||
opt.Default = []string{"hello, world!", "goodbye, world!"}
|
||||
assert.Equal(t, `"hello, world!","goodbye, world!"`, opt.String())
|
||||
}
|
||||
|
||||
func TestOptionStringSizeSuffix(t *testing.T) {
|
||||
opt := Option{
|
||||
Name: "size_suffix",
|
||||
Default: SizeSuffix(0),
|
||||
}
|
||||
assert.Equal(t, "0", opt.String())
|
||||
opt.Default = SizeSuffix(-1)
|
||||
assert.Equal(t, "off", opt.String())
|
||||
opt.Default = SizeSuffix(100)
|
||||
assert.Equal(t, "100B", opt.String())
|
||||
opt.Default = SizeSuffix(1024)
|
||||
assert.Equal(t, "1Ki", opt.String())
|
||||
}
|
||||
|
||||
func TestOptionSet(t *testing.T) {
|
||||
o := caseInsensitiveOption
|
||||
assert.Equal(t, true, o.Value)
|
||||
|
||||
Reference in New Issue
Block a user