@Override public void delete(AlluxioURI path, DeletePOptions options) throws DirectoryNotEmptyException, FileDoesNotExistException, IOException, AlluxioException { checkUri(path); FileSystemMasterClient masterClient = mFsContext.acquireMasterClient(); try { masterClient.delete(path, options); LOG.debug("Deleted {}, options: {}", path.getPath(), options); } catch (FailedPreconditionException e) { // A little sketchy, but this should be the only case that throws FailedPrecondition. throw new DirectoryNotEmptyException(e.getMessage()); } catch (NotFoundException e) { throw new FileDoesNotExistException(e.getMessage()); } catch (UnavailableException e) { throw e; } catch (AlluxioStatusException e) { throw e.toAlluxioException(); } finally { mFsContext.releaseMasterClient(masterClient); } }
/** * Tests the {@link FileSystemMaster#delete(AlluxioURI, DeleteContext)} method with a * non-empty directory. */ @Test public void deleteNonemptyDirectory() throws Exception { createFileWithSingleBlock(NESTED_FILE_URI); String dirName = mFileSystemMaster.getFileInfo(NESTED_URI, GET_STATUS_CONTEXT).getName(); try { mFileSystemMaster.delete(NESTED_URI, DeleteContext.defaults()); fail("Deleting a non-empty directory without setting recursive should fail"); } catch (DirectoryNotEmptyException e) { String expectedMessage = ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE.getMessage(dirName); assertEquals(expectedMessage, e.getMessage()); } // Now delete with recursive set to true. mFileSystemMaster.delete(NESTED_URI, DeleteContext.defaults(DeletePOptions.newBuilder().setRecursive(true))); }
throw new DirectoryNotEmptyException(ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE, inode.getName());
throw new DirectoryNotEmptyException(ExceptionMessage.DELETE_NONEMPTY_DIRECTORY_NONRECURSIVE, inode.getName());