/** * A wrapper around {@link FileContext#rename(Path, Path, Options.Rename...)}}. */ public static void renamePath(FileContext fc, Path oldName, Path newName, boolean overwrite) throws IOException { Options.Rename renameOptions = (overwrite) ? Options.Rename.OVERWRITE : Options.Rename.NONE; fc.rename(oldName, newName, renameOptions); }
@Override public void commit() throws IOException { checkIsNotTmp(); // FileContext supports atomic rename, whereas FileSystem doesn't FileContext fc = FileContext.getFileContext(_hadoopConf); Path dest = new Path(_path.getParent(), BLOBSTORE_DATA_FILE); if (_mustBeNew) { fc.rename(_path, dest); } else { fc.rename(_path, dest, Options.Rename.OVERWRITE); } // Note, we could add support for setting the replication factor }
this.fileContext.rename(stagingFilePath, outputFilePath, renameOptions); } catch (IOException ioe) { log.error("Could not commit file %s.", outputFilePath);
/** * A wrapper around {@link FileContext#rename(Path, Path, Options.Rename...)}}. */ public static void renamePath(FileContext fc, Path oldName, Path newName, boolean overwrite) throws IOException { Options.Rename renameOptions = (overwrite) ? Options.Rename.OVERWRITE : Options.Rename.NONE; fc.rename(oldName, newName, renameOptions); }
private void moveToDoneNow(final Path src, final Path target) throws IOException { LOG.info("Moving " + src.toString() + " to " + target.toString()); intermediateDoneDirFc.rename(src, target, Options.Rename.NONE); }
private void moveToDoneNow(final Path src, final Path target) throws IOException { LOG.info("Moving " + src.toString() + " to " + target.toString()); intermediateDoneDirFc.rename(src, target, Options.Rename.NONE); }
@Nullable @Override public Location renameTo(Location destination) throws IOException { Path targetPath = new Path(destination.toURI()); try { fc.rename(path, targetPath, Options.Rename.OVERWRITE); return new FileContextLocation(locationFactory, fc, targetPath); } catch (FileAlreadyExistsException | FileNotFoundException | ParentNotDirectoryException e) { return null; } }
@Override public void rename(long bucketKey, String fromName, String toName) throws IOException { FileContext fc = FileContext.getFileContext(fs.getUri()); Path bucketPath = getBucketPath(bucketKey); // file context requires absolute path if (!bucketPath.isAbsolute()) { bucketPath = new Path(fs.getWorkingDirectory(), bucketPath); } fc.rename(new Path(bucketPath, fromName), new Path(bucketPath, toName), Rename.OVERWRITE); }
@Test(expected=AccessControlException.class) public void testInternalRename1() throws IOException { fcView.rename(new Path("/internalDir"), new Path("/newDir")); } @Test(expected=AccessControlException.class)
@Test(expected=AccessControlException.class) public void testInternalRename1() throws IOException { fcView.rename(new Path("/internalDir"), new Path("/newDir")); } @Test(expected=AccessControlException.class)
@Override public Object run() throws IOException { FileContext myfc = FileContext.getFileContext(conf); Path newlink = new Path(targetParent, "newlink"); myfc.rename(link, newlink, Rename.NONE); return null; } });
@Test(expected=AccessControlException.class) public void testInternalRename3() throws IOException { fcView.rename(new Path("/user"), new Path("/internalDir/linkToDir2")); } @Test(expected=AccessControlException.class)
@Test(expected=AccessControlException.class) public void testInternalRename3() throws IOException { fcView.rename(new Path("/user"), new Path("/internalDir/linkToDir2")); } @Test(expected=AccessControlException.class)
@Test(expected=IOException.class) public void testRenameAcrossMounts2() throws IOException { fileContextTestHelper.createFile(fcView, "/user/foo"); fcView.rename(new Path("/user/foo"), new Path("/data/fooBar")); }
/** * We would have liked renames across file system to fail but * Unfortunately there is not way to distinguish the two file systems * @throws IOException */ @Test public void testRenameAcrossFs() throws IOException { fc.mkdir(new Path("/newDir/dirFoo"), FileContext.DEFAULT_PERM, true); // the root will get interpreted to the root of the chrooted fs. fc.rename(new Path("/newDir/dirFoo"), new Path("file:///dirFooBar")); FileContextTestHelper.isDir(fc, new Path("/dirFooBar")); }
@Test(expected=AccessControlException.class) public void testInternalRename2() throws IOException { Assert.assertTrue("linkTODir2 should be a dir", fcView.getFileStatus(new Path("/internalDir/linkToDir2")).isDirectory()); fcView.rename(new Path("/internalDir/linkToDir2"), new Path("/internalDir/dir1")); } @Test(expected=AccessControlException.class)
private void rename(Path src, Path dst, boolean renameShouldSucceed, boolean srcExists, boolean dstExists, Rename... options) throws IOException { fc.rename(src, dst, options); if (!renameShouldSucceed) Assert.fail("rename should have thrown exception"); Assert.assertEquals("Source exists", srcExists, exists(fc, src)); Assert.assertEquals("Destination exists", dstExists, exists(fc, dst)); } private boolean containsPath(Path path, FileStatus[] filteredPaths)
private void rename(Path src, Path dst, boolean dstExists, boolean renameSucceeds, boolean exception, Options.Rename... options) throws Exception { try { fc.rename(src, dst, options); Assert.assertTrue(renameSucceeds); } catch (Exception ex) { Assert.assertTrue(exception); } Assert.assertEquals(renameSucceeds, !exists(fc, src)); Assert.assertEquals((dstExists||renameSucceeds), exists(fc, dst)); } }
private void rename(Path src, Path dst, boolean renameShouldSucceed, boolean srcExists, boolean dstExists, Rename... options) throws IOException { fc.rename(src, dst, options); if (!renameShouldSucceed) Assert.fail("rename should have thrown exception"); Assert.assertEquals("Source exists", srcExists, exists(fc, src)); Assert.assertEquals("Destination exists", dstExists, exists(fc, dst)); }
private void rename(Path src, Path dst, boolean dstExists, boolean renameSucceeds, boolean exception, Options.Rename... options) throws Exception { try { fc.rename(src, dst, options); Assert.assertTrue(renameSucceeds); } catch (Exception ex) { Assert.assertTrue(exception); } Assert.assertEquals(renameSucceeds, !exists(fc, src)); Assert.assertEquals((dstExists||renameSucceeds), exists(fc, dst)); }