/** tries to delete a directory recursively; * use with care - see http://stackoverflow.com/questions/8320376/why-is-files-deletedirectorycontents-deprecated-in-guava. * <p> * also note this implementation refuses to delete / or ~ or anything else not passing {@link #checkSafe(File)}. * if you might really want to delete something like that, use {@link #deleteRecursively(File, boolean)}. */ @Beta public static DeletionResult deleteRecursively(File dir) { return deleteRecursively(dir, false); }
public void run() throws IOException { if (path.exists()) { if (recursively && path.isDirectory()) { Os.deleteRecursively(path); } else { path.delete(); } } } }
public static void deleteCompletely(File d) { DeletionResult result = Os.deleteRecursively(d); if (!result.wasSuccessful()) log.warn("Unable to delete persistence dir "+d); } }
@Override public Boolean call() { deletionResult.set(Os.deleteRecursively(osgiFrameworkCacheDir)); return deletionResult.get().wasSuccessful(); }}) .limitTimeTo(Duration.ONE_SECOND)
@AfterMethod(alwaysRun = true) public void tearDown() throws Exception { try { super.tearDown(); } finally { Os.deleteRecursively(sourceFileDir); Os.deleteRecursively(sourceTemplateDir); Os.deleteRecursively(installDir); Os.deleteRecursively(runDir); } } }
public static File getOsgiCacheDirCleanedIfNeeded(ManagementContext mgmt) { File cacheDirF = getOsgiCacheDir(mgmt); boolean clean = isOsgiCacheForCleaning(mgmt, cacheDirF); log.debug("OSGi cache dir computed as "+cacheDirF.getAbsolutePath()+" ("+ (cacheDirF.exists() ? "already exists" : "does not exist")+", "+ (clean ? "cleaning now (and on exit)" : "cleaning not requested")); if (clean) { Os.deleteRecursively(cacheDirF); Os.deleteOnExitRecursively(cacheDirF); } return cacheDirF; }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (file != null) file.delete(); if (dir != null) Os.deleteRecursively(dir); }
@AfterMethod(alwaysRun=true) @Override public void tearDown() throws Exception { super.tearDown(); if (destDir != null) Os.deleteRecursively(destDir); }
@AfterMethod(alwaysRun=true) @Override public void tearDown() throws Exception { try { super.tearDown(); } finally { if (pseudoBrooklynPropertiesFile != null) pseudoBrooklynPropertiesFile.delete(); if (pseudoBrooklynCatalogFile != null) pseudoBrooklynCatalogFile.delete(); if (brooklynCatalogSourceFile != null) brooklynCatalogSourceFile.delete(); if (persistenceDir != null) Os.deleteRecursively(persistenceDir); } }
@Test(groups="Integration") public void testMoveDir() throws Exception { File destParent = Files.createTempDir(); try { Files.write("abc", new File(dir, "afile"), Charsets.UTF_8); File destDir = new File(destParent, "dest"); FileUtil.moveDir(dir, destDir); assertEquals(Files.readLines(new File(destDir, "afile"), Charsets.UTF_8), ImmutableList.of("abc")); assertFalse(dir.exists()); } finally { if (destParent != null) Os.deleteRecursively(destParent); } }
@AfterMethod(alwaysRun=true) @Override public void tearDown() throws Exception { try { super.tearDown(); } finally { if (tempDataDir != null) Os.deleteRecursively(tempDataDir); } }
@Test public void testDeleteRecursivelySubDirs() throws Exception { File dir = Os.newTempDir(OsTest.class); File subdir = new File(dir, "mysubdir"); File subfile = new File(subdir, "mysubfile"); subdir.mkdirs(); Files.write("abc".getBytes(), subfile); DeletionResult result = Os.deleteRecursively(dir); assertTrue(result.wasSuccessful()); assertFalse(dir.exists()); } }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (store != null) store.close(); if (parentdir != null) Os.deleteRecursively(basedir); if (mgmt != null) Entities.destroyAll(mgmt); }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { super.tearDown(); dir = Os.deleteRecursively(dir).asNullOrThrowing(); } }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { super.tearDown(); mementoDir = Os.deleteRecursively(mementoDir).asNullOrThrowing(); }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (mgmt != null) Entities.destroyAll(mgmt); mgmt = null; tempDir = Os.deleteRecursively(tempDir).asNullOrThrowing(); checkExpectedFailure(); }
@AfterMethod(alwaysRun=true) public void tearDown() throws Exception { if (mgmt != null) Entities.destroyAll(mgmt); mgmt = null; tempDir = Os.deleteRecursively(tempDir).asNullOrThrowing(); checkExpectedFailure(); }
@Test public void testDeleteRecursivelyNonExistantDir() throws Exception { DeletionResult result = Os.deleteRecursively(Os.mergePaths(Os.tmp(), Identifiers.makeRandomId(8))); assertTrue(result.wasSuccessful()); }
@Test(groups = "Integration") public void testStartsInDifferentRunAndInstallSpecifiedDirectories() throws Exception { String dir1 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); String dir2 = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); app.config().set(BrooklynConfigKeys.INSTALL_DIR, dir1); app.config().set(BrooklynConfigKeys.RUN_DIR, dir2); doTestSpecifiedDirectory(dir1, dir2); Os.deleteRecursively(dir1); Os.deleteRecursively(dir2); }
@Test(groups = "Integration") public void testStartsInMgmtSpecifiedDirectory() throws Exception { String dir = Os.mergePathsUnix(Os.tmp(), "/brooklyn-test-"+Strings.makeRandomId(4)); tearDown(); mgmt = new LocalManagementContextForTests(); mgmt.getBrooklynProperties().put(BrooklynConfigKeys.ONBOX_BASE_DIR, dir); setUp(); doTestSpecifiedDirectory(dir, dir); Os.deleteRecursively(dir); }