From b22fd0884367fbd59286c9bd158c4fc615f20f66 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 24 Sep 2025 17:12:45 -0300 Subject: [PATCH] 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 --- internal/fsext/ls.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/fsext/ls.go b/internal/fsext/ls.go index 2c46416f28a2777ddc9092883686c8a3461a9f7d..2027f734c4156572b134c012b2e3c143c364bd29 100644 --- a/internal/fsext/ls.go +++ b/internal/fsext/ls.go @@ -4,6 +4,7 @@ import ( "log/slog" "os" "path/filepath" + "slices" "strings" "sync" @@ -200,7 +201,7 @@ func (dl *directoryLister) getIgnore(path string) ignore.IgnoreParser { // ListDirectory lists files and directories in the specified path, func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]string, bool, error) { - var results []string + results := csync.NewSlice[string]() truncated := false dl := NewDirectoryLister(initialPath) @@ -227,19 +228,19 @@ func ListDirectory(initialPath string, ignorePatterns []string, limit int) ([]st if d.IsDir() { path = path + string(filepath.Separator) } - results = append(results, path) + results.Append(path) } - if limit > 0 && len(results) >= limit { + if limit > 0 && results.Len() >= limit { truncated = true return filepath.SkipAll } return nil }) - if err != nil && len(results) == 0 { + if err != nil && results.Len() == 0 { return nil, truncated, err } - return results, truncated, nil + return slices.Collect(results.Seq()), truncated, nil }