60
60
public static int getWin32FileAttributes(File file) throws IOException {
61
return Kernel32.INSTANCE.GetFileAttributesW(new WString(file.getCanonicalPath()));
61
// allow lookup of paths longer than MAX_PATH
62
// http://msdn.microsoft.com/en-us/library/aa365247(v=VS.85).aspx
63
String canonicalPath = file.getCanonicalPath();
65
if(canonicalPath.length() < 260) {
66
// path is short, use as-is
68
} else if(canonicalPath.startsWith("\\\\")) {
70
// \\server\share --> \\?\UNC\server\share
71
path = "\\\\?\\UNC\\" + canonicalPath.substring(2);
73
// prefix, canonical path should be normalized and absolute so this should work.
74
path = "\\\\?\\" + canonicalPath;
76
return Kernel32.INSTANCE.GetFileAttributesW(new WString(path));
81
* If relative, resolved against the location of the symlink.
82
* If absolute, it's absolute.
83
* @throws UnsatisfiedLinkError
84
* If the function is not exported by kernel32.
85
* See http://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx
86
* for compatibility info.
88
public static void createSymbolicLink(File symlink, String target, boolean dirLink) throws IOException {
89
if (!Kernel32.INSTANCE.CreateSymbolicLinkW(
90
new WString(symlink.getPath()), new WString(target),
91
dirLink?Kernel32.SYMBOLIC_LINK_FLAG_DIRECTORY:0)) {
92
throw new WinIOException("Failed to create a symlink "+symlink+" to "+target);
64
96
public static boolean isJunctionOrSymlink(File file) throws IOException {
65
return (file.exists() && (Kernel32.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
97
return (file.exists() && (Kernel32.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
68
100
/*package*/ static Kernel32 load() {