diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index ab2f1113e0fc0806e79199dd9786ef76feda54b4..c5ba78129c383ec5eef223c22df24aeb6f9cee5c 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -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; diff --git a/core/src/main/java/hudson/util/jna/Kernel32.java b/core/src/main/java/hudson/util/jna/Kernel32.java index 1dc10ae71f98fbc7a1178cc1d6fa4678de1ce079..6f5828e3abc1a41717aa709c099d44fb9a1bf871 100644 --- a/core/src/main/java/hudson/util/jna/Kernel32.java +++ b/core/src/main/java/hudson/util/jna/Kernel32.java @@ -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; diff --git a/core/src/main/java/hudson/util/jna/Kernel32Utils.java b/core/src/main/java/hudson/util/jna/Kernel32Utils.java index f54b4d9b22610ebca08e875ae35cb12cddf15adb..a7cae117b6705f8eb103b939532c22b850030491 100644 --- a/core/src/main/java/hudson/util/jna/Kernel32Utils.java +++ b/core/src/main/java/hudson/util/jna/Kernel32Utils.java @@ -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); + } }