on main help sign in
fix(fsext): panic on fastwalk (#1122)

this seems to fix a panic I've been getting some times. bubbletea eats part of the trace, so I'm not sure it's a race, but judging by the code, and the fact that fastwalk creates multiple goroutines, it makes sense. i've been using this for the past few hours and haven't encountered the error since. Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

commitb22fd0884367fbd59286c9bd158c4fc615f20f66 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateWed 24 Sep 2025, 17:12 (1 year ago) parent09d8e75
1 file changed+6−5
internal/fsext/ls.go+6−5
internal/fsext/ls.go+6−5
@@ -4,6 +4,7 @@ import (
44 "log/slog"
55 "os"
66 "path/filepath"
7+ "slices"
78 "strings"
89 "sync"
910
@@ -200,7 +201,7 @@ func (dl *directoryLister) getIgnore(path string) ignore.IgnoreParser {
200201
201202// ListDirectory lists files and directories in the specified path,
202203func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) {
203− var results []string
204+ results := csync.NewSlice[string]()
204205 truncated := false
205206 dl := NewDirectoryLister(initialPath)
206207
@@ -227,19 +228,19 @@ func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]st
227228 if d.IsDir() {
228229 path = path + string(filepath.Separator)
229230 }
230− results = append(results, path)
231+ results.Append(path)
231232 }
232233
233− if limit > 0 && len(results) >= limit {
234+ if limit > 0 && results.Len() >= limit {
234235 truncated = true
235236 return filepath.SkipAll
236237 }
237238
238239 return nil
239240 })
240− if err != nil && len(results) == 0 {
241+ if err != nil && results.Len() == 0 {
241242 return nil, truncated, err
242243 }
243244
244− return results, truncated, nil
245+ return slices.Collect(results.Seq()), truncated, nil
245246}