Fix validation of files when in cache/not cached mode

This commit is contained in:
Seednode 2023-09-14 19:10:55 -05:00
parent aaee51e9a4
commit 8923a4c14d
3 changed files with 24 additions and 43 deletions

View File

@ -99,23 +99,14 @@ func preparePath(path string) string {
return mediaPrefix + path return mediaPrefix + path
} }
func appendPath(directory, path string, files *files, stats *scanStats, formats *types.Types, shouldCache bool) error { func appendPath(directory, path string, files *files, stats *scanStats, formats *types.Types, shouldCache bool) {
if shouldCache { if shouldCache && !formats.Validate(path) {
format := formats.FileType(path) return
if format == nil {
return nil
}
if !format.Validate(path) {
return nil
}
} }
files.append(directory, path) files.append(directory, path)
stats.filesMatched.Add(1) stats.filesMatched.Add(1)
return nil
} }
func appendPaths(path string, files *files, filters *filters, stats *scanStats, formats *types.Types) error { func appendPaths(path string, files *files, filters *filters, stats *scanStats, formats *types.Types) error {
@ -149,10 +140,7 @@ func appendPaths(path string, files *files, filters *filters, stats *scanStats,
filename, filename,
filters.included[i], filters.included[i],
) { ) {
err := appendPath(directory, path, files, stats, formats, shouldCache) appendPath(directory, path, files, stats, formats, shouldCache)
if err != nil {
return err
}
return nil return nil
} }
@ -163,10 +151,7 @@ func appendPaths(path string, files *files, filters *filters, stats *scanStats,
return nil return nil
} }
err = appendPath(directory, path, files, stats, formats, shouldCache) appendPath(directory, path, files, stats, formats, shouldCache)
if err != nil {
return err
}
return nil return nil
} }
@ -326,18 +311,11 @@ func pathHasSupportedFiles(path string, formats *types.Types) (bool, error) {
switch { switch {
case !Recursive && info.IsDir() && p != path: case !Recursive && info.IsDir() && p != path:
return filepath.SkipDir return filepath.SkipDir
case !info.IsDir(): case !info.IsDir() && formats.Validate(p):
format := formats.FileType(p)
if format == nil {
return nil
}
if format.Validate(p) {
hasRegisteredFiles <- true hasRegisteredFiles <- true
return filepath.SkipAll return filepath.SkipAll
} }
}
return err return err
}) })
@ -553,21 +531,15 @@ func pickFile(args []string, filters *filters, sort string, cache *fileCache, fo
path := fileList[val] path := fileList[val]
if !fromCache { switch {
format := formats.FileType(path) case !fromCache && formats.Validate(path):
if format == nil {
return "", nil
}
if format.Validate(path) {
return path, nil return path, nil
} case !fromCache:
continue continue
} default:
return path, nil return path, nil
} }
}
return "", ErrNoMediaFound return "", ErrNoMediaFound
} }

View File

@ -11,7 +11,7 @@ import (
) )
const ( const (
ReleaseVersion string = "0.84.0" ReleaseVersion string = "0.84.1"
) )
var ( var (

View File

@ -49,6 +49,15 @@ func (t *Types) Register(format Type) {
t.Add(format) t.Add(format)
} }
func (t *Types) Validate(path string) bool {
format, exists := t.Extensions[filepath.Ext(path)]
if !exists {
return false
}
return format.Validate(path)
}
func (t *Types) GetExtensions() string { func (t *Types) GetExtensions() string {
var output strings.Builder var output strings.Builder