@Override public boolean delete(Path f, boolean recursive) throws IOException { return originalFs.delete(f, recursive); }
@Override public boolean delete(Path f, boolean recursive) throws IOException { return unsafeFileSystem.delete(f, recursive); }
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); } }
return fileSystem.delete(path, false);
/** * Deletes the YARN application files, e.g., Flink binaries, libraries, etc., from the remote * filesystem. * * @param env The environment variables. */ public static void deleteApplicationFiles(final Map<String, String> env) { final String applicationFilesDir = env.get(YarnConfigKeys.FLINK_YARN_FILES); if (!StringUtils.isNullOrWhitespaceOnly(applicationFilesDir)) { final org.apache.flink.core.fs.Path path = new org.apache.flink.core.fs.Path(applicationFilesDir); try { final org.apache.flink.core.fs.FileSystem fileSystem = path.getFileSystem(); if (!fileSystem.delete(path, true)) { LOG.error("Deleting yarn application files under {} was unsuccessful.", applicationFilesDir); } } catch (final IOException e) { LOG.error("Could not properly delete yarn application files directory {}.", applicationFilesDir, e); } } else { LOG.debug("No yarn application files directory set. Therefore, cannot clean up the data."); } }
@Override public void tryCleanupOnError() { if (this.fileCreated) { this.fileCreated = false; try { close(); } catch (IOException e) { LOG.error("Could not properly close FileOutputFormat.", e); } try { FileSystem.get(this.actualFilePath.toUri()).delete(actualFilePath, false); } catch (FileNotFoundException e) { // ignore, may not be visible yet or may be already removed } catch (Throwable t) { LOG.error("Could not remove the incomplete file " + actualFilePath + '.', t); } } } }
@After public void cleanup() throws Exception { fs.delete(basePath, true); }
flinkFileSystem.delete(haDataDirectory, true);
@After public void cleanup() throws Exception { getFileSystem().delete(basePathForTest, true); }
restoreFileSystem.delete(instancePath, true);
@Test public void testSimpleFileWriteAndRead() throws Exception { final String testLine = "Hello Upload!"; final Path path = new Path(basePath, "test.txt"); try { try (FSDataOutputStream out = fs.create(path, FileSystem.WriteMode.OVERWRITE); OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) { writer.write(testLine); } // just in case, wait for the path to exist checkPathExistence(path, true, deadline); try (FSDataInputStream in = fs.open(path); InputStreamReader ir = new InputStreamReader(in, StandardCharsets.UTF_8); BufferedReader reader = new BufferedReader(ir)) { String line = reader.readLine(); assertEquals(testLine, line); } } finally { fs.delete(path, false); } checkPathExistence(path, false, deadline); }
local.delete(new Path(localTmpPath), true); } catch (IOException ioe) { LOG.error("PythonAPI file cleanup failed. {}", ioe.getMessage());
FileSystem restoreFileSystem = temporaryRestoreInstancePath.getFileSystem(); if (restoreFileSystem.exists(temporaryRestoreInstancePath)) { restoreFileSystem.delete(temporaryRestoreInstancePath, true);
@Test public void testGenericRecord() throws IOException { final Path outputPath = new Path(File.createTempFile("avro-output-file", "generic.avro").getAbsolutePath()); final AvroOutputFormat<GenericRecord> outputFormat = new AvroOutputFormat<>(outputPath, GenericRecord.class); Schema schema = new Schema.Parser().parse("{\"type\":\"record\", \"name\":\"user\", \"fields\": [{\"name\":\"user_name\", \"type\":\"string\"}, {\"name\":\"favorite_number\", \"type\":\"int\"}, {\"name\":\"favorite_color\", \"type\":\"string\"}]}"); outputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE); outputFormat.setSchema(schema); output(outputFormat, schema); GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema); DataFileReader<GenericRecord> dataFileReader = new DataFileReader<>(new File(outputPath.getPath()), reader); while (dataFileReader.hasNext()) { GenericRecord record = dataFileReader.next(); assertEquals(record.get("user_name").toString(), "testUser"); assertEquals(record.get("favorite_number"), 1); assertEquals(record.get("favorite_color").toString(), "blue"); } //cleanup FileSystem fs = FileSystem.getLocalFileSystem(); fs.delete(outputPath, false); }
@AfterClass public static void teardown() throws IOException, InterruptedException { try { if (fs != null) { // clean up fs.delete(basePath, true); // now directory must be gone checkPathExistence(basePath, false, deadline); } } finally { FileSystem.initialize(new Configuration()); } } }
FileSystem restoreFileSystem = temporaryRestoreInstancePath.getFileSystem(); if (restoreFileSystem.exists(temporaryRestoreInstancePath)) { restoreFileSystem.delete(temporaryRestoreInstancePath, true);
@Test public void testCompression() throws Exception { // given final Path outputPath = new Path(File.createTempFile("avro-output-file", "avro").getAbsolutePath()); final AvroOutputFormat<User> outputFormat = new AvroOutputFormat<>(outputPath, User.class); outputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE); final Path compressedOutputPath = new Path(File.createTempFile("avro-output-file", "compressed.avro").getAbsolutePath()); final AvroOutputFormat<User> compressedOutputFormat = new AvroOutputFormat<>(compressedOutputPath, User.class); compressedOutputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE); compressedOutputFormat.setCodec(AvroOutputFormat.Codec.SNAPPY); // when output(outputFormat); output(compressedOutputFormat); // then assertTrue(fileSize(outputPath) > fileSize(compressedOutputPath)); // cleanup FileSystem fs = FileSystem.getLocalFileSystem(); fs.delete(outputPath, false); fs.delete(compressedOutputPath, false); }
fs.delete(directory, true);
/** * 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)); }