mirror of
https://github.com/restic/restic.git
synced 2024-12-24 16:54:00 +00:00
Merge pull request #3309 from MichaelEischer/fix-random-check-crash
check: Fix crash of --read-data-subset=x% on empty repository
This commit is contained in:
commit
6712c6de73
3 changed files with 15 additions and 1 deletions
7
changelog/unreleased/issue-3296
Normal file
7
changelog/unreleased/issue-3296
Normal file
|
@ -0,0 +1,7 @@
|
|||
Bugfix: Fix crash of `check --read-data-subset=x%` run for an empty repository
|
||||
|
||||
`check --read-data-subset=x%` crashed when run for an empty repository. This
|
||||
has been fixed.
|
||||
|
||||
https://github.com/restic/restic/issues/3296
|
||||
https://github.com/restic/restic/pull/3309
|
|
@ -331,7 +331,7 @@ func selectPacksByBucket(allPacks map[restic.ID]int64, bucket, totalBuckets uint
|
|||
func selectRandomPacksByPercentage(allPacks map[restic.ID]int64, percentage float64) map[restic.ID]int64 {
|
||||
packCount := len(allPacks)
|
||||
packsToCheck := int(float64(packCount) * (percentage / 100.0))
|
||||
if packsToCheck < 1 {
|
||||
if packCount > 0 && packsToCheck < 1 {
|
||||
packsToCheck = 1
|
||||
}
|
||||
timeNs := time.Now().UnixNano()
|
||||
|
|
|
@ -122,3 +122,10 @@ func TestSelectRandomPacksByPercentage(t *testing.T) {
|
|||
rtest.Assert(t, ok, "Expected input and output to be equal")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectNoRandomPacksByPercentage(t *testing.T) {
|
||||
// that the a repository without pack files works
|
||||
var testPacks = make(map[restic.ID]int64)
|
||||
selectedPacks := selectRandomPacksByPercentage(testPacks, 10.0)
|
||||
rtest.Assert(t, len(selectedPacks) == 0, "Expected 0 selected packs")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue