From d612144be1ed20f708bda8f1686181c5d474f186 Mon Sep 17 00:00:00 2001 From: Seednode Date: Wed, 13 Sep 2023 22:08:01 -0500 Subject: [PATCH] Fix handling directories with only one or two files --- cmd/files.go | 8 +++++--- cmd/root.go | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index 360c8fa..3832364 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -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++ } diff --git a/cmd/root.go b/cmd/root.go index 42ea417..293ce25 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,7 +12,7 @@ import ( ) const ( - ReleaseVersion string = "0.80.0" + ReleaseVersion string = "0.80.1" ) var (