Skip to content

Commit

Permalink
HADOOP-19196. Allow base path to be deleted as well using Bulk Delete. (
Browse files Browse the repository at this point in the history
apache#6872)


Contributed by: Mukund Thakur
  • Loading branch information
mukund-thakur authored Jun 11, 2024
1 parent 005030f commit 06dd3bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public static void validateBulkDeletePaths(Collection<Path> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -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.
*/
Expand Down

0 comments on commit 06dd3bf

Please sign in to comment.