From 0971e79a369338e9723aba47470e41051787a91a Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Fri, 15 May 2015 23:05:03 +0000 Subject: Change UnixGlob#matcher to treat "**/" and "/**" as matching zero or more directories, as is specified in various places, not one or more. -- MOS_MIGRATED_REVID=93758086 --- .../java/com/google/devtools/build/lib/vfs/UnixGlob.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java') diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java index 441571ef3d..11d88cd324 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java @@ -252,7 +252,21 @@ public final class UnixGlob { char c = pattern.charAt(i); switch(c) { case '*': + int toIncrement = 0; + if (len > i + 1 && pattern.charAt(i + 1) == '*') { + // The pattern '**' is interpreted to match 0 or more directory separators, not 1 or + // more. We skip the next * and then find a trailing/leading '/' and get rid of it. + toIncrement = 1; + if (len > i + 2 && pattern.charAt(i + 2) == '/') { + // We have '**/' -- skip the '/'. + toIncrement = 2; + } else if (len == i + 2 && i > 0 && pattern.charAt(i - 1) == '/') { + // We have '/**' -- remove the '/'. + regexp.delete(regexp.length() - 1, regexp.length()); + } + } regexp.append(".*"); + i += toIncrement; break; case '?': regexp.append('.'); -- cgit v1.2.3