Fixed redirect URIs with relative input paths (e.g. ../../test) and --cache enabled

This commit is contained in:
Seednode 2023-04-11 07:19:06 -05:00
parent 15e2cc52cc
commit c85cd55598
2 changed files with 31 additions and 15 deletions

View File

@ -456,7 +456,12 @@ func scanPath(path string, files *Files, filters *Filters, stats *ScanStats, con
wg.Done() wg.Done()
}() }()
err = appendPaths(p, files, filters, stats) path, err := normalizePath(p)
if err != nil {
fmt.Println(err)
}
err = appendPaths(path, files, filters, stats)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
@ -622,23 +627,34 @@ func pickFile(args []string, filters *Filters, sort string, index *Index) (strin
return "", ErrNoImagesFound return "", ErrNoImagesFound
} }
func normalizePath(path string) (string, error) {
path, err := filepath.EvalSymlinks(path)
if err != nil {
return "", err
}
absolutePath, err := filepath.Abs(path)
if err != nil {
return "", err
}
return absolutePath, nil
}
func normalizePaths(args []string) ([]string, error) { func normalizePaths(args []string) ([]string, error) {
paths := []string{} paths := []string{}
fmt.Println("Paths:") fmt.Println("Paths:")
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
path, err := filepath.EvalSymlinks(args[i]) path, err := normalizePath(args[i])
if err != nil { if err != nil {
return nil, err return nil, err
} }
absolutePath, err := filepath.Abs(path) pathMatches := (args[i] == path)
if err != nil {
return nil, err
}
hasSupportedFiles, err := pathHasSupportedFiles(absolutePath) hasSupportedFiles, err := pathHasSupportedFiles(path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -646,20 +662,20 @@ func normalizePaths(args []string) ([]string, error) {
var addPath bool = false var addPath bool = false
switch { switch {
case args[i] == absolutePath && hasSupportedFiles: case pathMatches && hasSupportedFiles:
fmt.Printf("%s\n", args[i]) fmt.Printf("%s\n", args[i])
addPath = true addPath = true
case args[i] != absolutePath && hasSupportedFiles: case !pathMatches && hasSupportedFiles:
fmt.Printf("%s (resolved to %s)\n", args[i], absolutePath) fmt.Printf("%s (resolved to %s)\n", args[i], path)
addPath = true addPath = true
case args[i] == absolutePath && !hasSupportedFiles: case pathMatches && !hasSupportedFiles:
fmt.Printf("%s [No supported files found]\n", args[i]) fmt.Printf("%s [No supported files found]\n", args[i])
case args[i] != absolutePath && !hasSupportedFiles: case !pathMatches && !hasSupportedFiles:
fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], absolutePath) fmt.Printf("%s (resolved to %s) [No supported files found]\n", args[i], path)
} }
if addPath { if addPath {
paths = append(paths, absolutePath) paths = append(paths, path)
} }
} }

View File

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