Added deferred fd close for checkIfImage, and deferred getting filenames until after checking if file is an image
This commit is contained in:
parent
824965f2c3
commit
fbd4357afe
|
@ -19,6 +19,7 @@ func checkIfImage(path string) (bool, error) {
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
head := make([]byte, 261)
|
||||
file.Read(head)
|
||||
|
@ -102,17 +103,14 @@ func pickFile(fileList []string) (string, string, error) {
|
|||
|
||||
rand.Shuffle(len(fileList), func(i, j int) { fileList[i], fileList[j] = fileList[j], fileList[i] })
|
||||
|
||||
var filePath string
|
||||
var fileName string
|
||||
|
||||
for i := 0; i < len(fileList); i++ {
|
||||
filePath = fileList[i]
|
||||
fileName = filepath.Base(filePath)
|
||||
filePath := fileList[i]
|
||||
isImage, err := checkIfImage(filePath)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
if isImage {
|
||||
fileName := filepath.Base(filePath)
|
||||
return fileName, filePath, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.3.0"
|
||||
var Version = "0.3.1"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
Loading…
Reference in New Issue