mirror of
https://github.com/octoleo/restic.git
synced 2024-11-10 23:31:09 +00:00
Merge pull request #3052 from restic/error-on-invalid-size
Return an error for invalid sizes
This commit is contained in:
commit
0db9024aad
@ -314,6 +314,10 @@ func rejectBySize(maxSizeStr string) (RejectFunc, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseSizeStr(sizeStr string) (int64, error) {
|
func parseSizeStr(sizeStr string) (int64, error) {
|
||||||
|
if sizeStr == "" {
|
||||||
|
return 0, errors.New("expected size, got empty string")
|
||||||
|
}
|
||||||
|
|
||||||
numStr := sizeStr[:len(sizeStr)-1]
|
numStr := sizeStr[:len(sizeStr)-1]
|
||||||
var unit int64 = 1
|
var unit int64 = 1
|
||||||
|
|
||||||
@ -333,7 +337,7 @@ func parseSizeStr(sizeStr string) (int64, error) {
|
|||||||
}
|
}
|
||||||
value, err := strconv.ParseInt(numStr, 10, 64)
|
value, err := strconv.ParseInt(numStr, 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil
|
return 0, err
|
||||||
}
|
}
|
||||||
return value * unit, nil
|
return value * unit, nil
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,25 @@ func TestParseSizeStr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseInvalidSizeStr(t *testing.T) {
|
||||||
|
invalidSizes := []string{
|
||||||
|
"",
|
||||||
|
" ",
|
||||||
|
"foobar",
|
||||||
|
"zzz",
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range invalidSizes {
|
||||||
|
v, err := parseSizeStr(s)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("wanted error for invalid value %q, got nil", s)
|
||||||
|
}
|
||||||
|
if v != 0 {
|
||||||
|
t.Errorf("wanted zero for invalid value %q, got: %v", s, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestIsExcludedByFileSize is for testing the instance of
|
// TestIsExcludedByFileSize is for testing the instance of
|
||||||
// --exclude-larger-than parameters
|
// --exclude-larger-than parameters
|
||||||
func TestIsExcludedByFileSize(t *testing.T) {
|
func TestIsExcludedByFileSize(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user