diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java index d991642942..23f6e63157 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/BulkDeleteUtils.java @@ -48,14 +48,14 @@ public static void validateBulkDeletePaths(Collection paths, int pageSize, } /** - * Check if a path is under a base path. + * Check if a given path is the base path or under the base path. * @param p path to check. * @param basePath base path. - * @return true if the path is under the base path. + * @return true if the given path is the base path or under the base path. */ public static boolean validatePathIsUnderParent(Path p, Path basePath) { - while (p.getParent() != null) { - if (p.getParent().equals(basePath)) { + while (p != null) { + if (p.equals(basePath)) { return true; } p = p.getParent(); diff --git a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md index de0e4e893b..14048da43a 100644 --- a/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md +++ b/hadoop-common-project/hadoop-common/src/site/markdown/filesystem/bulkdelete.md @@ -23,6 +23,7 @@ in an object store or filesystem. * An API for submitting a list of paths to delete. * This list must be no larger than the "page size" supported by the client; This size is also exposed as a method. +* This list must not have any path outside the base path. * Triggers a request to delete files at the specific paths. * Returns a list of which paths were reported as delete failures by the store. * Does not consider a nonexistent file to be a failure. diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java index 1413e74a7e..daeb9d4808 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/contract/AbstractContractBulkDeleteTest.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -167,6 +168,17 @@ public void testDeletePathsNotUnderBase() throws Exception { () -> bulkDelete_delete(getFileSystem(), basePath, paths)); } + /** + * We should be able to delete the base path itself + * using bulk delete operation. + */ + @Test + public void testDeletePathSameAsBasePath() throws Exception { + assertSuccessfulBulkDelete(bulkDelete_delete(getFileSystem(), + basePath, + Arrays.asList(basePath))); + } + /** * This test should fail as path is not absolute. */