org.apache.hadoop.fs.PathIsNotEmptyDirectoryException Java Examples
The following examples show how to use
org.apache.hadoop.fs.PathIsNotEmptyDirectoryException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CleanerChore.java From hbase with Apache License 2.0 | 6 votes |
/** * Perform a delete on a specified type. * @param deletion a delete * @param type possible values are 'files', 'subdirs', 'dirs' * @return true if it deleted successfully, false otherwise */ private boolean deleteAction(Action<Boolean> deletion, String type, Path dir) { boolean deleted; try { LOG.trace("Start deleting {} under {}", type, dir); deleted = deletion.act(); } catch (PathIsNotEmptyDirectoryException exception) { // N.B. HDFS throws this exception when we try to delete a non-empty directory, but // LocalFileSystem throws a bare IOException. So some test code will get the verbose // message below. LOG.debug("Couldn't delete '{}' yet because it isn't empty w/exception.", dir, exception); deleted = false; } catch (IOException ioe) { LOG.info("Could not delete {} under {}. might be transient; we'll retry. if it keeps " + "happening, use following exception when asking on mailing list.", type, dir, ioe); deleted = false; } catch (Exception e) { LOG.info("unexpected exception: ", e); deleted = false; } LOG.trace("Finish deleting {} under {}, deleted=", type, dir, deleted); return deleted; }
Example #2
Source File: HadoopIgfs20FileSystemAbstractSelfTest.java From ignite with Apache License 2.0 | 6 votes |
/** @throws Exception If failed. */ @Test public void testDeleteFailsIfNonRecursive() throws Exception { Path fsHome = new Path(primaryFsUri); Path someDir3 = new Path(fsHome, "/someDir1/someDir2/someDir3"); FSDataOutputStream os = fs.create(someDir3, EnumSet.noneOf(CreateFlag.class), Options.CreateOpts.perms(FsPermission.getDefault())); os.close(); final Path someDir2 = new Path(fsHome, "/someDir1/someDir2"); GridTestUtils.assertThrows(log, new Callable<Object>() { @Override public Object call() throws Exception { fs.delete(someDir2, false); return null; } }, PathIsNotEmptyDirectoryException.class, null); assertPathExists(fs, someDir2); assertPathExists(fs, someDir3); }
Example #3
Source File: TestRegistryRMOperations.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testChildDeletion() throws Throwable { ServiceRecord app = createRecord("app1", PersistencePolicies.APPLICATION, "app", null); ServiceRecord container = createRecord("container1", PersistencePolicies.CONTAINER, "container", null); operations.bind("/app", app, BindFlags.OVERWRITE); operations.bind("/app/container", container, BindFlags.OVERWRITE); try { int p = purge("/", "app1", PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.FailOnChildren); fail("expected a failure, got a purge count of " + p); } catch (PathIsNotEmptyDirectoryException expected) { // expected } }
Example #4
Source File: FSDirDeleteOp.java From big-c with Apache License 2.0 | 6 votes |
/** * Remove a file/directory from the namespace. * <p> * For large directories, deletion is incremental. The blocks under * the directory are collected and deleted a small number at a time holding * the {@link FSNamesystem} lock. * <p> * For small directory or file the deletion is done in one shot. * */ static BlocksMapUpdateInfo delete( FSNamesystem fsn, String src, boolean recursive, boolean logRetryCache) throws IOException { FSDirectory fsd = fsn.getFSDirectory(); FSPermissionChecker pc = fsd.getPermissionChecker(); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); src = fsd.resolvePath(pc, src, pathComponents); final INodesInPath iip = fsd.getINodesInPath4Write(src, false); if (!recursive && fsd.isNonEmptyDirectory(iip)) { throw new PathIsNotEmptyDirectoryException(src + " is non empty"); } if (fsd.isPermissionEnabled()) { fsd.checkPermission(pc, iip, false, null, FsAction.WRITE, null, FsAction.ALL, true); } return deleteInternal(fsn, src, iip, logRetryCache); }
Example #5
Source File: FSDirDeleteOp.java From hadoop with Apache License 2.0 | 6 votes |
/** * Remove a file/directory from the namespace. * <p> * For large directories, deletion is incremental. The blocks under * the directory are collected and deleted a small number at a time holding * the {@link FSNamesystem} lock. * <p> * For small directory or file the deletion is done in one shot. * */ static BlocksMapUpdateInfo delete( FSNamesystem fsn, String src, boolean recursive, boolean logRetryCache) throws IOException { FSDirectory fsd = fsn.getFSDirectory(); FSPermissionChecker pc = fsd.getPermissionChecker(); byte[][] pathComponents = FSDirectory.getPathComponentsForReservedPath(src); src = fsd.resolvePath(pc, src, pathComponents); final INodesInPath iip = fsd.getINodesInPath4Write(src, false); if (!recursive && fsd.isNonEmptyDirectory(iip)) { throw new PathIsNotEmptyDirectoryException(src + " is non empty"); } if (fsd.isPermissionEnabled()) { fsd.checkPermission(pc, iip, false, null, FsAction.WRITE, null, FsAction.ALL, true); } return deleteInternal(fsn, src, iip, logRetryCache); }
Example #6
Source File: TestRegistryRMOperations.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testChildDeletion() throws Throwable { ServiceRecord app = createRecord("app1", PersistencePolicies.APPLICATION, "app", null); ServiceRecord container = createRecord("container1", PersistencePolicies.CONTAINER, "container", null); operations.bind("/app", app, BindFlags.OVERWRITE); operations.bind("/app/container", container, BindFlags.OVERWRITE); try { int p = purge("/", "app1", PersistencePolicies.APPLICATION, RegistryAdminService.PurgePolicy.FailOnChildren); fail("expected a failure, got a purge count of " + p); } catch (PathIsNotEmptyDirectoryException expected) { // expected } }
Example #7
Source File: BasicRootedOzoneFileSystem.java From hadoop-ozone with Apache License 2.0 | 5 votes |
DeleteIterator(Path f, boolean recursive) throws IOException { super(f); this.recursive = recursive; if (getStatus().isDirectory() && !this.recursive && listStatus(f).length != 0) { throw new PathIsNotEmptyDirectoryException(f.toString()); } // Initialize bucket here to reduce number of RPC calls OFSPath ofsPath = new OFSPath(f); // TODO: Refactor later. adapterImpl = (BasicRootedOzoneClientAdapterImpl) adapter; this.bucket = adapterImpl.getBucket(ofsPath, false); }
Example #8
Source File: HadoopIgfsSecondaryFileSystemDelegateImpl.java From ignite with Apache License 2.0 | 5 votes |
/** * Cast IO exception to IGFS exception. * * @param msg Error message. * @param e IO exception. * @return IGFS exception. */ public static IgfsException cast(String msg, IOException e) { if (e instanceof FileNotFoundException) return new IgfsPathNotFoundException(e); else if (e instanceof ParentNotDirectoryException) return new IgfsParentNotDirectoryException(msg, e); else if (e instanceof PathIsNotEmptyDirectoryException) return new IgfsDirectoryNotEmptyException(e); else if (e instanceof PathExistsException) return new IgfsPathAlreadyExistsException(msg, e); else return new IgfsException(msg, e); }
Example #9
Source File: Delete.java From big-c with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData item) throws IOException { if (!item.stat.isDirectory()) { throw new PathIsNotDirectoryException(item.toString()); } if (item.fs.listStatus(item.path).length == 0) { if (!item.fs.delete(item.path, false)) { throw new PathIOException(item.toString()); } } else if (!ignoreNonEmpty) { throw new PathIsNotEmptyDirectoryException(item.toString()); } }
Example #10
Source File: TestCuratorService.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testRMNonRf() throws Throwable { mkPath("/rm", CreateMode.PERSISTENT); mkPath("/rm/child", CreateMode.PERSISTENT); try { curatorService.zkDelete("/rm", false, null); fail("expected a failure"); } catch (PathIsNotEmptyDirectoryException expected) { } }
Example #11
Source File: TestRegistryOperations.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testDeleteNonEmpty() throws Throwable { putExampleServiceEntry(ENTRY_PATH, 0); try { operations.delete(PARENT_PATH, false); fail("Expected a failure"); } catch (PathIsNotEmptyDirectoryException expected) { // expected; ignore } operations.delete(PARENT_PATH, true); }
Example #12
Source File: Delete.java From hadoop with Apache License 2.0 | 5 votes |
@Override protected void processPath(PathData item) throws IOException { if (!item.stat.isDirectory()) { throw new PathIsNotDirectoryException(item.toString()); } if (item.fs.listStatus(item.path).length == 0) { if (!item.fs.delete(item.path, false)) { throw new PathIOException(item.toString()); } } else if (!ignoreNonEmpty) { throw new PathIsNotEmptyDirectoryException(item.toString()); } }
Example #13
Source File: TestCuratorService.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testRMNonRf() throws Throwable { mkPath("/rm", CreateMode.PERSISTENT); mkPath("/rm/child", CreateMode.PERSISTENT); try { curatorService.zkDelete("/rm", false, null); fail("expected a failure"); } catch (PathIsNotEmptyDirectoryException expected) { } }
Example #14
Source File: TestRegistryOperations.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testDeleteNonEmpty() throws Throwable { putExampleServiceEntry(ENTRY_PATH, 0); try { operations.delete(PARENT_PATH, false); fail("Expected a failure"); } catch (PathIsNotEmptyDirectoryException expected) { // expected; ignore } operations.delete(PARENT_PATH, true); }
Example #15
Source File: BasicOzoneFileSystem.java From hadoop-ozone with Apache License 2.0 | 5 votes |
DeleteIterator(Path f, boolean recursive) throws IOException { super(f); this.recursive = recursive; if (getStatus().isDirectory() && !this.recursive && listStatus(f).length != 0) { throw new PathIsNotEmptyDirectoryException(f.toString()); } }
Example #16
Source File: TestRootedOzoneFileSystem.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Helper function. Delete a path non-recursively and expect failure. * @param f Path to delete. * @throws IOException */ private void deleteNonRecursivelyAndFail(Path f) throws IOException { try { fs.delete(f, false); Assert.fail("Should have thrown PathIsNotEmptyDirectoryException!"); } catch (PathIsNotEmptyDirectoryException ignored) { } }
Example #17
Source File: RegistryOperations.java From big-c with Apache License 2.0 | 2 votes |
/** * Delete a path. * * If the operation returns without an error then the entry has been * deleted. * @param path path delete recursively * @param recursive recursive flag * @throws PathNotFoundException path is not in the registry. * @throws InvalidPathnameException the path is invalid. * @throws PathIsNotEmptyDirectoryException path has child entries, but * recursive is false. * @throws IOException Any other IO Exception * */ void delete(String path, boolean recursive) throws PathNotFoundException, PathIsNotEmptyDirectoryException, InvalidPathnameException, IOException;
Example #18
Source File: RegistryOperations.java From hadoop with Apache License 2.0 | 2 votes |
/** * Delete a path. * * If the operation returns without an error then the entry has been * deleted. * @param path path delete recursively * @param recursive recursive flag * @throws PathNotFoundException path is not in the registry. * @throws InvalidPathnameException the path is invalid. * @throws PathIsNotEmptyDirectoryException path has child entries, but * recursive is false. * @throws IOException Any other IO Exception * */ void delete(String path, boolean recursive) throws PathNotFoundException, PathIsNotEmptyDirectoryException, InvalidPathnameException, IOException;