From 2dbc874e3dfa381b2e5492c94bf4056d4a36f3f1 Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Mon, 8 Jul 2024 09:21:37 -0400 Subject: Update charlievieth/fastwalk to use forward-slashes on WSL and MSYS (#3907) This commit changes FZF to enforce that all paths are joined with forward-slashes when running on WSL or MSYS even when the FZF binary was compiled for Windows. Update: github.com/charlievieth/fastwalk Fixes: https://github.com/junegunn/fzf/issues/3859 --------- Co-authored-by: Junegunn Choi --- src/reader.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/reader.go b/src/reader.go index 9d4b2f46..b9368f07 100644 --- a/src/reader.go +++ b/src/reader.go @@ -233,14 +233,32 @@ func isSymlinkToDir(path string, de os.DirEntry) bool { return false } +func trimPath(path string) string { + bytes := stringBytes(path) + + for len(bytes) > 1 && bytes[0] == '.' && (bytes[1] == '/' || bytes[1] == '\\') { + bytes = bytes[2:] + } + + if len(bytes) == 0 { + return "." + } + + return byteString(bytes) +} + func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool { r.killed = false - conf := fastwalk.Config{Follow: opts.follow} + conf := fastwalk.Config{ + Follow: opts.follow, + // Use forward slashes when running a Windows binary under WSL or MSYS + ToSlash: fastwalk.DefaultToSlash(), + } fn := func(path string, de os.DirEntry, err error) error { if err != nil { return nil } - path = filepath.Clean(path) + path = trimPath(path) if path != "." { isDir := de.IsDir() if isDir || opts.follow && isSymlinkToDir(path, de) { -- cgit v1.2.3