2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

Add upper bound for t in --read-data-subset=n/t (#2304)

* Add upper bound for t in --read-data-subset=n/t

* Add changelog entry
This commit is contained in:
Fred Akalin 2019-06-29 11:34:54 -07:00 committed by ifedorenko
parent 5bd5db4294
commit 3ca424050f
2 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,7 @@
Bugfix: Add upper bound for t in --read-data-subset=n/t
256 is the effective maximum for t, but restic would allow larger
values, leading to strange behavior.
https://github.com/restic/restic/issues/2301
https://github.com/restic/restic/pull/2304

View File

@ -67,11 +67,17 @@ func checkFlags(opts CheckOptions) error {
if dataSubset[0] == 0 || dataSubset[1] == 0 || dataSubset[0] > dataSubset[1] {
return errors.Fatalf("check flag --read-data-subset=n/t values must be positive integers, and n <= t, e.g. --read-data-subset=1/2")
}
if dataSubset[1] > totalBucketsMax {
return errors.Fatalf("check flag --read-data-subset=n/t t must be at most %d", totalBucketsMax)
}
}
return nil
}
// See doReadData in runCheck below for why this is 256.
const totalBucketsMax = 256
// stringToIntSlice converts string to []uint, using '/' as element separator
func stringToIntSlice(param string) (split []uint, err error) {
if param == "" {
@ -257,6 +263,8 @@ func runCheck(opts CheckOptions, gopts GlobalOptions, args []string) error {
doReadData := func(bucket, totalBuckets uint) {
packs := restic.IDSet{}
for pack := range chkr.GetPacks() {
// If we ever check more than the first byte
// of pack, update totalBucketsMax.
if (uint(pack[0]) % totalBuckets) == (bucket - 1) {
packs.Insert(pack)
}