[hg] main-silver: #223168: symlink detection uses JDK7 nio

  • From: Svata Dedic < >
  • To:
  • Subject: [hg] main-silver: #223168: symlink detection uses JDK7 nio
  • Date: Wed, 12 Jun 2013 20:46:54 -0700

changeset b91df5ae0d70 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/b91df5ae0d70
description:
        #223168: symlink detection uses JDK7 nio

diffstat:

 
parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java
 |  16 +++++++++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diffs (40 lines):

diff --git 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java
 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java
--- 
a/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java
+++ 
b/parsing.api/src/org/netbeans/modules/parsing/impl/indexing/FileObjectCrawler.java
@@ -45,6 +45,8 @@
 import org.netbeans.modules.parsing.spi.indexing.SuspendStatus;
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayDeque;
 import java.util.Collection;
 import java.util.Comparator;
@@ -332,6 +334,18 @@
         return false;
     }
     
+    private static boolean isSameFile(File check, File other) throws 
IOException {
+        Path checkPath = check.toPath();
+        if (Files.isSymbolicLink(checkPath)) {
+            Path target = other.toPath();
+            // if the file exists, check the target using JDK/system call.
+            // otherwise compare the contents of the symbolic link.
+            return target.toRealPath().equals(checkPath.toRealPath());
+        } else {
+            return false;
+        }
+    }
+    
     private static boolean isLink(
         @NonNull final File file,
         @NonNull final Deque<? extends File> path,
@@ -346,7 +360,7 @@
                     try {
                         if (mockLinkTypes != null ?
                             
mockLinkTypes.get(Pair.<File,File>of(pathElement, file)) :
-                            
file.getCanonicalFile().equals(pathElement.getCanonicalFile())) {
+                            isSameFile(file, pathElement)) {
                             hasLink = true;
                             break;
                         }

[hg] main-silver: #223168: symlink detection uses JDK7 nio

Svata Dedic 06/13/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close