8315273: (fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link (win)
Reviewed-by: djelinski
This commit is contained in:
parent
b39e6a84ef
commit
f87701635f
src/java.base/share/classes/java/nio/file
test/jdk
@ -803,8 +803,8 @@ public interface Path
|
||||
* "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then
|
||||
* an implementation will typically cause both names to be removed. When
|
||||
* not resolving symbolic links and the preceding name is a symbolic link
|
||||
* then the names are only removed if it guaranteed that the resulting path
|
||||
* will locate the same file as this path.
|
||||
* then the names are only removed if it is guaranteed that the resulting
|
||||
* path will locate the same file as this path.
|
||||
*
|
||||
* @param options
|
||||
* options indicating how symbolic links are handled
|
||||
|
@ -569,8 +569,6 @@ java/nio/channels/DatagramChannel/AfterDisconnect.java 8308807 aix-ppc6
|
||||
java/nio/channels/DatagramChannel/ManySourcesAndTargets.java 8264385 macosx-aarch64
|
||||
java/nio/channels/DatagramChannel/Unref.java 8233437 generic-all
|
||||
|
||||
java/nio/file/Path/ToRealPath.java 8315273 windows-all
|
||||
|
||||
############################################################################
|
||||
|
||||
# jdk_rmi
|
||||
|
@ -33,6 +33,8 @@ import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jdk.test.lib.Platform;
|
||||
|
||||
@ -51,6 +53,7 @@ public class ToRealPath {
|
||||
static final Path SUBDIR;
|
||||
static final Path FILE;
|
||||
static final Path LINK;
|
||||
static final Set<Path> extraDeletions;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -59,6 +62,7 @@ public class ToRealPath {
|
||||
FILE = Files.createFile(DIR.resolve("foo"));
|
||||
LINK = DIR.resolve("link");
|
||||
SUPPORTS_LINKS = TestUtil.supportsSymbolicLinks(DIR);
|
||||
extraDeletions = new HashSet<Path>();
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
@ -154,8 +158,15 @@ public class ToRealPath {
|
||||
System.out.println("p: " + p);
|
||||
Path path = LINK.resolve(p);
|
||||
System.out.println("path: " + path);
|
||||
if (Platform.isWindows() && Files.notExists(path)) {
|
||||
Files.createFile(path);
|
||||
extraDeletions.add(path);
|
||||
}
|
||||
System.out.println("no follow: " + path.toRealPath(NOFOLLOW_LINKS));
|
||||
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
|
||||
if (Platform.isWindows())
|
||||
assertTrue(Files.isSameFile(path.toRealPath(NOFOLLOW_LINKS), path));
|
||||
else
|
||||
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
|
||||
|
||||
Files.delete(sub);
|
||||
Files.delete(sub.getParent());
|
||||
@ -177,8 +188,15 @@ public class ToRealPath {
|
||||
Path p = Path.of("aaa", "..", "..", "bbb", "..", "..", "out.txt");
|
||||
Path path = DIR.resolve(p);
|
||||
System.out.println("path: " + path);
|
||||
if (Platform.isWindows() && Files.notExists(path)) {
|
||||
Files.createFile(path);
|
||||
extraDeletions.add(path);
|
||||
}
|
||||
System.out.println("no follow: " + path.toRealPath(NOFOLLOW_LINKS));
|
||||
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
|
||||
if (Platform.isWindows())
|
||||
assertTrue(Files.isSameFile(path.toRealPath(NOFOLLOW_LINKS), path));
|
||||
else
|
||||
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
|
||||
System.out.println(path.toRealPath());
|
||||
|
||||
Files.delete(sub);
|
||||
@ -235,5 +253,7 @@ public class ToRealPath {
|
||||
Files.delete(FILE);
|
||||
Files.delete(SUBDIR);
|
||||
Files.delete(DIR);
|
||||
for (Path p : extraDeletions)
|
||||
Files.deleteIfExists(p);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user