Java Code Examples for com.google.common.io.MoreFiles#deleteRecursively()

The following examples show how to use com.google.common.io.MoreFiles#deleteRecursively() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FunctionActioner.java    From pulsar with Apache License 2.0 6 votes vote down vote up
private void cleanupFunctionFiles(FunctionRuntimeInfo functionRuntimeInfo) {
    Function.Instance instance = functionRuntimeInfo.getFunctionInstance();
    FunctionMetaData functionMetaData = instance.getFunctionMetaData();
    // clean up function package
    File pkgDir = new File(
            workerConfig.getDownloadDirectory(),
            getDownloadPackagePath(functionMetaData, instance.getInstanceId()));

    if (pkgDir.exists()) {
        try {
            MoreFiles.deleteRecursively(
                    Paths.get(pkgDir.toURI()), RecursiveDeleteOption.ALLOW_INSECURE);
        } catch (IOException e) {
            log.warn("Failed to delete package for function: {}",
                    FunctionCommon.getFullyQualifiedName(functionMetaData.getFunctionDetails()), e);
        }
    }
}
 
Example 2
Source File: ZipUtilsTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@AfterAll
public void tearDown() {
  try {
    MoreFiles.deleteRecursively(tmpDir);
  } catch (IOException ex) {
    // ignore
  }
}
 
Example 3
Source File: FileUtil.java    From copybara with Apache License 2.0 5 votes vote down vote up
/**
 * Delete all the contents of a path recursively.
 *
 * <p>First we try to delete securely. In case the FileSystem doesn't support it,
 * delete it insecurely.
 */
public static void deleteRecursively(Path path) throws IOException {
  try {
    MoreFiles.deleteRecursively(path);
  } catch (InsecureRecursiveDeleteException ignore) {
    logger.atWarning().log("Secure delete not supported. Deleting '%s' insecurely.", path);
    MoreFiles.deleteRecursively(path, RecursiveDeleteOption.ALLOW_INSECURE);
  }
}
 
Example 4
Source File: BesuNode.java    From besu with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("UnstableApiUsage")
public void close() {
  stop();
  try {
    MoreFiles.deleteRecursively(homeDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
  } catch (final IOException e) {
    LOG.info("Failed to clean up temporary file: {}", homeDirectory, e);
  }
}
 
Example 5
Source File: SimpleJavaLibraryBuilder.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static void cleanupDirectory(@Nullable Path directory) throws IOException {
  if (directory == null) {
    return;
  }

  if (Files.exists(directory)) {
    try {
      MoreFiles.deleteRecursively(directory, RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException e) {
      throw new IOException("Cannot clean '" + directory + "'", e);
    }
  }

  Files.createDirectories(directory);
}
 
Example 6
Source File: WindowsBundledPythonCopier.java    From appengine-plugins-core with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static void deleteCopiedPython(String pythonExePath) {
  // The path returned from gcloud points to the "python.exe" binary. Delete it from the path.
  String pythonHome = pythonExePath.replaceAll("[pP][yY][tT][hH][oO][nN]\\.[eE][xX][eE]$", "");
  boolean endsWithPythonExe = !pythonHome.equals(pythonExePath);

  if (endsWithPythonExe) { // just to be safe
    try {
      MoreFiles.deleteRecursively(Paths.get(pythonHome), RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException e) {
      // not critical to remove a temp directory
    }
  }
}
 
Example 7
Source File: FileUtil.java    From teku with Apache License 2.0 5 votes vote down vote up
public static void recursivelyDeleteDirectories(final List<File> directories) {
  for (File tmpDirectory : directories) {
    try {
      MoreFiles.deleteRecursively(tmpDirectory.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException e) {
      LOG.error("Failed to delete directory: " + tmpDirectory.getAbsolutePath(), e);
      throw new RuntimeException(e);
    }
  }
}
 
Example 8
Source File: SafeFilesTest.java    From Strata with Apache License 2.0 5 votes vote down vote up
@AfterAll
public void tearDown() {
  try {
    MoreFiles.deleteRecursively(tmpDir);
  } catch (IOException ex) {
    // ignore
  }
}
 
Example 9
Source File: FastSyncDownloader.java    From besu with Apache License 2.0 5 votes vote down vote up
public void deleteFastSyncState() {
  // Make sure downloader is stopped before we start cleaning up its dependencies
  worldStateDownloader.cancel();
  try {
    taskCollection.close();
    if (fastSyncDataDirectory.toFile().exists()) {
      // Clean up this data for now (until fast sync resume functionality is in place)
      MoreFiles.deleteRecursively(fastSyncDataDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
    }
  } catch (final IOException e) {
    LOG.error("Unable to clean up fast sync state", e);
  }
}
 
Example 10
Source File: FileOperationProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the file or directory at the given path recursively, allowing insecure delete according
 * to {@code allowInsecureDelete}.
 *
 * @see RecursiveDeleteOption#ALLOW_INSECURE
 */
public void deleteRecursively(File file, boolean allowInsecureDelete) throws IOException {
  if (allowInsecureDelete) {
    MoreFiles.deleteRecursively(file.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
  } else {
    MoreFiles.deleteRecursively(file.toPath());
  }
}
 
Example 11
Source File: VanillaJavaBuilder.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static void createOutputDirectory(Path dir) throws IOException {
  if (Files.exists(dir)) {
    try {
      MoreFiles.deleteRecursively(dir, RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException e) {
      throw new IOException("Cannot clean output directory '" + dir + "'", e);
    }
  }
  Files.createDirectories(dir);
}
 
Example 12
Source File: Files.java    From mojito with Apache License 2.0 5 votes vote down vote up
public static void deleteRecursivelyIfExists(Path path) {
    try {
        if (path.toFile().exists()) {
            MoreFiles.deleteRecursively(path, RecursiveDeleteOption.ALLOW_INSECURE);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
Example 13
Source File: BaseFileTempTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
private static void deleteTempDirIfExists() throws IOException {
	File tempDir = new File(tempDirUri);
	if (tempDir.exists()) {
		MoreFiles.deleteRecursively(tempDir.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
	}
}
 
Example 14
Source File: JacocoInstrumentationProcessor.java    From bazel with Apache License 2.0 4 votes vote down vote up
public void cleanup() throws IOException {
  if (Files.exists(instrumentedClassesDirectory)) {
    MoreFiles.deleteRecursively(
        instrumentedClassesDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
  }
}
 
Example 15
Source File: AndroidDataBindingProcessingActionTest.java    From bazel with Apache License 2.0 4 votes vote down vote up
@After
public void deletePaths() throws Exception {
  Files.deleteIfExists(dataBindingInfoOut);
  MoreFiles.deleteRecursively(tempDir);
}
 
Example 16
Source File: DashboardUnavailableArtifactTest.java    From cloud-opensource-java with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void cleanUp() throws IOException {
  // Mac's APFS fails with InsecureRecursiveDeleteException without ALLOW_INSECURE.
  // Still safe as this test does not use symbolic links
  MoreFiles.deleteRecursively(outputDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example 17
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@AfterAll
static void afterAll() throws IOException {
    support.after();
    MoreFiles.deleteRecursively(baseDataDir, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example 18
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@AfterAll
static void afterAll() throws IOException {
    support.after();
    MoreFiles.deleteRecursively(baseDataDir, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example 19
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@AfterAll
static void afterAll() throws IOException {
    support.after();
    MoreFiles.deleteRecursively(baseDataDir, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example 20
Source File: DirectoryListCacheTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void whenFolderIsDeletedThenInvalidateParent() throws Exception {
  Path root = tmp.getRoot();
  DirectoryListCache cache = DirectoryListCache.of(root);
  Path dir1 = root.resolve("dir1");
  Files.createDirectory(dir1);
  Files.createFile(dir1.resolve("file1"));
  Path dir2 = dir1.resolve("dir2");
  Files.createDirectory(dir2);
  Files.createFile(dir2.resolve("file2"));

  cache.put(
      ImmutableDirectoryListKey.of(Paths.get("dir1")),
      ImmutableDirectoryList.of(
          ImmutableSortedSet.of(Paths.get("dir1/file1")),
          ImmutableSortedSet.of(Paths.get("dir1/dir2")),
          ImmutableSortedSet.of()));

  cache.put(
      ImmutableDirectoryListKey.of(Paths.get("dir1/dir2")),
      ImmutableDirectoryList.of(
          ImmutableSortedSet.of(Paths.get("dir1/dir2/file2")),
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of()));

  MoreFiles.deleteRecursively(dir2, RecursiveDeleteOption.ALLOW_INSECURE);

  WatchmanPathEvent event =
      WatchmanPathEvent.of(
          AbsPath.of(root), Kind.DELETE, RelPath.of(Paths.get("dir1/dir2/file2")));
  FileHashCacheEvent.InvalidationStarted started = FileHashCacheEvent.invalidationStarted();
  cache.getInvalidator().onInvalidationStart(started);
  cache.getInvalidator().onFileSystemChange(event);
  cache.getInvalidator().onInvalidationFinish(FileHashCacheEvent.invalidationFinished(started));

  // should invalidate both folder and parent folder
  Optional<DirectoryList> dlist = cache.get(ImmutableDirectoryListKey.of(Paths.get("dir1/dir2")));
  assertFalse(dlist.isPresent());

  dlist = cache.get(ImmutableDirectoryListKey.of(Paths.get("dir1")));
  assertFalse(dlist.isPresent());
}