summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2014-01-12 01:34:58 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2014-02-10 23:07:28 +0100
commit50a19fcdef271a74eb055f6996a425fc0c01d81f (patch)
treee1c91bcf4cf30a5aef3eb22bb20d9decb3cd8519
parent078a9f60664fee1f7e85f0c3ab3fd067c0f674cc (diff)
downloadjgit-50a19fcdef271a74eb055f6996a425fc0c01d81f.tar.gz
jgit-50a19fcdef271a74eb055f6996a425fc0c01d81f.zip
Dynamically detect if Windows supports symbolic links
To get symlink support you typically need to run as administrator. Change-Id: I394ea75bc2f250c62f860e537a0af9e6380b3b38 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java26
1 files changed, 25 insertions, 1 deletions
diff --git a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java
index b015362247..98df7c85c1 100644
--- a/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java
+++ b/org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java
@@ -51,6 +51,8 @@ import java.io.IOException;
*/
public class FS_Win32_Java7 extends FS_Win32 {
+ private volatile Boolean supportSymlinks;
+
FS_Win32_Java7(FS src) {
super(src);
}
@@ -65,7 +67,29 @@ public class FS_Win32_Java7 extends FS_Win32 {
@Override
public boolean supportsSymlinks() {
- return true;
+ if (supportSymlinks == null)
+ detectSymlinkSupport();
+ return Boolean.TRUE.equals(supportSymlinks);
+ }
+
+ private void detectSymlinkSupport() {
+ File tempFile = null;
+ try {
+ tempFile = File.createTempFile("tempsymlinktarget", ""); //$NON-NLS-1$ //$NON-NLS-2$
+ File linkName = new File(tempFile.getParentFile(), "tempsymlink"); //$NON-NLS-1$
+ FileUtil.createSymLink(linkName, tempFile.getPath());
+ supportSymlinks = Boolean.TRUE;
+ linkName.delete();
+ } catch (IOException e) {
+ supportSymlinks = Boolean.FALSE;
+ } finally {
+ if (tempFile != null)
+ try {
+ FileUtils.delete(tempFile);
+ } catch (IOException e) {
+ throw new RuntimeException(e); // panic
+ }
+ }
}
@Override