@ 260812.1

241025.1 · aa71a4ca319d67550c8db59f9158165af96c3a28

fastwalk: don't clean the path argument to Walk on Windows

On Windows don't attempt to clean the path argument to Walk since the existing clean logic (cleanRootPath) transforms paths like "C:\" => "C:" which are not equivalent.

This logic only existed to make the joining of paths simpler and should probably be removed since we shouldn't be modifying user provided paths.

TODO: Investigate if anything relies on the current clean logic and remove it if nothing does.

Fixes: https://github.com/charlievieth/fastwalk/issues/37

reading declarations

Changes to dirent_export_test.go. All files

dirent_export_test.go

@@ -4,6 +4,7 @@ import ( 	"fmt" 	"io/fs" 	"os"+	"runtime" 	"testing" 	"time" )@@ -29,26 +30,44 @@ func FormatFileInfo(fi fs.FileInfo) string { 	}) } +// NB: this test lives here and not in fastwalk_test.go since we need to+// access the internal cleanRootPath function. func TestCleanRootPath(t *testing.T) {-	tests := map[string]string{-		"":      "",-		"/":     "/",-		"//":    "/",-		"/foo":  "/foo",-		"/foo/": "/foo",-		"a":     "a",-		`C:/`:   `C:`,-	}-	if os.PathSeparator != '/' {-		const sep = string(os.PathSeparator)-		tests["C:"+sep] = `C:`-		tests["C:"+sep+sep] = `C:`-		tests[sep+sep] = sep-	}-	for in, want := range tests {-		got := cleanRootPath(in)-		if got != want {-			t.Errorf("cleanRootPath(%q) = %q; want: %q", in, got, want)+	test := func(t *testing.T, tests map[string]string) {+		t.Helper()+		for in, want := range tests {+			got := cleanRootPath(in)+			if got != want {+				t.Errorf("cleanRootPath(%q) = %q; want: %q", in, got, want)+			} 		} 	}+	// NB: The name here isn't exactly correct since we run this for+	// any non-Windows OS.+	t.Run("Unix", func(t *testing.T) {+		if runtime.GOOS == "windows" {+			t.Skip("test not supported on Windows")+		}+		test(t, map[string]string{+			"":      "",+			".":     ".",+			"/":     "/",+			"//":    "/",+			"/foo":  "/foo",+			"/foo/": "/foo",+			"a":     "a",+		})+	})+	// Test that cleanRootPath is a no-op on Windows+	t.Run("Windows", func(t *testing.T) {+		if runtime.GOOS != "windows" {+			t.Skip("test only supported on Windows")+		}+		test(t, map[string]string{+			`C:/`:              `C:/`,+			`C://`:             `C://`,+			`\\?\GLOBALROOT`:   `\\?\GLOBALROOT`,+			`\\?\GLOBALROOT\\`: `\\?\GLOBALROOT\\`,+		})+	}) }