List of usage examples for com.google.common.io RecursiveDeleteOption ALLOW_INSECURE
RecursiveDeleteOption ALLOW_INSECURE
To view the source code for com.google.common.io RecursiveDeleteOption ALLOW_INSECURE.
Click Source Link
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 .ja v a 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 {/*w w w.jav a 2 s . co 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; }//w w w .ja va 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 {// www . java 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:neon.common.files.FileUtils.java
/** * Clears all content from the given folder. * //from ww w . j ava 2 s.co m * @param folder */ public static void clearFolder(Path folder) { logger.info("clearing folder " + folder); try { MoreFiles.deleteDirectoryContents(folder, RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException e) { throw new IllegalArgumentException("can't clear folder " + folder, e); } }
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); }/*w w w . j a v a 2s .c om*/ 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 {/*from w w w .j a va 2s .c o m*/ 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 {// ww w . j a v a 2 s .com MoreFiles.deleteRecursively(existing.toPath(), RecursiveDeleteOption.ALLOW_INSECURE); } catch (IOException e) { throw new RuntimeException(e); } } new UnzipRunnable(DEMO_MAP_OBJECT, Sponge.getServer().getDefaultWorldName()).run(); }