diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java index 7c69167c3a125..519bf39c6f3e2 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Globber.java @@ -231,7 +231,9 @@ private FileStatus[] doGlob() throws IOException { } for (FileStatus candidate : candidates) { if (globFilter.hasPattern()) { - FileStatus[] children = listStatus(candidate.getPath()); + Path path = candidate.getPath(); + path.filter = globFilter; + FileStatus[] children = listStatus(path); if (children.length == 1) { // If we get back only one result, this could be either a listing // of a directory with one entry, or it could reflect the fact @@ -254,8 +256,8 @@ private FileStatus[] doGlob() throws IOException { if (!child.isDirectory()) continue; } // Set the child path based on the parent path. - child.setPath(new Path(candidate.getPath(), - child.getPath().getName())); + child.setPath(new Path(candidate.getPath().toString() + Path.SEPARATOR + + child.getPath().getName())); if (globFilter.accept(child.getPath())) { newCandidates.add(child); } diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java index 252b3cca79a3e..dad043f3ec747 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java @@ -63,6 +63,8 @@ public class Path implements Comparable, Serializable, ObjectInputValidation { public static final boolean WINDOWS = System.getProperty("os.name").startsWith("Windows"); + public PathFilter filter = null; + /** * Pre-compiled regular expressions to detect path formats. */ diff --git a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java index 1786e68a53a96..0f57653472b12 100644 --- a/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java +++ b/hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java @@ -1432,7 +1432,7 @@ public FileStatus[] innerListStatus(Path f) throws FileNotFoundException, Listing.FileStatusListingIterator files = listing.createFileStatusListingIterator(path, request, - ACCEPT_ALL, + (f.filter == null) ? ACCEPT_ALL : f.filter, new Listing.AcceptAllButSelfAndS3nDirs(path)); result = new ArrayList<>(files.getBatchSize()); while (files.hasNext()) {