bodewig     2003/06/25 03:31:45

  Modified:    src/main/org/apache/tools/ant/taskdefs FixCRLF.java
               src/main/org/apache/tools/ant/util FileUtils.java
  Log:
  Make fixcrlf work even with /tmp on a separate filesystem
  
  Revision  Changes    Path
  1.48      +8 -34     ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java
  
  Index: FixCRLF.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/FixCRLF.java,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- FixCRLF.java      24 Jun 2003 08:44:02 -0000      1.47
  +++ FixCRLF.java      25 Jun 2003 10:31:45 -0000      1.48
  @@ -552,50 +552,24 @@
   
               File destFile = new File(destD, file);
   
  +            boolean destIsWrong = true;
               if (destFile.exists()) {
                   // Compare the destination with the temp file
                   log("destFile exists", Project.MSG_DEBUG);
                   if (!fileUtils.contentEquals(destFile, tmpFile)) {
                       log(destFile + " is being written", Project.MSG_DEBUG);
  -                    if (!destFile.delete()) {
  -                        throw new BuildException("Unable to delete "
  -                                                 + destFile);
  -                    }
  -                    if (!tmpFile.renameTo(destFile)) {
  -                        throw new BuildException(
  -                                "Failed to transform " + srcFile
  -                                + " to " + destFile
  -                                + ". Couldn't rename temporary file: "
  -                                + tmpFile);
  -                    }
  -
  -                } else { // destination is equal to temp file
  +                } else {
                       log(destFile +
                           " is not written, as the contents are identical",
                           Project.MSG_DEBUG);
  -                    if (!tmpFile.delete()) {
  -                        throw new BuildException("Unable to delete "
  -                                                 + tmpFile);
  -                    }
  -                }
  -            } else { // destFile does not exist - write the temp file
  -                log("destFile does not exist", Project.MSG_DEBUG);
  -
  -                File parent = fileUtils.getParentFile(destFile);
  -                if (!parent.exists()) {
  -                    parent.mkdirs();
  -                }
  -
  -                if (!tmpFile.renameTo(destFile)) {
  -                    throw new BuildException(
  -                            "Failed to transform " + srcFile
  -                            + " to " + destFile
  -                            + ". Couldn't rename temporary file: "
  -                            + tmpFile);
  +                    destIsWrong = false;
                   }
               }
   
  -            tmpFile = null;
  +            if (destIsWrong) {
  +                fileUtils.rename(tmpFile, destFile);
  +                tmpFile = null;
  +            }
   
           } catch (IOException e) {
               throw new BuildException(e);
  
  
  
  1.44      +39 -1     ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- FileUtils.java    24 Jun 2003 16:07:24 -0000      1.43
  +++ FileUtils.java    25 Jun 2003 10:31:45 -0000      1.44
  @@ -1122,5 +1122,43 @@
               .equals(normalize(f2.getAbsolutePath()));
       }
   
  +    /**
  +     * Renames a file, even if that involves crossing file system boundaries.
  +     *
  +     * <p>This will remove <code>to</code> (if it exists), ensure that
  +     * <code>to</code>'s parent directory exists and move
  +     * <code>from</code>, which involves deleting <code>from</code> as
  +     * well.</p>
  +     *
  +     * @throws IOException if anything bad happens during this
  +     * process.  Note that <code>to</code> may have been deleted
  +     * already when this happens.
  +     *
  +     * @param from the file to move
  +     * @param to the new file name
  +     *
  +     * @since Ant 1.6
  +     */
  +    public void rename(File from, File to) throws IOException {
  +        if (to.exists() && !to.delete()) {
  +            throw new IOException("Failed to delete " + to 
  +                                  + " while trying to rename " + from);
  +        }
  +        
  +        File parent = getParentFile(to);
  +        if (!parent.exists() && !parent.mkdirs()) {
  +            throw new IOException("Failed to create directory " + parent
  +                                  + " while trying to rename " + from);
  +        }
  +
  +        if (!from.renameTo(to)) {
  +            copyFile(from, to);
  +            if (!from.delete()) {
  +                throw new IOException("Failed to delete " + from 
  +                                      + " while trying to rename it.");
  +            }
  +        }
  +    }
  +
   }
   
  
  
  

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

Reply via email to