/** *Test:toRealPath()shouldresolvelinks
*/ if (supportsLinks) {
Path resolvedFile = file; if (Platform.isWindows()) { // Path::toRealPath does not work with environments using the // legacy subst mechanism. This is a workaround to keep the // test working if 'dir' points to a location on a subst drive. // See JDK-8213216. //
Path tempLink = dir.resolve("tempLink");
Files.createSymbolicLink(tempLink, dir.toAbsolutePath());
Path resolvedDir = tempLink.toRealPath();
Files.delete(tempLink);
resolvedFile = resolvedDir.resolve(file.getFileName());
}
// Real path should retain case as dir/theLink/theTarget
assertTrue(noFollow.getName(nc - 2).equals(Path.of("theLink")));
assertTrue(noFollow.getName(nc - 1).equals(Path.of("theTarget")));
assertTrue(noFollow.toString().equals(
Path.of(dir.toString(), "theLink", "theTarget").toString()));
// Test where a link is preceded by ".." in the path
Path superBeforeLink =
Path.of(subdir.toString(), "..", "thelink", "thetarget");
noFollow = superBeforeLink.toRealPath(NOFOLLOW_LINKS);
nc = noFollow.getNameCount();
assertTrue(noFollow.getName(nc - 2).equals(Path.of("theLink")));
assertTrue(noFollow.getName(nc - 1).equals(Path.of("theTarget")));
// Test where a link is followed by ".." in the path
Path linkBeforeSuper =
Path.of(dir.toString(), "thelink", "..", "subdir", "thetarget");
noFollow = linkBeforeSuper.toRealPath(NOFOLLOW_LINKS);
nc = noFollow.getNameCount();
assertTrue(noFollow.getName(nc - 4).equals(Path.of("theLink")));
assertTrue(noFollow.getName(nc - 1).equals(Path.of("theTarget")));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.