diff --git a/WHATSNEW b/WHATSNEW index 1d6e52913..45bcf8c02 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -4,13 +4,13 @@ Changes from Ant 1.8.1 TO current SVN version Changes that could break older environments: ------------------------------------------- - * Prior to Ant 1.8.0 the task would overwrite read-only - destination files. Starting with 1.8.0 it would only do so if - under special circumstances. Ant 1.8.2 now consistently won't - replace a read-only file by default. The same is true for a number - of other tasks. - The task now has a new force attribute that can be used to - make the task overwrite read-only destinations. + * Prior to Ant 1.8.0 the task and several other tasks would + overwrite read-only destination files. Starting with 1.8.0 it + would only do so if under special circumstances. Ant 1.8.2 now + consistently won't replace a read-only file by default. The same is + true for a number of other tasks. + The and task now have a new force attribute that can + be used to make the task overwrite read-only destinations. Bugzilla Report 49261. Fixed bugs: diff --git a/docs/manual/CoreTasks/move.html b/docs/manual/CoreTasks/move.html index 8f81162e1..90bd0ef97 100644 --- a/docs/manual/CoreTasks/move.html +++ b/docs/manual/CoreTasks/move.html @@ -85,6 +85,12 @@ there is a directory by the same name in todir, the action will fail. files are newer (default is "true") No + + force + Overwrite read-only destination + files. since Ant 1.8.2 + No; defaults to false. + filtering indicates whether token filtering should take place during diff --git a/src/main/org/apache/tools/ant/taskdefs/Copy.java b/src/main/org/apache/tools/ant/taskdefs/Copy.java index 6c49fe0a2..06dbfed91 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Copy.java +++ b/src/main/org/apache/tools/ant/taskdefs/Copy.java @@ -240,6 +240,15 @@ public class Copy extends Task { force = f; } + /** + * Whether read-only destinations will be overwritten. + * + * @since Ant 1.8.2 + */ + public boolean getForce() { + return force; + } + /** * Set whether files copied from directory trees will be "flattened" * into a single directory. If there are multiple files with @@ -856,7 +865,7 @@ public class Copy extends Task { preserveLastModified, /* append: */ false, inputEncoding, outputEncoding, getProject(), - force); + getForce()); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + getDueTo(ioe); @@ -947,7 +956,7 @@ public class Copy extends Task { inputEncoding, outputEncoding, getProject(), - force); + getForce()); } catch (IOException ioe) { String msg = "Failed to copy " + fromResource + " to " + toFile diff --git a/src/main/org/apache/tools/ant/taskdefs/Move.java b/src/main/org/apache/tools/ant/taskdefs/Move.java index bd74605a1..a2680705d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Move.java +++ b/src/main/org/apache/tools/ant/taskdefs/Move.java @@ -233,9 +233,10 @@ public class Move extends Copy { getFilterChains(), forceOverwrite, getPreserveLastModified(), + /* append: */ false, getEncoding(), getOutputEncoding(), - getProject()); + getProject(), getForce()); } catch (IOException ioe) { String msg = "Failed to copy " + fromFile + " to " + toFile + " due to " + ioe.getMessage(); @@ -329,6 +330,18 @@ public class Move extends Copy { || getFilterChains().size() > 0) { return false; } + + // identical logic lives in ResourceUtils.copyResource(): + if (destFile.isFile() && !destFile.canWrite()) { + if (!getForce()) { + throw new IOException("can't replace read-only destination " + + "file " + destFile); + } else if (!getFileUtils().tryHardToDelete(destFile)) { + throw new IOException("failed to delete read-only " + + "destination file " + destFile); + } + } + // identical logic lives in FileUtils.rename(): File parent = destFile.getParentFile(); if (parent != null && !parent.exists()) { diff --git a/src/tests/antunit/taskdefs/move-test.xml b/src/tests/antunit/taskdefs/move-test.xml index 2ce49bc50..9acac7493 100644 --- a/src/tests/antunit/taskdefs/move-test.xml +++ b/src/tests/antunit/taskdefs/move-test.xml @@ -124,4 +124,111 @@ value="Y"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +