Skip to content

Commit f877016

Browse files
author
Brian Burkhalter
committed
8315273: (fs) Path.toRealPath(LinkOption.NOFOLLOW_LINKS) fails when "../../" follows a link (win)
Reviewed-by: djelinski
1 parent b39e6a8 commit f877016

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/java.base/share/classes/java/nio/file/Path.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,8 @@ default Path resolveSibling(String other) {
803803
* "{@code ..}" (or equivalent) is preceded by a non-"{@code ..}" name then
804804
* an implementation will typically cause both names to be removed. When
805805
* not resolving symbolic links and the preceding name is a symbolic link
806-
* then the names are only removed if it guaranteed that the resulting path
807-
* will locate the same file as this path.
806+
* then the names are only removed if it is guaranteed that the resulting
807+
* path will locate the same file as this path.
808808
*
809809
* @param options
810810
* options indicating how symbolic links are handled

test/jdk/ProblemList.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,6 @@ java/nio/channels/DatagramChannel/AfterDisconnect.java 8308807 aix-ppc6
569569
java/nio/channels/DatagramChannel/ManySourcesAndTargets.java 8264385 macosx-aarch64
570570
java/nio/channels/DatagramChannel/Unref.java 8233437 generic-all
571571

572-
java/nio/file/Path/ToRealPath.java 8315273 windows-all
573-
574572
############################################################################
575573

576574
# jdk_rmi

test/jdk/java/nio/file/Path/ToRealPath.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.io.UncheckedIOException;
3434
import java.nio.file.Files;
3535
import java.nio.file.Path;
36+
import java.util.HashSet;
37+
import java.util.Set;
3638

3739
import jdk.test.lib.Platform;
3840

@@ -51,6 +53,7 @@ public class ToRealPath {
5153
static final Path SUBDIR;
5254
static final Path FILE;
5355
static final Path LINK;
56+
static final Set<Path> extraDeletions;
5457

5558
static {
5659
try {
@@ -59,6 +62,7 @@ public class ToRealPath {
5962
FILE = Files.createFile(DIR.resolve("foo"));
6063
LINK = DIR.resolve("link");
6164
SUPPORTS_LINKS = TestUtil.supportsSymbolicLinks(DIR);
65+
extraDeletions = new HashSet<Path>();
6266
} catch (IOException e) {
6367
throw new UncheckedIOException(e);
6468
}
@@ -154,8 +158,15 @@ public void noCollapseDots1() throws IOException {
154158
System.out.println("p: " + p);
155159
Path path = LINK.resolve(p);
156160
System.out.println("path: " + path);
161+
if (Platform.isWindows() && Files.notExists(path)) {
162+
Files.createFile(path);
163+
extraDeletions.add(path);
164+
}
157165
System.out.println("no follow: " + path.toRealPath(NOFOLLOW_LINKS));
158-
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
166+
if (Platform.isWindows())
167+
assertTrue(Files.isSameFile(path.toRealPath(NOFOLLOW_LINKS), path));
168+
else
169+
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
159170

160171
Files.delete(sub);
161172
Files.delete(sub.getParent());
@@ -177,8 +188,15 @@ public void noCollapseDots2() throws IOException {
177188
Path p = Path.of("aaa", "..", "..", "bbb", "..", "..", "out.txt");
178189
Path path = DIR.resolve(p);
179190
System.out.println("path: " + path);
191+
if (Platform.isWindows() && Files.notExists(path)) {
192+
Files.createFile(path);
193+
extraDeletions.add(path);
194+
}
180195
System.out.println("no follow: " + path.toRealPath(NOFOLLOW_LINKS));
181-
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
196+
if (Platform.isWindows())
197+
assertTrue(Files.isSameFile(path.toRealPath(NOFOLLOW_LINKS), path));
198+
else
199+
assertEquals(path.toRealPath(NOFOLLOW_LINKS), path);
182200
System.out.println(path.toRealPath());
183201

184202
Files.delete(sub);
@@ -235,5 +253,7 @@ public static void cleanup() throws IOException {
235253
Files.delete(FILE);
236254
Files.delete(SUBDIR);
237255
Files.delete(DIR);
256+
for (Path p : extraDeletions)
257+
Files.deleteIfExists(p);
238258
}
239259
}

0 commit comments

Comments
 (0)