()
| 1382 | } |
| 1383 | |
| 1384 | @Test |
| 1385 | public void testUnlink() throws Exception { |
| 1386 | Assume.assumeTrue(Os.type != Os.WINDOWS); |
| 1387 | assertMemoryLeak(() -> { |
| 1388 | File tmpFolder = temporaryFolder.newFolder("unlink"); |
| 1389 | final String fileName = "いくつかの列.d"; |
| 1390 | final String fileContent = "**unlink** deletes a name from the filesystem." + EOL + |
| 1391 | "If the name IS a symbolic link, the link is removed." + EOL + |
| 1392 | "If the name is the last link to the file, and no processes have" + EOL + |
| 1393 | "the file open, the file is deleted and the space it was using is " + EOL + |
| 1394 | "made available for reuse. Otherwise, if any process maintains the" + EOL + |
| 1395 | "file open, it will remain in existence until the last file descriptor" + EOL + |
| 1396 | "referring to it is closed." + EOL; |
| 1397 | |
| 1398 | try ( |
| 1399 | Path srcPath = new Path().of(tmpFolder.getAbsolutePath()); |
| 1400 | Path coldRoot = new Path().of(srcPath).concat("S3").slash(); // does not exist yet |
| 1401 | Path linkPath = new Path().of(coldRoot).concat(fileName).put(TableUtils.ATTACHABLE_DIR_MARKER) |
| 1402 | ) { |
| 1403 | createTempFile(srcPath, fileName, fileContent); // updates srcFilePath |
| 1404 | |
| 1405 | // create the soft link |
| 1406 | createSoftLink(coldRoot, srcPath, linkPath); |
| 1407 | |
| 1408 | // check contents are the same |
| 1409 | assertEqualsFileContent(linkPath, fileContent); |
| 1410 | |
| 1411 | // unlink soft link |
| 1412 | Assert.assertEquals(0, Files.unlink(linkPath.$())); |
| 1413 | |
| 1414 | // check original file still exists and contents are the same |
| 1415 | assertEqualsFileContent(srcPath, fileContent); |
| 1416 | |
| 1417 | // however the link no longer exists |
| 1418 | File link = new File(linkPath.toString()); |
| 1419 | Assert.assertFalse(link.exists()); |
| 1420 | Assert.assertFalse(link.canRead()); |
| 1421 | Assert.assertEquals(-1, Files.openRO(linkPath.$())); |
| 1422 | } |
| 1423 | }); |
| 1424 | } |
| 1425 | |
| 1426 | @Test |
| 1427 | public void testWriteFails() throws Exception { |
nothing calls this directly
no test coverage detected