Skip to content

Commit

Permalink
Fix recursive ufs listing
Browse files Browse the repository at this point in the history
Fixes: #11339

pr-link: #11340
change-id: cid-ca29c3f3cf783e6434afebdc00681662317a5cbe
  • Loading branch information
madanadit committed Apr 24, 2020
1 parent 77b72b8 commit 28319c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public UfsStatus[] listStatus(String path, ListOptions options) throws IOExcepti
final Pair<String, UfsStatus> pathToProcessPair = pathsToProcess.remove();
final String pathToProcess = pathToProcessPair.getFirst();
UfsStatus pathStatus = pathToProcessPair.getSecond();
returnPaths.add(pathStatus.setName(pathToProcess.substring(path.length() + 1)));
int beginIndex = path.endsWith(AlluxioURI.SEPARATOR) ? path.length() : path.length() + 1;
returnPaths.add(pathStatus.setName(pathToProcess.substring(beginIndex)));

if (pathStatus.isDirectory()) {
// Add all of its subpaths
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -751,11 +751,20 @@ public void listStatusRecursiveTest() throws IOException {
}
// lsr from sub1 should return paths relative to sub1
String[] expectedResSub1 = {"sub11", "sub11/file11"};
String[] actualResSub1 =
UfsStatus.convertToNames(mUfs.listStatus(sub1, ListOptions.defaults().setRecursive(true)));
Arrays.sort(expectedResSub1);
Arrays.sort(actualResSub1);
if (!Arrays.equals(expectedResSub1, actualResSub1)
// Case A: the path sub1 does not end with a trailing /
String[] actualResSub1a =
UfsStatus.convertToNames(mUfs.listStatus(sub1, ListOptions.defaults().setRecursive(true)));
Arrays.sort(actualResSub1a);
if (!Arrays.equals(expectedResSub1, actualResSub1a)
|| (mUfs.listStatus(file, ListOptions.defaults().setRecursive(true)) != null)) {
throw new IOException(LIST_STATUS_RESULT_INCORRECT);
}
// Case B: the path sub1 ends with a trailing /
String[] actualResSub1b = UfsStatus.convertToNames(
mUfs.listStatus(sub1 + "/", ListOptions.defaults().setRecursive(true)));
Arrays.sort(actualResSub1b);
if (!Arrays.equals(expectedResSub1, actualResSub1b)
|| (mUfs.listStatus(file, ListOptions.defaults().setRecursive(true)) != null)) {
throw new IOException(LIST_STATUS_RESULT_INCORRECT);
}
Expand Down

0 comments on commit 28319c0

Please sign in to comment.