com.google.common.io.RecursiveDeleteOption Java Examples

The following examples show how to use com.google.common.io.RecursiveDeleteOption. 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: ProcessRuntimeTest.java    From pulsar with Apache License 2.0 6 votes vote down vote up
@Test
public void testJavaConstructorWithDeps() throws Exception {
    InstanceConfig config = createJavaInstanceConfig(FunctionDetails.Runtime.JAVA);

    Path dir = Files.createTempDirectory("test-empty-dir");
    assertTrue(Files.exists(dir));
    try {
        int numFiles = 3;
        for (int i = 0; i < numFiles; i++) {
            Path file = Files.createFile(Paths.get(dir.toAbsolutePath().toString(), "file-" + i));
            assertTrue(Files.exists(file));
        }

        factory = createProcessRuntimeFactory(dir.toAbsolutePath().toString());

        verifyJavaInstance(config, dir);
    } finally {
        MoreFiles.deleteRecursively(dir, RecursiveDeleteOption.ALLOW_INSECURE);
    }
}
 
Example #3
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 #4
Source File: DirectoryListCacheTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void whenRootFolderIsDeletedThenInvalidateAll() throws Exception {
  Path root = tmp.getRoot().resolve("root");
  Files.createDirectory(root);

  DirectoryListCache cache = DirectoryListCache.of(root);
  Path dir = root.resolve("dir");
  Files.createDirectory(dir);
  Files.createFile(dir.resolve("file"));

  cache.put(
      ImmutableDirectoryListKey.of(Paths.get("")),
      ImmutableDirectoryList.of(
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of(Paths.get("dir")),
          ImmutableSortedSet.of()));

  cache.put(
      ImmutableDirectoryListKey.of(Paths.get("dir")),
      ImmutableDirectoryList.of(
          ImmutableSortedSet.of(Paths.get("dir/file")),
          ImmutableSortedSet.of(),
          ImmutableSortedSet.of()));

  MoreFiles.deleteRecursively(root, RecursiveDeleteOption.ALLOW_INSECURE);

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

  // should invalidate root properly
  Optional<DirectoryList> dlist = cache.get(ImmutableDirectoryListKey.of(Paths.get("")));
  assertFalse(dlist.isPresent());

  dlist = cache.get(ImmutableDirectoryListKey.of(Paths.get("dir")));
  assertFalse(dlist.isPresent());
}
 
Example #5
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 #6
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 #7
Source File: ExtensionClassExporter.java    From Mixin with MIT License 5 votes vote down vote up
public ExtensionClassExporter(MixinEnvironment env) {
    this.decompiler = this.initDecompiler(env, new File(Constants.DEBUG_OUTPUT_DIR, ExtensionClassExporter.EXPORT_JAVA_DIR));

    try {
        MoreFiles.deleteRecursively(this.classExportDir.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException ex) {
        ExtensionClassExporter.logger.debug("Error cleaning class output directory: {}", ex.getMessage());
    }
}
 
Example #8
Source File: RuntimeDecompiler.java    From Mixin with MIT License 5 votes vote down vote up
public RuntimeDecompiler(File outputPath) {
    this.outputPath = outputPath;
    if (this.outputPath.exists()) {
        try {
            MoreFiles.deleteRecursively(this.outputPath.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
        } catch (IOException ex) {
            this.logger.debug("Error cleaning output directory: {}", ex.getMessage());
        }
    }
}
 
Example #9
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 #10
Source File: ProcessRuntimeTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test
public void testJavaConstructorWithEmptyDir() throws Exception {
    InstanceConfig config = createJavaInstanceConfig(FunctionDetails.Runtime.JAVA);

    Path dir = Files.createTempDirectory("test-empty-dir");
    assertTrue(Files.exists(dir));
    try {
        factory = createProcessRuntimeFactory(dir.toAbsolutePath().toString());

        verifyJavaInstance(config, dir);
    } finally {
        MoreFiles.deleteRecursively(dir, RecursiveDeleteOption.ALLOW_INSECURE);
    }
}
 
Example #11
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 #12
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 #13
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 #14
Source File: DashboardTest.java    From cloud-opensource-java with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void cleanUp() {
  try {
    // Mac's APFS fails with InsecureRecursiveDeleteException without ALLOW_INSECURE.
    // Still safe as this test does not use symbolic links
    if (outputDirectory != null) {
      MoreFiles.deleteRecursively(outputDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
    }
  } catch (IOException ex) {
    // no big deal
  }
}
 
Example #15
Source File: AbstractCacheBasedTest.java    From lemminx with Eclipse Public License 2.0 5 votes vote down vote up
@AfterEach
public final void clearCache() throws IOException {
	if (Files.exists(TEST_WORK_DIRECTORY)) {
		MoreFiles.deleteDirectoryContents(TEST_WORK_DIRECTORY,RecursiveDeleteOption.ALLOW_INSECURE);
	}
	System.clearProperty(FilesUtils.LEMMINX_WORKDIR_KEY);
	FilesUtils.resetDeployPath();
}
 
Example #16
Source File: WorldStateDownloaderBenchmark.java    From besu with Apache License 2.0 5 votes vote down vote up
@TearDown(Level.Invocation)
public void tearDown() throws Exception {
  ethProtocolManager.stop();
  ethProtocolManager.awaitStop();
  pendingRequests.close();
  storageProvider.close();
  MoreFiles.deleteRecursively(tempDir, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example #17
Source File: OrionTestHarness.java    From besu with Apache License 2.0 5 votes vote down vote up
public void close() {
  stop();
  try {
    MoreFiles.deleteRecursively(config.workDir(), RecursiveDeleteOption.ALLOW_INSECURE);
  } catch (final IOException e) {
    LOG.info("Failed to clean up temporary file: {}", config.workDir(), e);
  }
}
 
Example #18
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 #19
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 #20
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 #21
Source File: TestCaseUtils.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Cleans the AIRSONIC_HOME directory used for tests. (Does not delete the folder itself)
 */
public static void cleanAirsonicHomeForTest() throws IOException {
    Path airsonicHomeDir = Paths.get(airsonicHomePathForTest());
    MoreFiles.deleteDirectoryContents(airsonicHomeDir, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example #22
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());
}
 
Example #23
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 #24
Source File: OperationBenchmarkHelper.java    From besu with Apache License 2.0 4 votes vote down vote up
public void cleanUp() throws IOException {
  keyValueStorage.close();
  MoreFiles.deleteRecursively(storageDirectory, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example #25
Source File: PGPKeysCacheTest.java    From pgpverify-maven-plugin with Apache License 2.0 4 votes vote down vote up
@AfterMethod
public void cleanup() throws IOException {
    MoreFiles.deleteRecursively(cachePath, RecursiveDeleteOption.ALLOW_INSECURE);
}
 
Example #26
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 #27
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 #28
Source File: FreemarkerTest.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 #29
Source File: ContentModelManagerCacheTest.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testXSDCache() throws IOException, BadLocationException {
	String xsdPath = tempDirUri.getPath() + "/tag.xsd";
	String xmlPath = tempDirUri.toString() + "/tag.xml";

	// Create a XSD file in the temp directory
	String xsd = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" + //
			"<xs:schema\r\n" + //
			"    xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + //
			"    elementFormDefault=\"qualified\">\r\n" + //
			"  <xs:element name=\"root\">\r\n" + //
			"    <xs:complexType>\r\n" + //
			"      <xs:sequence>\r\n" + //
			"        <xs:element name=\"tag\"/>\r\n" + //
			"      </xs:sequence>\r\n" + //
			"    </xs:complexType>\r\n" + //
			"  </xs:element>\r\n" + //
			"</xs:schema>";
	createFile(xsdPath, xsd);

	// Open completion in a XML which is bound to the XML Schema
	String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n" + //
			"<root\r\n" + //
			"    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + //
			"    xsi:noNamespaceSchemaLocation=\"tag.xsd\">\r\n" + //
			"  | " + // <-- completion must provide tag
			"</root>";
	XMLAssert.testCompletionFor(xml, null, xmlPath, 5 /* region, endregion, cdata, comment, tag */,
			c("tag", "<tag></tag>"));
	// Open again the completion to use the cache
	XMLAssert.testCompletionFor(xml, null, xmlPath, null, c("tag", "<tag></tag>"));

	// Change the content of the XSD on the file system
	xsd = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" + //
			"<xs:schema\r\n" + //
			"    xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\r\n" + //
			"    elementFormDefault=\"qualified\">\r\n" + //
			"  <xs:element name=\"root\">\r\n" + //
			"    <xs:complexType>\r\n" + //
			"      <xs:sequence>\r\n" + //
			"        <xs:element name=\"label\"/>\r\n" + // <-- change tag by label
			"      </xs:sequence>\r\n" + //
			"    </xs:complexType>\r\n" + //
			"  </xs:element>\r\n" + //
			"</xs:schema>";
	updateFile(xsdPath, xsd);

	XMLAssert.testCompletionFor(xml, null, xmlPath, 5 /* region, endregion, cdata, comment, label */,
			c("label", "<label></label>"));
	// Open again the completion to use the cache
	XMLAssert.testCompletionFor(xml, null, xmlPath, 5, c("label", "<label></label>"));

	// delete the XSD file
	MoreFiles.deleteRecursively(new File(xsdPath).toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
	// Completion must be empty
	XMLAssert.testCompletionFor(xml, null, xmlPath, 4 /* region, endregion, cdata, comment */);
	
	// recreate the XSD file
	createFile(xsdPath, xsd);
	XMLAssert.testCompletionFor(xml, null, xmlPath, 5 /* region, endregion, cdata, comment, label */,
			c("label", "<label></label>"));
	XMLAssert.testCompletionFor(xml, null, xmlPath, 5 /* region, endregion, cdata, comment, label */,
			c("label", "<label></label>"));
	
}
 
Example #30
Source File: CleanupOldDeploysJob.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
private void deleteDirectories(List<File> directories) throws IOException {
  for (int i = RECENT_DIRECTORIES_TO_KEEP; i < directories.size(); i++) {
    MoreFiles.deleteRecursively(directories.get(i).toPath(),
        RecursiveDeleteOption.ALLOW_INSECURE);
  }
}