Fix handling directories with only one or two files

This commit is contained in:
Seednode 2023-09-13 22:08:01 -05:00
parent bfb04cab66
commit d612144be1
2 changed files with 6 additions and 4 deletions

View File

@ -527,11 +527,12 @@ func pickFile(args []string, filters *filters, sort string, cache *fileCache, fo
fileList, fromCache := fileList(args, filters, sort, cache, formats)
fileCount := len(fileList)
if fileCount < 1 {
return "", ErrNoMediaFound
}
r, err := rand.Int(rand.Reader, big.NewInt(int64(fileCount-2)))
r, err := rand.Int(rand.Reader, big.NewInt(int64(fileCount)))
if err != nil {
return "", err
}
@ -542,9 +543,10 @@ func pickFile(args []string, filters *filters, sort string, cache *fileCache, fo
}
for i := 0; i < fileCount; i++ {
if val >= fileCount {
switch {
case val >= fileCount:
val = 0
} else {
case val < fileCount-1:
val++
}

View File

@ -12,7 +12,7 @@ import (
)
const (
ReleaseVersion string = "0.80.0"
ReleaseVersion string = "0.80.1"
)
var (