summaryrefslogtreecommitdiff
path: root/src/reader.go
diff options
context:
space:
mode:
authorCharlie Vieth <charlie.vieth@gmail.com>2024-07-08 09:21:37 -0400
committerGitHub <noreply@github.com>2024-07-08 22:21:37 +0900
commit2dbc874e3dfa381b2e5492c94bf4056d4a36f3f1 (patch)
tree9c631f59dbe4c4cb7a8752999a2a6f7b50291e6e /src/reader.go
parent039a2f1d04417d6aae0a3197227f1cba15bcb22b (diff)
downloadfzf-2dbc874e3dfa381b2e5492c94bf4056d4a36f3f1.tar.gz
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 <junegunn.c@gmail.com>
Diffstat (limited to 'src/reader.go')
-rw-r--r--src/reader.go22
1 files changed, 20 insertions, 2 deletions
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) {