bodewig     2003/07/16 06:57:10

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
  Log:
  Fix symlink check
  
  Revision  Changes    Path
  1.47      +39 -0     ant/src/main/org/apache/tools/ant/DirectoryScanner.java
  
  Index: DirectoryScanner.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- DirectoryScanner.java     16 Jul 2003 11:47:52 -0000      1.46
  +++ DirectoryScanner.java     16 Jul 2003 13:56:55 -0000      1.47
  @@ -705,6 +705,10 @@
               }
   
               if (myfile.exists()) {
  +                if (!followSymlinks && isSymlink(basedir, currentelement)) {
  +                    continue;
  +                }
  +
                   if (myfile.isDirectory()) {
                       if (isIncluded(currentelement)
                           && currentelement.length() > 0) {
  @@ -1191,5 +1195,40 @@
               }
           }
           return null;
  +    }
  +
  +    /**
  +     * Do we have to traverse a symlink when trying to reach path from
  +     * basedir?
  +     * @since Ant 1.6
  +     */
  +    private boolean isSymlink(File base, String path) {
  +        return isSymlink(base, SelectorUtils.tokenizePath(path));
  +    }
  +
  +    /**
  +     * Do we have to traverse a symlink when trying to reach path from
  +     * basedir?
  +     * @since Ant 1.6
  +     */
  +    private boolean isSymlink(File base, Vector pathElements) { 
  +        if (pathElements.size() > 0) {
  +            String current = (String) pathElements.remove(0);
  +            try {
  +                if (fileUtils.isSymbolicLink(base, current)) {
  +                    return true;
  +                } else {
  +                    base = new File(base, current);
  +                    return isSymlink(base, pathElements);
  +                }
  +            } catch (IOException ioe) {
  +                String msg = "IOException caught while checking "
  +                    + "for links, couldn't get cannonical path!";
  +                // will be caught and redirected to Ant's logging system
  +                System.err.println(msg);
  +                return false;
  +            }
  +        }
  +        return false;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to