()
| 281 | } |
| 282 | |
| 283 | @Test |
| 284 | public void testDeleteDir() throws Exception { |
| 285 | Assume.assumeFalse(Os.isWindows()); |
| 286 | assertMemoryLeak(() -> { |
| 287 | File r = temporaryFolder.newFolder("to_delete"); |
| 288 | Assert.assertTrue(new File(r, "a" + Files.SEPARATOR + "b" + Files.SEPARATOR + "c" + Files.SEPARATOR + "d").mkdirs()); |
| 289 | Assert.assertTrue(new File(r, "d" + Files.SEPARATOR + "e" + Files.SEPARATOR + "f").mkdirs()); |
| 290 | touch(new File(r, "a" + Files.SEPARATOR + "1.txt")); |
| 291 | touch(new File(r, "a" + Files.SEPARATOR + "b" + Files.SEPARATOR + "2.txt")); |
| 292 | touch(new File(r, "a" + Files.SEPARATOR + "b" + Files.SEPARATOR + "c" + Files.SEPARATOR + "3.txt")); |
| 293 | touch(new File(r, "d" + Files.SEPARATOR + "1.txt")); |
| 294 | touch(new File(r, "d" + Files.SEPARATOR + "e" + Files.SEPARATOR + "2.txt")); |
| 295 | touch(new File(r, "d" + Files.SEPARATOR + "e" + Files.SEPARATOR + "f" + Files.SEPARATOR + "3.txt")); |
| 296 | |
| 297 | try ( |
| 298 | Path targetPath = new Path().of(r.getAbsolutePath()).concat("d"); |
| 299 | Path linkPath = new Path().of(r.getAbsolutePath()).concat("a").concat("link_to_d") |
| 300 | ) { |
| 301 | Assert.assertEquals(0, Files.softLink(targetPath.$(), linkPath.$())); |
| 302 | Assert.assertTrue(Files.isSoftLink(linkPath.$())); |
| 303 | |
| 304 | targetPath.of(r.getAbsolutePath()); |
| 305 | linkPath.of(r.getParentFile().getAbsolutePath()).concat("start_here"); |
| 306 | Assert.assertEquals(0, Files.softLink(targetPath.$(), linkPath.$())); |
| 307 | Assert.assertTrue(Files.isSoftLink(linkPath.$())); |
| 308 | |
| 309 | Assert.assertTrue(Files.rmdir(linkPath, true)); |
| 310 | Assert.assertFalse(new File(linkPath.toString()).exists()); |
| 311 | Assert.assertTrue(r.exists()); |
| 312 | Assert.assertEquals(0L, Files.getDirSize(targetPath)); |
| 313 | Assert.assertTrue(Files.rmdir(targetPath.slash(), true)); |
| 314 | Assert.assertFalse(r.exists()); |
| 315 | } |
| 316 | }); |
| 317 | } |
| 318 | |
| 319 | @Test |
| 320 | public void testDeleteOpenFile() throws Exception { |
nothing calls this directly
no test coverage detected