/** * Delete a file or directory and its contents recursively. * Don't follow directories if they are symlinks. * * @param file Input file / dir to be deleted * @throws IOException if deletion is unsuccessful */ public static void deleteRecursively(File file) throws IOException { deleteRecursively(file, null); }
/** * Delete a file or directory and its contents recursively. * Don't follow directories if they are symlinks. * * @param file Input file / dir to be deleted * @throws IOException if deletion is unsuccessful */ public static void deleteRecursively(File file) throws IOException { deleteRecursively(file, null); }
/** * Synchronously deletes each directory one at a time. * Should be executed in its own thread, as this may take a long time. */ private void deleteExecutorDirs(String[] dirs) { for (String localDir : dirs) { try { JavaUtils.deleteRecursively(new File(localDir)); logger.debug("Successfully cleaned up directory: {}", localDir); } catch (Exception e) { logger.error("Failed to delete directory: " + localDir, e); } } }
/** * Synchronously deletes each directory one at a time. * Should be executed in its own thread, as this may take a long time. */ private void deleteExecutorDirs(String[] dirs) { for (String localDir : dirs) { try { JavaUtils.deleteRecursively(new File(localDir)); logger.debug("Successfully cleaned up directory: {}", localDir); } catch (Exception e) { logger.error("Failed to delete directory: " + localDir, e); } } }
/** * Synchronously deletes each directory one at a time. * Should be executed in its own thread, as this may take a long time. */ private void deleteExecutorDirs(String[] dirs) { for (String localDir : dirs) { try { JavaUtils.deleteRecursively(new File(localDir)); logger.debug("Successfully cleaned up directory: {}", localDir); } catch (Exception e) { logger.error("Failed to delete directory: " + localDir, e); } } }
/** * Synchronously deletes non-shuffle files in each directory recursively. * Should be executed in its own thread, as this may take a long time. */ private void deleteNonShuffleFiles(String[] dirs) { FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { // Don't delete shuffle data or shuffle index files. return !name.endsWith(".index") && !name.endsWith(".data"); } }; for (String localDir : dirs) { try { JavaUtils.deleteRecursively(new File(localDir), filter); logger.debug("Successfully cleaned up non-shuffle files in directory: {}", localDir); } catch (Exception e) { logger.error("Failed to delete non-shuffle files in directory: " + localDir, e); } } }
/** * Synchronously deletes non-shuffle files in each directory recursively. * Should be executed in its own thread, as this may take a long time. */ private void deleteNonShuffleFiles(String[] dirs) { FilenameFilter filter = new FilenameFilter() { @Override public boolean accept(File dir, String name) { // Don't delete shuffle data or shuffle index files. return !name.endsWith(".index") && !name.endsWith(".data"); } }; for (String localDir : dirs) { try { JavaUtils.deleteRecursively(new File(localDir), filter); logger.debug("Successfully cleaned up non-shuffle files in directory: {}", localDir); } catch (Exception e) { logger.error("Failed to delete non-shuffle files in directory: " + localDir, e); } } }
void cleanup() { if (tempDir != null) { try { JavaUtils.deleteRecursively(tempDir); } catch (IOException io) { throw new RuntimeException(io); } } } }
private static void deleteRecursivelyUsingJavaIO(File file) throws IOException { if (file.isDirectory() && !isSymlink(file)) { IOException savedIOException = null; for (File child : listFilesSafely(file)) { try { deleteRecursively(child); } catch (IOException e) { // In case of multiple exceptions, only last one will be thrown savedIOException = e; } } if (savedIOException != null) { throw savedIOException; } } boolean deleted = file.delete(); // Delete can also fail if the file simply did not exist. if (!deleted && file.exists()) { throw new IOException("Failed to delete: " + file.getAbsolutePath()); } }
private static void deleteRecursivelyUsingJavaIO(File file) throws IOException { if (file.isDirectory() && !isSymlink(file)) { IOException savedIOException = null; for (File child : listFilesSafely(file)) { try { deleteRecursively(child); } catch (IOException e) { // In case of multiple exceptions, only last one will be thrown savedIOException = e; } } if (savedIOException != null) { throw savedIOException; } } boolean deleted = file.delete(); // Delete can also fail if the file simply did not exist. if (!deleted && file.exists()) { throw new IOException("Failed to delete: " + file.getAbsolutePath()); } }
public void cleanup() { for (String localDir : localDirs) { try { JavaUtils.deleteRecursively(new File(localDir)); } catch (IOException e) { logger.warn("Unable to cleanup localDir = " + localDir, e); } } }
public void cleanup() { for (String localDir : localDirs) { try { JavaUtils.deleteRecursively(new File(localDir)); } catch (IOException e) { logger.warn("Unable to cleanup localDir = " + localDir, e); } } }
public void cleanup() { for (String localDir : localDirs) { try { JavaUtils.deleteRecursively(new File(localDir)); } catch (IOException e) { logger.warn("Unable to cleanup localDir = " + localDir, e); } } }
private static void deleteRecursivelyUsingJavaIO( File file, FilenameFilter filter) throws IOException { if (file.isDirectory() && !isSymlink(file)) { IOException savedIOException = null; for (File child : listFilesSafely(file, filter)) { try { deleteRecursively(child, filter); } catch (IOException e) { // In case of multiple exceptions, only last one will be thrown savedIOException = e; } } if (savedIOException != null) { throw savedIOException; } } // Delete file only when it's a normal file or an empty directory. if (file.isFile() || (file.isDirectory() && listFilesSafely(file, null).length == 0)) { boolean deleted = file.delete(); // Delete can also fail if the file simply did not exist. if (!deleted && file.exists()) { throw new IOException("Failed to delete: " + file.getAbsolutePath()); } } }
private static void deleteRecursivelyUsingJavaIO( File file, FilenameFilter filter) throws IOException { if (file.isDirectory() && !isSymlink(file)) { IOException savedIOException = null; for (File child : listFilesSafely(file, filter)) { try { deleteRecursively(child, filter); } catch (IOException e) { // In case of multiple exceptions, only last one will be thrown savedIOException = e; } } if (savedIOException != null) { throw savedIOException; } } // Delete file only when it's a normal file or an empty directory. if (file.isFile() || (file.isDirectory() && listFilesSafely(file, null).length == 0)) { boolean deleted = file.delete(); // Delete can also fail if the file simply did not exist. if (!deleted && file.exists()) { throw new IOException("Failed to delete: " + file.getAbsolutePath()); } } }