From 7bfd1cc2eb7f5455f5d995f27fc63678eeb5cca6 Mon Sep 17 00:00:00 2001 From: Mark Sagi-Kazar Date: Tue, 4 Jun 2024 20:15:07 +0200 Subject: [PATCH] fix: glob match on windows Signed-off-by: Mark Sagi-Kazar --- finder.go | 4 ++-- glob.go | 5 +++++ glob_windows.go | 8 ++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 glob.go create mode 100644 glob_windows.go diff --git a/finder.go b/finder.go index 1c1468a..ef8d547 100644 --- a/finder.go +++ b/finder.go @@ -63,7 +63,7 @@ func (f Finder) Find(fsys afero.Fs) ([]string, error) { // pool.Go(func() ([]string, error) { // // If the name contains any glob character, perform a glob match - // if strings.ContainsAny(searchName, "*?[]\\^") { + // if strings.ContainsAny(searchName, globMatch) { // return globWalkSearch(fsys, searchPath, searchName, f.Type) // } // @@ -79,7 +79,7 @@ func (f Finder) Find(fsys afero.Fs) ([]string, error) { allResults, err := iter.MapErr(searchItems, func(item *searchItem) ([]string, error) { // If the name contains any glob character, perform a glob match - if strings.ContainsAny(item.name, "*?[]\\^") { + if strings.ContainsAny(item.name, globMatch) { return globWalkSearch(fsys, item.path, item.name, f.Type) } diff --git a/glob.go b/glob.go new file mode 100644 index 0000000..00f833e --- /dev/null +++ b/glob.go @@ -0,0 +1,5 @@ +//go:build !windows + +package locafero + +const globMatch = "*?[]\\^" diff --git a/glob_windows.go b/glob_windows.go new file mode 100644 index 0000000..7aec2b2 --- /dev/null +++ b/glob_windows.go @@ -0,0 +1,8 @@ +//go:build windows + +package locafero + +// See [filepath.Match]: +// +// On Windows, escaping is disabled. Instead, '\\' is treated as path separator. +const globMatch = "*?[]^"