@@ -61,12 +61,8 @@ func (index *YamlFileIndex) Add(file string) error {
6161
6262func (index * YamlFileIndex ) Scan (path string ) {
6363 // Collect the list of yaml files within path.
64- files := []string {}
6564 file_exts := []string {".yml" , ".yaml" }
66- for _ , ext := range file_exts {
67- indexed_files , _ := indexFiles (path , ext )
68- files = append (files , indexed_files ... )
69- }
65+ files , _ := indexFiles (path , file_exts )
7066
7167 // Load each file into the index.
7268 for _ , f := range files {
@@ -133,16 +129,27 @@ func (index *YamlFileIndex) SaveAll() error {
133129 return nil
134130}
135131
136- func indexFiles (path string , extension string ) ([]string , error ) {
132+ func indexFiles (path string , extensions [] string ) ([]string , error ) {
137133 files := []string {}
138134 fileSystem := os .DirFS (path )
135+ extMap := make (map [string ]bool )
136+ for _ , ext := range extensions {
137+ extMap [ext ] = true
138+ }
139+
139140 err := fs .WalkDir (fileSystem , "." , func (s string , d fs.DirEntry , e error ) error {
140141 if e != nil {
141142 return nil
142143 }
143- slog . Debug ( fmt . Sprintf ( "IndexFiles: %s (%t, %s)" , s , d .IsDir (), filepath .Ext (s )))
144- if ! d . IsDir () && filepath .Ext (s ) == extension {
144+ if ! d .IsDir () && extMap [ filepath .Ext (s )] {
145+ slog . Debug ( fmt . Sprintf ( "IndexFiles: %s (indexed, %s)" , s , filepath .Ext (s )))
145146 files = append (files , filepath .Join (path , s ))
147+ } else {
148+ if d .IsDir () {
149+ slog .Debug (fmt .Sprintf ("IndexFiles: %s (directory)" , s ))
150+ } else {
151+ slog .Debug (fmt .Sprintf ("IndexFiles: %s (<not indexed>)" , s ))
152+ }
146153 }
147154 return nil
148155 })
0 commit comments