on main help sign in
fix(fsext): panic on fastwalk (#1122)
b22fd08Carlos Alexandro Becker
internal/fsext/ls.go+6−5
@@ -4,6 +4,7 @@ import (
4 "log/slog"
4 "log/slog"
5 "os"
5 "os"
6 "path/filepath"
6 "path/filepath"
7+ "slices"
7 "strings"
8 "strings"
8 "sync"
9 "sync"
9
10
@@ -200,7 +201,7 @@ func (dl *directoryLister) getIgnore(path string) ignore.IgnoreParser {
200
201
201// ListDirectory lists files and directories in the specified path,
202// ListDirectory lists files and directories in the specified path,
202func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) {
203func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) {
203− var results []string
204+ results := csync.NewSlice[string]()
204 truncated := false
205 truncated := false
205 dl := NewDirectoryLister(initialPath)
206 dl := NewDirectoryLister(initialPath)
206
207
@@ -227,19 +228,19 @@ func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]st
227 if d.IsDir() {
228 if d.IsDir() {
228 path = path + string(filepath.Separator)
229 path = path + string(filepath.Separator)
229 }
230 }
230− results = append(results, path)
231+ results.Append(path)
231 }
232 }
232
233
233− if limit > 0 && len(results) >= limit {
234+ if limit > 0 && results.Len() >= limit {
234 truncated = true
235 truncated = true
235 return filepath.SkipAll
236 return filepath.SkipAll
236 }
237 }
237
238
238 return nil
239 return nil
239 })
240 })
240− if err != nil && len(results) == 0 {
241+ if err != nil && results.Len() == 0 {
241 return nil, truncated, err
242 return nil, truncated, err
242 }
243 }
243
244
244− return results, truncated, nil
245+ return slices.Collect(results.Seq()), truncated, nil
245}
246}