feat(shell): make hasfiles support case insensitive filenames in pattern

This commit is contained in:
Warren Buckley 2023-10-02 09:00:36 +00:00 committed by Jan De Dobbeleer
parent d6a3345b99
commit 64da68a3b8

View file

@ -425,22 +425,36 @@ func (env *Shell) Pwd() string {
func (env *Shell) HasFiles(pattern string) bool { func (env *Shell) HasFiles(pattern string) bool {
defer env.Trace(time.Now(), pattern) defer env.Trace(time.Now(), pattern)
cwd := env.Pwd() cwd := env.Pwd()
fileSystem := os.DirFS(cwd) fileSystem := os.DirFS(cwd)
matches, err := fs.Glob(fileSystem, pattern)
matches, err := fs.ReadDir(fileSystem, ".")
if err != nil { if err != nil {
env.Error(err) env.Error(err)
env.Debug("false") env.Debug("false")
return false return false
} }
pattern = strings.ToLower(pattern)
for _, match := range matches { for _, match := range matches {
file, err := fs.Stat(fileSystem, match) if match.IsDir() {
if err != nil || file.IsDir() {
continue continue
} }
env.Debug("true")
return true matchFileName, err := filepath.Match(pattern, strings.ToLower(match.Name()))
if err != nil {
env.Error(err)
env.Debug("false")
return false
}
if matchFileName {
env.Debug("true")
return true
}
} }
env.Debug("false") env.Debug("false")
return false return false
} }