From 297c561fab51fd0ed2ab1405fa99b1dd8a054d7b Mon Sep 17 00:00:00 2001 From: Seednode Date: Fri, 28 Oct 2022 23:07:25 -0500 Subject: [PATCH] pickFile now iterates through entire file list, instead of stopping after an arbitrary number --- cmd/files.go | 14 +++++++++++--- cmd/root.go | 3 --- cmd/version.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/cmd/files.go b/cmd/files.go index d8e10bf..8f241fa 100644 --- a/cmd/files.go +++ b/cmd/files.go @@ -495,10 +495,18 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string) } } - for i := 0; i < maxRetries; i++ { - i := rand.Intn(len(fileList)) + fileCount := len(fileList) - 1 - filePath := fileList[i] + r := rand.Intn(fileCount) + + for i := 0; i < fileCount; i++ { + if r > fileCount { + r = 0 + } else { + r++ + } + + filePath := fileList[r] if !Cache { isImage, err := isImage(filePath) diff --git a/cmd/root.go b/cmd/root.go index 004a215..f493a38 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,9 +17,6 @@ const ( // avoid hitting default open file descriptor limits (1024) maxDirectoryScans MaxConcurrency = 32 maxFileScans MaxConcurrency = 256 - - // number of times pickFile() will check for a valid file - maxRetries int = 10 ) type Concurrency struct { diff --git a/cmd/version.go b/cmd/version.go index 6b67020..1207176 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -var Version = "0.20.6" +var Version = "0.20.7" func init() { rootCmd.AddCommand(versionCmd)