antoine     2003/08/05 15:23:57

  Modified:    src/main/org/apache/tools/ant DirectoryScanner.java
               src/main/org/apache/tools/ant/taskdefs/optional/net FTP.java
  Log:
  Make the FTP.FTPDirectoryScanner behave like the DirectoryScanner
  in terms of following symbolic links which are directories.
  This will make a change of behavior in comparison with ant 1.5.3
  where the behavior of the ftp task was to never follow symbolic links.
  
  Also select symbolic links which are files
  PR: 14063
  
  Revision  Changes    Path
  1.62      +12 -1     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.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- DirectoryScanner.java     29 Jul 2003 19:47:16 -0000      1.61
  +++ DirectoryScanner.java     5 Aug 2003 22:23:57 -0000       1.62
  @@ -514,6 +514,17 @@
       }
   
       /**
  +     * gets whether or not a DirectoryScanner follows symbolic links
  +     *
  +     * @return flag indicating whether symbolic links should be followed
  +     *
  +     * @since ant 1.6
  +     */
  +    public boolean isFollowSymlinks() {
  +        return followSymlinks;
  +    }
  +
  +    /**
        * Sets whether or not symbolic links should be followed.
        *
        * @param followSymlinks whether or not symbolic links should be followed
  @@ -1005,7 +1016,7 @@
        */
       private boolean isMorePowerfulThanExcludes(String name, String 
includepattern) {
           String soughtexclude = name + File.separator + "**";
  -        for (int counter=0; counter <excludes.length; counter++) {
  +        for (int counter = 0; counter < excludes.length; counter++) {
               if (excludes[counter].equals(soughtexclude))  {
                   return false;
               }
  
  
  
  1.41      +82 -8     
ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  
  Index: FTP.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- FTP.java  5 Aug 2003 16:44:43 -0000       1.40
  +++ FTP.java  5 Aug 2003 22:23:57 -0000       1.41
  @@ -258,16 +258,24 @@
   
                   for (int i = 0; i < newfiles.length; i++) {
                       FTPFile file = newfiles[i];
  -
                       if (!file.getName().equals(".")
                            && !file.getName().equals("..")) {
  -                        if (file.isDirectory()) {
  +                        if (isFunctioningAsDirectory(ftp, dir, file)) {
                               String name = vpath + file.getName();
  -                            if (isIncluded(name)) {
  +                            boolean slowScanAllowed = true;
  +                            if (!isFollowSymlinks() && 
file.isSymbolicLink()) {
  +                                dirsExcluded.addElement(name);
  +                                slowScanAllowed = false;
  +                            } else if (isIncluded(name)) {
                                   if (!isExcluded(name)) {
                                       if (fast) {
  -                                        scandir(file.getName(),
  +                                        if (file.isSymbolicLink()) {
  +                                            scandir(file.getLink(),
                                                   name + File.separator, fast);
  +                                        } else {
  +                                            scandir(file.getName(),
  +                                                name + File.separator, fast);
  +                                        }
                                       }
                                       dirsIncluded.addElement(name);
                                   } else {
  @@ -284,12 +292,12 @@
                                               name + File.separator, fast);
                                   }
                               }
  -                            if (!fast) {
  +                            if (!fast && slowScanAllowed) {
                                   scandir(file.getName(),
                                           name + File.separator, fast);
                               }
                           } else {
  -                            if (file.isFile()) {
  +                            if (isFunctioningAsFile(ftp, dir, file)) {
                                   String name = vpath + file.getName();
   
                                   if (isIncluded(name)) {
  @@ -312,8 +320,74 @@
               }
           }
       }
  -
  -
  +    /**
  +     * check FTPFiles to check whether they function as directories too
  +     * the FTPFile API seem to make directory and symbolic links incompatible
  +     * we want to find out if we can cd to a symbolic link
  +     * @param dir  the parent directory of the file to test
  +     * @param file the file to test
  +     * @return true if it is possible to cd to this directory
  +     * @since ant 1.6
  +     */
  +    private boolean isFunctioningAsDirectory(FTPClient ftp, String dir, 
FTPFile file) {
  +        String testDirectory =  dir + remoteFileSep + file.getName();
  +        boolean result = false;
  +        String currentWorkingDir = null;
  +        if (file.isDirectory()) {
  +            return true;
  +        } else if (file.isFile()) {
  +            return false;
  +        }
  +        try {
  +            currentWorkingDir = ftp.printWorkingDirectory();
  +        } catch (IOException ioe) {
  +            getProject().log("could not find current working directory " + 
dir
  +                + " while checking a symlink",
  +                Project.MSG_DEBUG);
  +        }
  +        if (currentWorkingDir != null) {
  +            try {
  +                result = ftp.changeWorkingDirectory(file.getLink());
  +            } catch (IOException ioe) {
  +                getProject().log("could not cd to " + file.getLink() + " 
while checking a symlink",
  +                    Project.MSG_DEBUG);
  +            }
  +            if (result) {
  +                boolean comeback = false;
  +                try {
  +                    comeback = ftp.changeWorkingDirectory(currentWorkingDir);
  +                } catch (IOException ioe) {
  +                    getProject().log("could not cd back to " + dir + " while 
checking a symlink",
  +                        Project.MSG_ERR);
  +                } finally {
  +                    if (!comeback) {
  +                        throw new BuildException("could not cd back to " + 
dir
  +                            + " while checking a symlink");
  +                    }
  +                }
  +            }
  +        }
  +        return result;
  +    }
  +    /**
  +     * check FTPFiles to check whether they function as directories too
  +     * the FTPFile API seem to make directory and symbolic links incompatible
  +     * we want to find out if we can cd to a symbolic link
  +     * @param dir  the parent directory of the file to test
  +     * @param file the file to test
  +     * @return true if it is possible to cd to this directory
  +     * @since ant 1.6
  +     */
  +    private boolean isFunctioningAsFile(FTPClient ftp, String dir, FTPFile 
file) {
  +        String testDirectory =  dir + remoteFileSep + file.getName();
  +        System.out.println("checking dir entry " + testDirectory);
  +        if (file.isDirectory()) {
  +            return false;
  +        } else if (file.isFile()) {
  +            return true;
  +        }
  +        return !isFunctioningAsDirectory(ftp, dir, file);
  +    }
       /**
        * Sets the remote directory where files will be placed. This may be a
        * relative or absolute path, and must be in the path syntax expected by
  
  
  

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

Reply via email to