This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push:
new 8511719 I've broken output to files that don't exist before running
sshexec
8511719 is described below
commit 8511719cf38cfe9be3c000e89d448f7f13f49cba
Author: Stefan Bodewig <[email protected]>
AuthorDate: Thu Oct 17 20:37:14 2019 +0200
I've broken output to files that don't exist before running sshexec
---
WHATSNEW | 2 ++
src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/WHATSNEW b/WHATSNEW
index ab9d210..1eaf764 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,8 @@ Fixed bugs:
the stacktrace for failures. This is now fixed.
Bugzilla Report 63827
+ * sshexec failed to write output to a file if the file didn't exist
+
Other changes:
--------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
index 3a87879..1cd273b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
@@ -482,8 +482,10 @@ public class SSHExec extends SSHBase {
*/
private void writeToFile(final String from, final boolean append, final
File to)
throws IOException {
+ final StandardOpenOption appendOrTruncate = append ?
StandardOpenOption.APPEND
+ : StandardOpenOption.TRUNCATE_EXISTING;
try (BufferedWriter out =
Files.newBufferedWriter(to.getAbsoluteFile().toPath(),
- StandardOpenOption.APPEND)) {
+ appendOrTruncate, StandardOpenOption.CREATE)) {
final StringReader in = new StringReader(from);
final char[] buffer = new char[BUFFER_SIZE];
while (true) {