HADOOP-19196. Allow base path to be deleted as well using Bulk Delete. (#6872)
Contributed by: Mukund Thakur
This commit is contained in:
parent
005030f7a0
commit
06dd3bfee8
@ -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();
|
||||
|
@ -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.
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user