ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 624] New - copy commands should remove existing file before copying content
Date Thu, 15 Feb 2001 23:49:01 GMT
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=624

*** shadow/624	Thu Feb 15 15:49:01 2001
--- shadow/624.tmp.4651	Thu Feb 15 15:49:01 2001
***************
*** 0 ****
--- 1,51 ----
+ +============================================================================+
+ | copy commands should remove existing file before copying content           |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 624                         Product: Ant                     |
+ |       Status: NEW                         Version: 1.2                     |
+ |   Resolution:                            Platform: Sun                     |
+ |     Severity: Normal                   OS/Version: All                     |
+ |     Priority:                           Component: Core tasks              |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: ant-dev@jakarta.apache.org                                   |
+ |  Reported By: ederksen@arrow.lz.att.com                                    |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ The copy task uses org.apache.ant.tools.ant.Project.copyFile() which
+ contains a minor bug. It uses a BufferWriter or FileOutputStream and starts
+ copying the file contents, without removing the original file.
+ If the original file is a soft link (on Unix), it changes the contents of the 
+ file that the soft link points to, which is not what you want IMHO.
+ One would expect the copy task to work more similar to the Unix 'cp' command
+ which creates a new file (in essence wiping out the previous file.)
+ 
+ To fix this, add something like this before copying the contents:
+ 
+ //--- Original code
+ 
+ ...
+ if (parent.exists())
+ {
+     parent.mkdirs();
+ }
+ 
+ //--- Start of insertion:
+ 
+ File dest = new File(destFile);
+ if (dest.exists()) dest.delete();
+ 
+ //---- End of insertion. Rest of original code:
+ 
+ if (filtering) ...
+ 
+ //--- etc.
+ 
+ I'm not sure what should happen if the existing file is a directory.
+ My guess is you would want to delete it anyway, so I don't think you need
+ to test for that.
+ 
+ I was using Ant 1.2 on Solaris, but the problem concerns any platform that
+ has (soft) links.

Mime
View raw message