@Test public void testDeleteRecursivelyEmptyDir() throws Exception { File dir = Os.newTempDir(OsTest.class); DeletionResult result = Os.deleteRecursively(dir); assertTrue(result.wasSuccessful()); assertFalse(dir.exists()); }
/** * @see {@link #deleteRecursively(File)} */ @Beta public static DeletionResult deleteRecursively(String dir) { if (dir==null) return new DeletionResult(null, true, null); return deleteRecursively(new File(dir)); }
.backoffTo(Duration.millis(50)) .run(); if (deletionResult.get().getThrowable()!=null) { log.debug("Unable to delete "+osgiFrameworkCacheDir+" (possibly being modified concurrently?): "+deletionResult.get().getThrowable());
/** * as {@link #deleteRecursively(File)} but includes safety checks to prevent deletion of / or ~ * or anything else not passing {@link #checkSafe(File)}, unless the skipSafetyChecks parameter is set */ @Beta public static DeletionResult deleteRecursively(File dir, boolean skipSafetyChecks) { if (dir==null) return new DeletionResult(null, true, null); try { if (!skipSafetyChecks) checkSafe(dir); FileUtils.deleteDirectory(dir); return new DeletionResult(dir, true, null); } catch (IllegalArgumentException e) { // See exception reported in https://issues.apache.org/jira/browse/BROOKLYN-72 // If another thread is changing the contents of the directory at the same time as // we delete it, then can get this exception. return new DeletionResult(dir, false, e); } catch (IOException e) { return new DeletionResult(dir, false, e); } }
public <T> T asNullOrThrowing() { throwIfFailed(); return null; } }
@Override public Boolean call() { deletionResult.set(Os.deleteRecursively(osgiFrameworkCacheDir)); return deletionResult.get().wasSuccessful(); }}) .limitTimeTo(Duration.ONE_SECOND)
@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(); }
public static void deleteCompletely(File d) { DeletionResult result = Os.deleteRecursively(d); if (!result.wasSuccessful()) log.warn("Unable to delete persistence dir "+d); } }
@Test public void testDeleteRecursivelyNonExistantDir() throws Exception { DeletionResult result = Os.deleteRecursively(Os.mergePaths(Os.tmp(), Identifiers.makeRandomId(8))); assertTrue(result.wasSuccessful()); }
@Override @AfterMethod(alwaysRun=true) public void tearDown() throws Exception { super.tearDown(); dir = Os.deleteRecursively(dir).asNullOrThrowing(); } }
@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()); } }