提交 a9a01991 编写于 作者: A Andrew Stucki 提交者: photoionized

Fix Windows symlink detection

上级 468c5210
......@@ -68,6 +68,8 @@ import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import hudson.util.jna.Kernel32Utils;
import static hudson.util.jna.GNUCLibrary.LIBC;
/**
......@@ -308,6 +310,9 @@ public class Util {
*/
//Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup
public static boolean isSymlink(File file) throws IOException {
if (Functions.isWindows()) {
return Kernel32Utils.isJunctionOrSymlink(file);
}
String name = file.getName();
if (name.equals(".") || name.equals(".."))
return false;
......
......@@ -26,6 +26,7 @@ package hudson.util.jna;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.WString;
import com.sun.jna.Native;
/**
......@@ -47,8 +48,11 @@ public interface Kernel32 extends StdCallLibrary {
int MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
int MOVEFILE_REPLACE_EXISTING = 1;
int MOVEFILE_WRITE_THROUGH = 8;
int FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
int WaitForSingleObject(Pointer handle, int milliseconds);
int GetFileAttributesW(WString lpFileName);
boolean GetExitCodeProcess(Pointer handle, IntByReference r);
int STILL_ACTIVE = 259;
......
......@@ -23,8 +23,11 @@
*/
package hudson.util.jna;
import java.io.*;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.WString;
/**
*
......@@ -50,4 +53,12 @@ public class Kernel32Utils {
}
}
}
public static int getWin32FileAttributes(File file) throws IOException {
return Kernel32.INSTANCE.GetFileAttributesW(new WString(file.getCanonicalPath()));
}
public static boolean isJunctionOrSymlink(File file) throws IOException {
return (file.exists() && (Kernel32.INSTANCE.FILE_ATTRIBUTE_REPARSE_POINT & getWin32FileAttributes(file)) != 0);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册