List of usage examples for com.google.common.io MoreFiles deleteRecursively
public static void deleteRecursively(Path path, RecursiveDeleteOption... options) throws IOException
From source file:com.otcdlink.chiron.testing.DirectoryFixture.java
private static File getAllFixturesDirectory() throws IOException { synchronized (LOCK) { File file = allFixturesDirectory; if (null == file) { final String testfilesDirSystemProperty = System .getProperty(SCRATCH_DIRECTORY_SYSTEM_PROPERTY_NAME); if (null == testfilesDirSystemProperty) { file = new File(DEFAULT_SCRATCH_DIR_NAME).getCanonicalFile(); } else { file = new File(testfilesDirSystemProperty).getCanonicalFile(); }/*from w ww . j a va 2 s . c o m*/ if (file.exists() && !"no" .equalsIgnoreCase(System.getProperty(DELETE_SCRATCH_DIRECTORY_SYSTEM_PROPERTY_NAME))) { MoreFiles.deleteRecursively(file.toPath(), RecursiveDeleteOption.ALLOW_INSECURE); } else { if (file.mkdir()) { // LOGGER.debug( "Created '", file.getAbsolutePath(), "'." ) ; } } // LOGGER.info( "Created ", file.getAbsolutePath(), "' as clean directory for all fixtures." ) ; } allFixturesDirectory = file; return allFixturesDirectory; } }
From source file:com.google.cloud.tools.managedcloudsdk.components.WindowsBundledPythonCopier.java
@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 {/*from w w w . j ava 2s . c o m*/ MoreFiles.deleteRecursively(Paths.get(pythonHome), RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException e) { // not critical to remove a temp directory } } }
From source file:com.google.cloud.tools.managedcloudsdk.install.Extractor.java
private void cleanUp(final Path target) throws IOException { MoreFiles.deleteRecursively(target, RecursiveDeleteOption.ALLOW_INSECURE); }
From source file:org.apache.bookkeeper.statelib.impl.rocksdb.checkpoint.RocksCheckpointer.java
private static void cleanupLocalCheckpoints(File checkpointsDir, String checkpointToExclude) { String[] checkpoints = checkpointsDir.list(); for (String checkpoint : checkpoints) { if (checkpoint.equals(checkpointToExclude)) { continue; }/*from w w w . j av a 2 s . c o m*/ try { MoreFiles.deleteRecursively(Paths.get(checkpointsDir.getAbsolutePath(), checkpoint), RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException ioe) { log.warn("Failed to remove unused checkpoint {} from {}", checkpoint, checkpointsDir, ioe); } } }
From source file:org.apache.bookkeeper.statelib.impl.rocksdb.checkpoint.fs.FSCheckpointManager.java
@Override public void deleteRecursively(String srcPath) throws IOException { MoreFiles.deleteRecursively(Paths.get(getFullyQualifiedPath(srcPath).getAbsolutePath()), RecursiveDeleteOption.ALLOW_INSECURE); }
From source file:com.google.cloud.tools.managedcloudsdk.install.SdkInstaller.java
/** Download and install a new Cloud SDK. */ public Path install(final ProgressListener progressListener, final ConsoleListener consoleListener) throws IOException, InterruptedException, SdkInstallerException, CommandExecutionException, CommandExitException {/*from ww w . j ava 2 s .c o m*/ FileResourceProvider fileResourceProvider = fileResourceProviderFactory.newFileResourceProvider(); // Cleanup, remove old downloaded archive if exists if (Files.isRegularFile(fileResourceProvider.getArchiveDestination())) { logger.info("Removing stale archive: " + fileResourceProvider.getArchiveDestination()); Files.delete(fileResourceProvider.getArchiveDestination()); } // Cleanup, remove old SDK directory if exists if (Files.exists(fileResourceProvider.getArchiveExtractionDestination())) { logger.info("Removing stale install: " + fileResourceProvider.getArchiveExtractionDestination()); MoreFiles.deleteRecursively(fileResourceProvider.getArchiveExtractionDestination(), RecursiveDeleteOption.ALLOW_INSECURE); } progressListener.start("Installing Cloud SDK", installerFactory != null ? 300 : 200); // download and verify Downloader downloader = downloaderFactory.newDownloader(fileResourceProvider.getArchiveSource(), fileResourceProvider.getArchiveDestination(), progressListener.newChild(100)); downloader.download(); if (!Files.isRegularFile(fileResourceProvider.getArchiveDestination())) { throw new SdkInstallerException("Download succeeded but valid archive not found at " + fileResourceProvider.getArchiveDestination()); } try { // extract and verify extractorFactory .newExtractor(fileResourceProvider.getArchiveDestination(), fileResourceProvider.getArchiveExtractionDestination(), progressListener.newChild(100)) .extract(); if (!Files.isDirectory(fileResourceProvider.getExtractedSdkHome())) { throw new SdkInstallerException("Extraction succeeded but valid sdk home not found at " + fileResourceProvider.getExtractedSdkHome()); } } catch (UnknownArchiveTypeException e) { // fileResourceProviderFactory.newFileResourceProvider() creates a fileResourceProvider that // returns either .tar.gz or .zip for getArchiveDestination(). throw new RuntimeException(e); } // install if necessary if (installerFactory != null) { installerFactory.newInstaller(fileResourceProvider.getExtractedSdkHome(), progressListener.newChild(100), consoleListener).install(); } // verify final state if (!Files.isRegularFile(fileResourceProvider.getExtractedGcloud())) { throw new SdkInstallerException("Installation succeeded but gcloud executable not found at " + fileResourceProvider.getExtractedGcloud()); } progressListener.done(); return fileResourceProvider.getExtractedSdkHome(); }
From source file:com.otcdlink.chiron.testing.DirectoryFixture.java
public File getDirectory() throws IOException { if (null == scratchDirectory) { scratchDirectory = new File(getAllFixturesDirectory(), testIdentifier); if (scratchDirectory.exists()) { MoreFiles.deleteRecursively(scratchDirectory.toPath(), RecursiveDeleteOption.ALLOW_INSECURE); }//from ww w .j a v a 2 s . com if (scratchDirectory.mkdirs()) { // LOGGER.debug( "Created '", scratchDirectory.getAbsolutePath(), "'." ) ; } } return scratchDirectory; }
From source file:org.apache.bookkeeper.statelib.impl.rocksdb.checkpoint.RocksdbCheckpointTask.java
public String checkpoint(byte[] txid) throws StateStoreException { String checkpointId = UUID.randomUUID().toString(); File tempDir = new File(checkpointDir, checkpointId); log.info("Create a local checkpoint of state store {} at {}", dbName, tempDir); try {// w ww .j a v a 2 s. c om try { checkpoint.createCheckpoint(tempDir.getAbsolutePath()); } catch (RocksDBException e) { throw new StateStoreException("Failed to create a checkpoint at " + tempDir, e); } String remoteCheckpointPath = RocksUtils.getDestCheckpointPath(dbPrefix, checkpointId); if (!checkpointStore.fileExists(remoteCheckpointPath)) { checkpointStore.createDirectories(remoteCheckpointPath); } String sstsPath = RocksUtils.getDestSstsPath(dbPrefix); if (!checkpointStore.fileExists(sstsPath)) { checkpointStore.createDirectories(sstsPath); } // get the files to copy List<File> filesToCopy = getFilesToCopy(tempDir); // copy the files copyFilesToDest(checkpointId, filesToCopy); // finalize copy files finalizeCopyFiles(checkpointId, filesToCopy); // dump the file list to checkpoint file finalizeCheckpoint(checkpointId, tempDir, txid); // clean up the remote checkpoints if (removeRemoteCheckpointsAfterSuccessfulCheckpoint) { cleanupRemoteCheckpoints(tempDir, checkpointId); } return checkpointId; } catch (IOException ioe) { log.error("Failed to checkpoint db {} to dir {}", new Object[] { dbName, tempDir, ioe }); throw new StateStoreException("Failed to checkpoint db " + dbName + " to dir " + tempDir, ioe); } finally { if (removeLocalCheckpointAfterSuccessfulCheckpoint && tempDir.exists()) { try { MoreFiles.deleteRecursively(Paths.get(tempDir.getAbsolutePath()), RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException ioe) { log.warn("Failed to remove temporary checkpoint dir {}", tempDir, ioe); } } } }
From source file:io.github.m0pt0pmatt.survivalgames.command.executor.DemoCommand.java
private void unzipWorld() { File existing = new File(Sponge.getServer().getDefaultWorldName(), DEMO_MAP_WORLD_NAME); if (existing.exists()) { try {/* w ww .j a v a 2 s. co m*/ MoreFiles.deleteRecursively(existing.toPath(), RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException e) { throw new RuntimeException(e); } } new UnzipRunnable(DEMO_MAP_OBJECT, Sponge.getServer().getDefaultWorldName()).run(); }
From source file:org.apache.pulsar.functions.worker.FunctionActioner.java
public void stopFunction(FunctionRuntimeInfo functionRuntimeInfo) { Function.Instance instance = functionRuntimeInfo.getFunctionInstance(); FunctionMetaData functionMetaData = instance.getFunctionMetaData(); FunctionDetails details = functionMetaData.getFunctionDetails(); log.info("{}/{}/{}-{} Stopping function...", details.getTenant(), details.getNamespace(), details.getName(), instance.getInstanceId());//from ww w. ja va2s.co m if (functionRuntimeInfo.getRuntimeSpawner() != null) { functionRuntimeInfo.getRuntimeSpawner().close(); functionRuntimeInfo.setRuntimeSpawner(null); } // 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: {}", FunctionDetailsUtils.getFullyQualifiedName(functionMetaData.getFunctionDetails()), e); } } }