@Override public boolean rename(Path src, Path dst) throws IOException { return originalFs.rename(src, dst); }
@Override public boolean rename(Path src, Path dst) throws IOException { return unsafeFileSystem.rename(src, dst); }
@Test public void testRenameNonExistingFile() throws IOException { final FileSystem fs = FileSystem.getLocalFileSystem(); final File srcFile = new File(temporaryFolder.newFolder(), "someFile.txt"); final File destFile = new File(temporaryFolder.newFolder(), "target"); final Path srcFilePath = new Path(srcFile.toURI()); final Path destFilePath = new Path(destFile.toURI()); // this cannot succeed because the source file does not exist assertFalse(fs.rename(srcFilePath, destFilePath)); }
@Test public void testRenameToNonEmptyTargetDir() throws IOException { final FileSystem fs = FileSystem.getLocalFileSystem(); // a source folder with a file final File srcFolder = temporaryFolder.newFolder(); final File srcFile = new File(srcFolder, "someFile.txt"); assertTrue(srcFile.createNewFile()); // a non-empty destination folder final File dstFolder = temporaryFolder.newFolder(); final File dstFile = new File(dstFolder, "target"); assertTrue(dstFile.createNewFile()); // this cannot succeed because the destination folder is not empty assertFalse(fs.rename(new Path(srcFolder.toURI()), new Path(dstFolder.toURI()))); // retry after deleting the occupying target file assertTrue(dstFile.delete()); assertTrue(fs.rename(new Path(srcFolder.toURI()), new Path(dstFolder.toURI()))); assertTrue(new File(dstFolder, srcFile.getName()).exists()); }
@Test public void testRenameFileWithNoAccess() throws IOException { final FileSystem fs = FileSystem.getLocalFileSystem(); final File srcFile = temporaryFolder.newFile("someFile.txt"); final File destFile = new File(temporaryFolder.newFolder(), "target"); // we need to make the file non-modifiable so that the rename fails Assume.assumeTrue(srcFile.getParentFile().setWritable(false, false)); Assume.assumeTrue(srcFile.setWritable(false, false)); try { final Path srcFilePath = new Path(srcFile.toURI()); final Path destFilePath = new Path(destFile.toURI()); // this cannot succeed because the source folder has no permission to remove the file assertFalse(fs.rename(srcFilePath, destFilePath)); } finally { // make sure we give permission back to ensure proper cleanup //noinspection ResultOfMethodCallIgnored srcFile.getParentFile().setWritable(true, false); //noinspection ResultOfMethodCallIgnored srcFile.setWritable(true, false); } }
Path path2 = mock(Path.class); lfs.rename(path1, path2); verify(fs).rename(path1, path2);
@Override public boolean rename(Path src, Path dst) throws IOException { return unsafeFileSystem.rename(src, dst); }
@Override public boolean rename(Path src, Path dst) throws IOException { return unsafeFileSystem.rename(src, dst); }
@Override public boolean rename(Path src, Path dst) throws IOException { return originalFs.rename(src, dst); }
@Override public boolean rename(Path src, Path dst) throws IOException { return originalFs.rename(src, dst); }
fileSystem.rename(tmpMetadataFilePath, metadataFilePath);
@Override public void finish() throws IOException, InterruptedException { sortMerger.finishAdding(); List<SortedDataFile<Tuple2<Integer, T>>> remainFiles = sortMerger.getRemainingSortedDataFiles(); int nextFileId = 0; FileSystem localFileSystem = FileSystem.getLocalFileSystem(); for (SortedDataFile<Tuple2<Integer, T>> file : remainFiles) { // rename file localFileSystem.rename( new Path(file.getChannelID().getPath()), new Path(ExternalBlockShuffleUtils.generateDataPath(partitionDataRootPath, nextFileId++))); } LOG.info("Finish external result partition writing."); }