/** * Tests if fullyDelete deletes (a) dangling symlink to file properly (b) dangling symlink to * directory properly * * @throws IOException */ @Test(timeout = 30000) public void testFullyDeleteDanglingSymlinks() throws IOException { setupDirs(); // delete the directory tmp to make tmpDir a dangling link to dir tmp and // to make y as a dangling link to file tmp/x boolean ret = FileUtil.fullyDelete(tmp); Assert.assertTrue(ret); Assert.assertFalse(tmp.exists()); // dangling symlink to file File link = new File(del, LINK); Assert.assertEquals(5, del.list().length); // Even though 'y' is dangling symlink to file tmp/x, fullyDelete(y) // should delete 'y' properly. ret = FileUtil.fullyDelete(link); Assert.assertTrue(ret); Assert.assertEquals(4, del.list().length); // dangling symlink to directory File linkDir = new File(del, "tmpDir"); // Even though tmpDir is dangling symlink to tmp, fullyDelete(tmpDir) should // delete tmpDir properly. ret = FileUtil.fullyDelete(linkDir); Assert.assertTrue(ret); Assert.assertEquals(3, del.list().length); }
private void cleanupImpl() throws IOException { FileUtil.fullyDelete(del, true); Assert.assertTrue(!del.exists()); FileUtil.fullyDelete(tmp, true); Assert.assertTrue(!tmp.exists()); FileUtil.fullyDelete(partitioned, true); Assert.assertTrue(!partitioned.exists()); }
private void doUntarAndVerify(File tarFile, File untarDir) throws IOException { if (untarDir.exists() && !FileUtil.fullyDelete(untarDir)) { throw new IOException("Could not delete directory '" + untarDir + "'"); } FileUtil.unTar(tarFile, untarDir); String parentDir = untarDir.getCanonicalPath() + Path.SEPARATOR + "name"; File testFile = new File(parentDir + Path.SEPARATOR + "version"); Assert.assertTrue(testFile.exists()); Assert.assertTrue(testFile.length() == 0); String imageDir = parentDir + Path.SEPARATOR + "image"; testFile = new File(imageDir + Path.SEPARATOR + "fsimage"); Assert.assertTrue(testFile.exists()); Assert.assertTrue(testFile.length() == 157); String currentDir = parentDir + Path.SEPARATOR + "current"; testFile = new File(currentDir + Path.SEPARATOR + "fsimage"); Assert.assertTrue(testFile.exists()); Assert.assertTrue(testFile.length() == 4331); testFile = new File(currentDir + Path.SEPARATOR + "edits"); Assert.assertTrue(testFile.exists()); Assert.assertTrue(testFile.length() == 1033); testFile = new File(currentDir + Path.SEPARATOR + "fstime"); Assert.assertTrue(testFile.exists()); Assert.assertTrue(testFile.length() == 8); }
@Test(timeout = 30000) public void testFailFullyDeleteGrantPermissions() throws IOException { setupDirsAndNonWritablePermissions(); boolean ret = FileUtil.fullyDelete(new MyFile(del), true); // this time the directories with revoked permissions *should* be deleted: validateAndSetWritablePermissions(false, ret); }
@Test(timeout = 30000) public void testFullyDelete() throws IOException { setupDirs(); boolean ret = FileUtil.fullyDelete(del); Assert.assertTrue(ret); Assert.assertFalse(del.exists()); validateTmpDir(); }
@Test(timeout = 30000) public void testFailFullyDelete() throws IOException { if (Shell.WINDOWS) { // windows Dir.setWritable(false) does not work for directories return; } LOG.info("Running test to verify failure of fullyDelete()"); setupDirsAndNonWritablePermissions(); boolean ret = FileUtil.fullyDelete(new MyFile(del)); validateAndSetWritablePermissions(true, ret); }
/** * Tests if fullyDelete deletes (a) symlink to file only and not the file pointed to by symlink. * (b) symlink to dir only and not the dir pointed to by symlink. * * @throws IOException */ @Test(timeout = 30000) public void testFullyDeleteSymlinks() throws IOException { setupDirs(); File link = new File(del, LINK); Assert.assertEquals(5, del.list().length); // Since tmpDir is symlink to tmp, fullyDelete(tmpDir) should not // delete contents of tmp. See setupDirs for details. boolean ret = FileUtil.fullyDelete(link); Assert.assertTrue(ret); Assert.assertFalse(link.exists()); Assert.assertEquals(4, del.list().length); validateTmpDir(); File linkDir = new File(del, "tmpDir"); // Since tmpDir is symlink to tmp, fullyDelete(tmpDir) should not // delete contents of tmp. See setupDirs for details. ret = FileUtil.fullyDelete(linkDir); Assert.assertTrue(ret); Assert.assertFalse(linkDir.exists()); Assert.assertEquals(3, del.list().length); validateTmpDir(); }