Skip to content
Permalink
Browse files

Merge pull request #595 from onemanbucket/jenkins-15418

[FIXED JENKINS-15418] Allow long paths on windows.
  • Loading branch information
jglick committed Oct 25, 2012
2 parents edbe2ae + f66e19c commit d7ef52e1bf68c3e7ca0a82596be89650625c1099
Showing with 44 additions and 2 deletions.
  1. +16 −1 core/src/main/java/hudson/util/jna/Kernel32Utils.java
  2. +28 −1 core/src/test/java/hudson/FilePathTest.java
@@ -58,7 +58,22 @@ public static int waitForExitProcess(Pointer hProcess) throws InterruptedExcepti
}

public static int getWin32FileAttributes(File file) throws IOException {
return Kernel32.INSTANCE.GetFileAttributesW(new WString(file.getCanonicalPath()));
// allow lookup of paths longer than MAX_PATH
// http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx
String canonicalPath = file.getCanonicalPath();
String path = null;
if(canonicalPath.length() < 260) {
// path is short, use as-is
path = canonicalPath;
} else if(canonicalPath.startsWith("\\\\")) {
// network share
// \\server\share --> \\?\UNC\server\share
path = "\\\\?\\UNC\\" + canonicalPath.substring(2);
} else {
// prefix, canonical path should be normalized and absolute so this should work.
path = "\\\\?\\" + canonicalPath;
}
return Kernel32.INSTANCE.GetFileAttributesW(new WString(path));
}

public static boolean isJunctionOrSymlink(File file) throws IOException {
@@ -474,5 +474,32 @@ public void testValidateAntFileMaskBounded() throws Exception {
Util.deleteRecursive(tmp);
}
}


@Bug(15418)
public void testDeleteLongPathOnWindows() throws Exception {
File tmp = Util.createTempDir();
try {
FilePath d = new FilePath(french, tmp.getPath());

// construct a very long path
StringBuilder sb = new StringBuilder();
while(sb.length() + tmp.getPath().length() < 260 - "very/".length()) {
sb.append("very/");
}
sb.append("pivot/very/very/long/path");

FilePath longPath = d.child(sb.toString());
longPath.mkdirs();
FilePath childInLongPath = longPath.child("file.txt");
childInLongPath.touch(0);

File firstDirectory = new File(tmp.getAbsolutePath() + "/very");
Util.deleteRecursive(firstDirectory);

assertFalse("Could not delete directory!", firstDirectory.exists());

} finally {
Util.deleteRecursive(tmp);
}
}
}

0 comments on commit d7ef52e

Please sign in to comment.
You can’t perform that action at this time.