]> source.dussan.org Git - jgit.git/commitdiff
Dynamically detect if Windows supports symbolic links 42/20542/7
authorRobin Rosenberg <robin.rosenberg@dewire.com>
Sun, 12 Jan 2014 00:34:58 +0000 (01:34 +0100)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 10 Feb 2014 22:07:28 +0000 (23:07 +0100)
To get symlink support you typically need to run as administrator.

Change-Id: I394ea75bc2f250c62f860e537a0af9e6380b3b38
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.java7/src/org/eclipse/jgit/util/FS_Win32_Java7.java

index b015362247067791680e861136b93d7d270653de..98df7c85c10177f6790bdd2707321a92eb3bd607 100644 (file)
@@ -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