@Override public boolean exists(Path f) throws IOException { return originalFs.exists(f); }
@Override public boolean exists(Path f) throws IOException { return unsafeFileSystem.exists(f); }
private static void deleteIfExists(Path path) throws IOException { FileSystem fs = path.getFileSystem(); if (fs.exists(path)) { fs.delete(path, true); } }
private static void deleteIfExists(Path path) throws IOException { FileSystem fs = path.getFileSystem(); if (fs.exists(path)) { fs.delete(path, true); } }
public static void checkPathExistence(Path path, boolean expectedExists, long deadline) throws IOException, InterruptedException { if (deadline == 0) { //strongly consistency assertEquals(expectedExists, fs.exists(path)); } else { //eventually consistency checkPathEventualExistence(fs, path, expectedExists, deadline); } }
public VirtualFileServerHandler(Path path) throws IOException { this.path = path; if (!path.isAbsolute()) { throw new IllegalArgumentException("path must be absolute: " + path.toString()); } this.fs = path.getFileSystem(); if (!fs.exists(path) || fs.getFileStatus(path).isDir()) { throw new IllegalArgumentException("no such file: " + path.toString()); } }
/** * Verifies that the given path eventually appears on / disappears from <tt>fs</tt> within * <tt>deadline</tt> nanoseconds. */ public static void checkPathEventualExistence( FileSystem fs, Path path, boolean expectedExists, long deadline) throws IOException, InterruptedException { boolean dirExists; while ((dirExists = fs.exists(path)) != expectedExists && System.nanoTime() < deadline) { Thread.sleep(10); } assertEquals(expectedExists, dirExists); } }
if (restoreFileSystem.exists(instancePath)) { restoreFileSystem.delete(instancePath, true);
Path p = new Path(path); FileSystem fileSystem = FileSystem.get(p.toUri()); if (!fileSystem.exists(p)) { throw new FileNotFoundException("The provided file path " + path + " does not exist.");
if (!FileSystem.getUnguardedFileSystem(planPath.toUri()).exists(planPath)) { throw new FileNotFoundException("Plan file " + planFile + " does not exist."); if (!FileSystem.getUnguardedFileSystem(filePath.toUri()).exists(filePath)) { throw new FileNotFoundException("Additional file " + file + " does not exist.");
if (restoreFileSystem.exists(temporaryRestoreInstancePath)) { restoreFileSystem.delete(temporaryRestoreInstancePath, true);
if (!FileSystem.getUnguardedFileSystem(planPath.toUri()).exists(planPath)) { throw new FileNotFoundException("Plan file " + planFile + " does not exist."); if (!FileSystem.getUnguardedFileSystem(filePath.toUri()).exists(filePath)) { throw new FileNotFoundException("Additional file " + file + " does not exist.");
/** * Copies all files from source to target and sets executable flag. Paths might be on different systems. * @param sourcePath source path to copy from * @param targetPath target path to copy to * @param executable if target file should be executable * @throws IOException if the copy fails */ public static void copy(Path sourcePath, Path targetPath, boolean executable) throws IOException { // we unwrap the file system to get raw streams without safety net FileSystem sFS = FileSystem.getUnguardedFileSystem(sourcePath.toUri()); FileSystem tFS = FileSystem.getUnguardedFileSystem(targetPath.toUri()); if (!tFS.exists(targetPath)) { if (sFS.getFileStatus(sourcePath).isDir()) { internalCopyDirectory(sourcePath, targetPath, executable, sFS, tFS); } else { internalCopyFile(sourcePath, targetPath, executable, sFS, tFS); } } }
/** * Test that {@link FileUtils#deletePathIfEmpty(FileSystem, Path)} deletes the path if it is * empty. A path can only be empty if it is a directory which does not contain any * files/directories. */ @Test public void testDeletePathIfEmpty() throws IOException { File file = temporaryFolder.newFile(); File directory = temporaryFolder.newFolder(); File directoryFile = new File(directory, UUID.randomUUID().toString()); assertTrue(directoryFile.createNewFile()); Path filePath = new Path(file.toURI()); Path directoryPath = new Path(directory.toURI()); Path directoryFilePath = new Path(directoryFile.toURI()); FileSystem fs = FileSystem.getLocalFileSystem(); // verify that the files have been created assertTrue(fs.exists(filePath)); assertTrue(fs.exists(directoryFilePath)); // delete the single file assertFalse(FileUtils.deletePathIfEmpty(fs, filePath)); assertTrue(fs.exists(filePath)); // try to delete the non-empty directory assertFalse(FileUtils.deletePathIfEmpty(fs, directoryPath)); assertTrue(fs.exists(directoryPath)); // delete the file contained in the directory assertTrue(fs.delete(directoryFilePath, false)); // now the deletion should work assertTrue(FileUtils.deletePathIfEmpty(fs, directoryPath)); assertFalse(fs.exists(directoryPath)); }
} finally { FileSystem restoreFileSystem = temporaryRestoreInstancePath.getFileSystem(); if (restoreFileSystem.exists(temporaryRestoreInstancePath)) { restoreFileSystem.delete(temporaryRestoreInstancePath, true);
@Test public void testMkdirsReturnsTrueWhenCreatingDirectory() throws Exception { // this test applies to object stores as well, as rely on the fact that they // return true when things are not bad final Path directory = new Path(basePath, randomName()); assertTrue(fs.mkdirs(directory)); if (getFileSystemKind() != FileSystemKind.OBJECT_STORE) { assertTrue(fs.exists(directory)); } }
private static void assertState(DistributedCache.DistributedCacheEntry entry, boolean isExecutable, boolean isZipped) throws IOException { assertNotNull(entry); assertEquals(isExecutable, entry.isExecutable); assertEquals(isZipped, entry.isZipped); org.apache.flink.core.fs.Path filePath = new org.apache.flink.core.fs.Path(entry.filePath); assertTrue(filePath.getFileSystem().exists(filePath)); assertFalse(filePath.getFileSystem().getFileStatus(filePath).isDir()); } }
@Test public void testMkdirsCreatesParentDirectories() throws Exception { // this test applies to object stores as well, as rely on the fact that they // return true when things are not bad final Path directory = new Path(new Path(new Path(basePath, randomName()), randomName()), randomName()); assertTrue(fs.mkdirs(directory)); if (getFileSystemKind() != FileSystemKind.OBJECT_STORE) { assertTrue(fs.exists(directory)); } }