NOTE: I attempted subscription to ant user mailing list but have not yet
received a subscribe email ack, so PLEASE include
[email protected] in responses. Thanks
Copy issue ant 1.8.2 windows (Failed copy deletes targeted file even
when copy is not attempted)
copy uses overwrite but not force.
Is this fixed perhaps in 1.8.3? Should a bug be created? Any workarounds?
What I assume is happening based on code is targeted file canWrite
fails, read-only exception is thrown, and then targeted file is deleted,
which succeeds.
The later part is what i observe, read-only exception followed by file
deletion. This is not the behavior i would expect.
Copy.java
protected void doResourceOperations(Map map)
{
if (map.size() > 0) {
log("Copying " + map.size() + " resource" + (map.size() == 1 ? ""
: "s") + " to " + this.destDir.getAbsolutePath());
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
Resource fromResource = (Resource)iter.next();
String[] toFiles = (String[])map.get(fromResource);
for (int i = 0; i < toFiles.length; i++) {
String toFile = toFiles[i];
try
{
log("Copying " + fromResource + " to " + toFile,
this.verbosity);
FilterSetCollection executionFilters = new
FilterSetCollection();
if (this.filtering) {
executionFilters.addFilterSet(getProject().getGlobalFilterSet());
}
Enumeration filterEnum = this.filterSets.elements();
while (filterEnum.hasMoreElements()) {
executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
}
ResourceUtils.copyResource(fromResource, new
FileResource(this.destDir, toFile), executionFilters, this.filterChains,
this.forceOverwrite, this.preserveLastModified, false,
this.inputEncoding, this.outputEncoding, getProject(), getForce());
}
catch (IOException ioe)
{
String msg = "Failed to copy " + fromResource + " to " +
toFile + " due to " + getDueTo(ioe);
File targetFile = new File(toFile);
if ((targetFile.exists()) && (!targetFile.delete())) {
msg = msg + " and I couldn't delete the corrupt " + toFile;
}
if (this.failonerror) {
throw new BuildException(msg, ioe, getLocation());
}
log(msg, 0);
}
ResourceUtils.java#copyResource
File destFile = null;
if (dest.as(FileProvider.class) != null) {
destFile = ((FileProvider)dest.as(FileProvider.class)).getFile();
}
if ((destFile != null) && (destFile.isFile()) &&
(!destFile.canWrite())) {
if (!force) {
throw new IOException("can't write to read-only destination
file " + destFile);
}