2424/* @test
2525 @bug 4759207 4403166 4165006 4403166 6182812 6274272 7160013
2626 @summary Test to see if win32 path length can be greater than 260
27+ @library .. /test/lib
2728 */
2829
2930import java .io .*;
3031import java .nio .file .Files ;
3132import java .nio .file .Path ;
3233import java .nio .file .DirectoryNotEmptyException ;
34+ import jdk .test .lib .Platform ;
3335
3436public class MaxPathLength {
3537 private static String sep = File .separator ;
3638 private static String pathComponent = sep +
3739 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ;
3840 private static String fileName =
39- "areallylongfilenamethatsforsur" ;
40- private static boolean isWindows = false ;
41+ "areallylongfilenamethatsforsur" ;
4142
4243 private static final int MAX_LENGTH = 256 ;
4344
45+ private static final int FILE_EXISTS_SLEEP = 100 ;
46+
47+ private static final int MAX_PATH_COMPONENTS_WINDOWS = 20 ;
48+
4449 private static int counter = 0 ;
4550
4651 public static void main (String [] args ) throws Exception {
47- String osName = System .getProperty ("os.name" );
48- if (osName .startsWith ("Windows" )) {
49- isWindows = true ;
50- }
5152
5253 for (int i = 4 ; i < 7 ; i ++) {
5354 String name = fileName ;
@@ -59,8 +60,10 @@ public static void main(String[] args) throws Exception {
5960 }
6061
6162 // test long paths on windows
62- // And these long pathes cannot be handled on Solaris and Mac platforms
63- testLongPathOnWindows ();
63+ // And these long paths cannot be handled on Linux and Mac platforms
64+ if (Platform .isWindows ()) {
65+ testLongPath ();
66+ }
6467 }
6568
6669 private static String getNextName (String fName ) {
@@ -139,7 +142,7 @@ static void testLongPath(int max, String fn,
139142 if (flist == null || !fn .equals (flist [0 ].getName ()))
140143 throw new RuntimeException ("File.listFiles() failed" );
141144
142- if (isWindows &&
145+ if (Platform . isWindows () &&
143146 !fu .getCanonicalPath ().equals (f .getCanonicalPath ()))
144147 throw new RuntimeException ("getCanonicalPath() failed" );
145148
@@ -155,7 +158,7 @@ static void testLongPath(int max, String fn,
155158 String abPath = f .getAbsolutePath ();
156159 if (!abPath .startsWith ("\\ \\ " ) ||
157160 abPath .length () < 1093 ) {
158- throw new RuntimeException ("File.renameTo() failed for lenth ="
161+ throw new RuntimeException ("File.renameTo() failed for length ="
159162 + abPath .length ());
160163 }
161164 } else {
@@ -182,7 +185,7 @@ static void testLongPath(int max, String fn,
182185 Files .deleteIfExists (p );
183186 // Test if the file is really deleted and wait for 1 second at most
184187 for (int j = 0 ; j < 10 && Files .exists (p ); j ++) {
185- Thread .sleep (100 );
188+ Thread .sleep (FILE_EXISTS_SLEEP );
186189 }
187190 } catch (DirectoryNotEmptyException ex ) {
188191 // Give up the clean-up, let jtreg handle it.
@@ -193,14 +196,12 @@ static void testLongPath(int max, String fn,
193196 }
194197 }
195198
196- private static void testLongPathOnWindows () throws Exception {
197- if (isWindows ) {
198- String name = fileName ;
199- while (name .length () < MAX_LENGTH ) {
200- testLongPath (20 , name , false );
201- testLongPath (20 , name , true );
202- name = getNextName (name );
203- }
199+ private static void testLongPath () throws Exception {
200+ String name = fileName ;
201+ while (name .length () < MAX_LENGTH ) {
202+ testLongPath (MAX_PATH_COMPONENTS_WINDOWS , name , false );
203+ testLongPath (MAX_PATH_COMPONENTS_WINDOWS , name , true );
204+ name = getNextName (name );
204205 }
205206 }
206- }
207+ }
0 commit comments