fix(fsext): panic on fastwalk (#1122)
Carlos Alexandro Becker
created 1 month ago
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>
Change summary
internal/fsext/ls.go | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
Detailed changes
@@ -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
}