Skip to content

8363720: Follow up to JDK-8360411 with post review comments #26445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 21 additions & 20 deletions test/jdk/java/io/File/MaxPathLength.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,31 @@
/* @test
@bug 4759207 4403166 4165006 4403166 6182812 6274272 7160013
@summary Test to see if win32 path length can be greater than 260
@library .. /test/lib
*/

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.DirectoryNotEmptyException;
import jdk.test.lib.Platform;

public class MaxPathLength {
private static String sep = File.separator;
private static String pathComponent = sep +
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
private static String fileName =
"areallylongfilenamethatsforsur";
private static boolean isWindows = false;
"areallylongfilenamethatsforsur";

private static final int MAX_LENGTH = 256;

private static final int FILE_EXISTS_SLEEP = 100;

private static final int MAX_PATH_COMPONENTS_WINDOWS = 20;

private static int counter = 0;

public static void main(String[] args) throws Exception {
String osName = System.getProperty("os.name");
if (osName.startsWith("Windows")) {
isWindows = true;
}

for (int i = 4; i < 7; i++) {
String name = fileName;
Expand All @@ -59,8 +60,10 @@ public static void main(String[] args) throws Exception {
}

// test long paths on windows
// And these long pathes cannot be handled on Solaris and Mac platforms
testLongPathOnWindows();
// And these long paths cannot be handled on Linux and Mac platforms
if (Platform.isWindows()) {
testLongPath();
}
}

private static String getNextName(String fName) {
Expand Down Expand Up @@ -139,7 +142,7 @@ static void testLongPath(int max, String fn,
if (flist == null || !fn.equals(flist[0].getName()))
throw new RuntimeException ("File.listFiles() failed");

if (isWindows &&
if (Platform.isWindows() &&
!fu.getCanonicalPath().equals(f.getCanonicalPath()))
throw new RuntimeException ("getCanonicalPath() failed");

Expand All @@ -155,7 +158,7 @@ static void testLongPath(int max, String fn,
String abPath = f.getAbsolutePath();
if (!abPath.startsWith("\\\\") ||
abPath.length() < 1093) {
throw new RuntimeException ("File.renameTo() failed for lenth="
throw new RuntimeException ("File.renameTo() failed for length="
+ abPath.length());
}
} else {
Expand All @@ -182,7 +185,7 @@ static void testLongPath(int max, String fn,
Files.deleteIfExists(p);
// Test if the file is really deleted and wait for 1 second at most
for (int j = 0; j < 10 && Files.exists(p); j++) {
Thread.sleep(100);
Thread.sleep(FILE_EXISTS_SLEEP);
}
} catch (DirectoryNotEmptyException ex) {
// Give up the clean-up, let jtreg handle it.
Expand All @@ -193,14 +196,12 @@ static void testLongPath(int max, String fn,
}
}

private static void testLongPathOnWindows () throws Exception {
if (isWindows) {
String name = fileName;
while (name.length() < MAX_LENGTH) {
testLongPath (20, name, false);
testLongPath (20, name, true);
name = getNextName(name);
}
private static void testLongPath () throws Exception {
String name = fileName;
while (name.length() < MAX_LENGTH) {
testLongPath(MAX_PATH_COMPONENTS_WINDOWS, name, false);
testLongPath(MAX_PATH_COMPONENTS_WINDOWS, name, true);
name = getNextName(name);
}
}
}
}