Skip to content

Commit

Permalink
windows use / in glob matcher?
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed May 19, 2024
1 parent c728147 commit 626bc10
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,7 @@ public static List<Path> walkPathWithPattern(Path basePath, String pattern,
} else if (Files.isDirectory(basePath)) {
try (var walk = Files.walk(basePath, FileVisitOption.FOLLOW_LINKS)) {
return walk
.filter(path -> {
System.err.println(
" " + basePath + " " + pattern + " " + basePath.relativize(path) + " " +
matcher.matches(basePath.relativize(path)));
return matcher.matches(path.getFileName()) || matcher.matches(basePath.relativize(path));
})
.filter(path -> matcher.matches(path.getFileName()) || matcher.matches(basePath.relativize(path)))
.flatMap(path -> {
if (FileUtils.hasExtension(path, "zip")) {
return walkZipFile.apply(path).stream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static Glob of(Path path) {

/** Resolves a subdirectory using parts separated by the platform file separator. */
public Glob resolve(String... subPath) {
String separator = base.getFileSystem().getSeparator();
String separator = "/";
if (pattern != null) {
return new Glob(base, pattern + separator + String.join(separator, subPath));
} else if (subPath == null || subPath.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,7 @@ void testWalkPathWithPattern() throws IOException {
var path = tmpDir.resolve("a").resolve("b").resolve("c.txt");
FileUtils.createParentDirectories(path);
Files.writeString(path, "test");
var sep = path.getFileSystem().getSeparator();
System.err.println("============");
System.err.println(
path.getFileSystem().getPathMatcher("glob:*" + sep + "*" + sep + "c.txt").matches(Path.of("a", "b", "c.txt")));
System.err.println(path.getFileSystem().getPathMatcher("glob:." + sep + "*" + sep + "*" + sep + "c.txt")
.matches(Path.of("a", "b", "c.txt")));
System.err.println(path.getFileSystem().getPathMatcher("glob:*/*/c.txt").matches(Path.of("a", "b", "c.txt")));
assertEquals(List.of(path), Glob.of(tmpDir).resolve("a", "*", "c.txt").find());
System.err.println(Glob.of(tmpDir).resolve("*", "*", "c.txt"));
System.err.println(Glob.of(tmpDir).resolve("*", "*", "c.txt").find()); // nope
System.err.println(Glob.of(tmpDir).resolve("**", "c.txt").find()); // ok
System.err.println(Glob.of(tmpDir).resolve("*", "b", "c.txt").find()); // nada
assertEquals(List.of(path), Glob.of(tmpDir).resolve("*", "*", "c.txt").find());
assertEquals(List.of(path), Glob.of(tmpDir).resolve("a", "b", "c.txt").find());
}
Expand Down

0 comments on commit 626bc10

Please sign in to comment.