Skip to content

Commit

Permalink
[Truffle] Handle directory globbing without any '*' in the pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvdrum committed Jan 28, 2015
1 parent 331bae6 commit 9ccac8b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/DirNodes.java
Expand Up @@ -133,6 +133,7 @@ private static RubyArray glob(final RubyContext context, String glob) {
* satisfies MSpec, but it will likely break for anyone else.
*/

final RubyArray array = new RubyArray(context.getCoreLibrary().getArrayClass());
String absoluteGlob;

if (!glob.startsWith("/") && !org.jruby.RubyFile.startsWithDriveLetterOnWindows(glob)) {
Expand All @@ -143,13 +144,18 @@ private static RubyArray glob(final RubyContext context, String glob) {

// Get the first star
final int firstStar = absoluteGlob.indexOf('*');
assert firstStar >= 0;

// If there's no star, there's nothing to glob. Return an empty result set.
if (firstStar == -1) {
return array;
}

// Walk back from that to the first / before that star

int prefixLength = firstStar;

while (prefixLength > 0 && absoluteGlob.charAt(prefixLength) == File.separatorChar) {
System.out.println(String.format("char: %s; separator: %s", absoluteGlob.charAt(prefixLength), File.separatorChar));
prefixLength--;
}

Expand All @@ -158,8 +164,6 @@ private static RubyArray glob(final RubyContext context, String glob) {
// Glob patterns must always use '/', even on Windows.
final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + absoluteGlob.substring(prefixLength).replace('\\', '/'));

final RubyArray array = new RubyArray(context.getCoreLibrary().getArrayClass());

try {
Files.walkFileTree(FileSystems.getDefault().getPath(prefix), new SimpleFileVisitor<Path>() {

Expand Down

0 comments on commit 9ccac8b

Please sign in to comment.