Added check for empty input paths

This commit is contained in:
Seednode 2023-04-11 04:44:18 -05:00
parent 290395d0eb
commit 15e2cc52cc
3 changed files with 65 additions and 7 deletions

View File

@ -398,6 +398,43 @@ func isImage(path string) (bool, error) {
return filetype.IsImage(head), nil
}
func pathHasSupportedFiles(path string) (bool, error) {
hasSupportedFiles := make(chan bool, 1)
err := filepath.WalkDir(path, func(p string, info os.DirEntry, err error) error {
if err != nil {
return err
}
switch {
case !recursive && info.IsDir() && p != path:
return filepath.SkipDir
case !info.IsDir():
image, err := isImage(p)
if err != nil {
return err
}
if image {
hasSupportedFiles <- true
return filepath.SkipAll
}
}
return err
})
if err != nil {
return false, err
}
select {
case <-hasSupportedFiles:
return true, nil
default:
return false, nil
}
}
func scanPath(path string, files *Files, filters *Filters, stats *ScanStats, concurrency *Concurrency) error {
var wg sync.WaitGroup
@ -586,7 +623,7 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin
}
func normalizePaths(args []string) ([]string, error) {
paths := make([]string, len(args))
paths := []string{}
fmt.Println("Paths:")
@ -601,13 +638,29 @@ func normalizePaths(args []string) ([]string, error) {
return nil, err
}
if (args[i]) != absolutePath {
fmt.Printf("%s (resolved to %s)\n", args[i], absolutePath)
} else {
fmt.Printf("%s\n", args[i])
hasSupportedFiles, err := pathHasSupportedFiles(absolutePath)
if err != nil {
return nil, err
}
paths[i] = absolutePath
var addPath bool = false
switch {
case args[i] == absolutePath && hasSupportedFiles:
fmt.Printf("%s\n", args[i])
addPath = true
case args[i] != absolutePath && hasSupportedFiles:
fmt.Printf("%s (resolved to %s)\n", args[i], absolutePath)
addPath = true
case args[i] == absolutePath && !hasSupportedFiles:
fmt.Printf("%s [No supported files found]\n", args[i])
case args[i] != absolutePath && !hasSupportedFiles:
fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], absolutePath)
}
if addPath {
paths = append(paths, absolutePath)
}
}
fmt.Println()

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)
var Version = "0.38.2"
var Version = "0.39.0"
func init() {
rootCmd.AddCommand(versionCmd)

View File

@ -770,6 +770,11 @@ func ServePage(args []string) error {
return err
}
if len(paths) == 0 {
fmt.Println("No supported files found in provided paths. Exiting.")
os.Exit(0)
}
Regexes := &Regexes{
filename: regexp.MustCompile(`(.+)([0-9]{3})(\..+)`),
alphanumeric: regexp.MustCompile(`^[a-zA-Z0-9]*$`),