Existence check for the target of a symbolic link gives wrong result.
Reproduction:
Create a file on in-memory filesystem.
Create a symbolic link to that file.
Check existence of file by following links via Files.exists
Expected behavior:
Files.exists(symLink) should return true.
Actual behavior:Files.exists(symLink) returns false.
However, Files.exists(Files.readSymbolicLink(symLink)) returns true.
Unit test:
@Test
public void testFileExistenceWithFollowingLinks() throws IOException {
FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build();
Path realFile = Files.writeString(fileSystem.getPath("realFile"), "Test");
Path symLink = Files.createSymbolicLink(fileSystem.getPath("symLink"), realFile);
Assert.assertTrue("Real file should exist", Files.exists(realFile));
Assert.assertTrue("Symlink file should exist without following links", Files.exists(symLink, LinkOption.NOFOLLOW_LINKS));
Assert.assertTrue("Target of symlink file should exist", Files.exists(Files.readSymbolicLink(symLink)));
Assert.assertEquals("Target of symlink file should be real file", realFile, Files.readSymbolicLink(symLink));
// The following assertion fails:
Assert.assertTrue("Symlink file target should exist when following links", Files.exists(symLink));
}
Existence check for the target of a symbolic link gives wrong result.
Reproduction:
Files.exists
Expected behavior:
Files.exists(symLink)
should return true.Actual behavior:
Files.exists(symLink)
returns false. However,Files.exists(Files.readSymbolicLink(symLink))
returns true.Unit test: