提交 d7ef52e1 编写于 作者: J Jesse Glick

Merge pull request #595 from onemanbucket/jenkins-15418

[FIXED JENKINS-15418] Allow long paths on windows.
......@@ -58,7 +58,22 @@ public class Kernel32Utils {
}
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 class FilePathTest extends ChannelTestCase {
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);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册