You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2020/11/21 05:15:40 UTC
[ant] branch master updated: bz-64742 Fix SCP task (with sftp=true)
to correctly parse the remote directory when fetching from root directory
This is an automated email from the ASF dual-hosted git repository.
jaikiran 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 a2b9f4c bz-64742 Fix SCP task (with sftp=true) to correctly parse the remote directory when fetching from root directory
a2b9f4c is described below
commit a2b9f4c33e244c67831e82b39fd82c4dd440533c
Author: Jaikiran Pai <ja...@apache.org>
AuthorDate: Sat Nov 21 10:44:13 2020 +0530
bz-64742 Fix SCP task (with sftp=true) to correctly parse the remote directory when fetching from root directory
---
WHATSNEW | 6 ++++++
.../tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java | 11 +++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index f17bf4b..1c6e28c 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -1,5 +1,11 @@
Changes from Ant 1.10.9 TO Ant 1.10.10
======================================
+Fixed bugs:
+-----------
+
+ * SCP (with sftp=true) task would fail if fetching file located in root directory
+ Bugzilla Report 64742
+
Changes from Ant 1.10.8 TO Ant 1.10.9
=====================================
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
index 0ad0899..7e5edab 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
@@ -134,9 +134,16 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
final String remoteFile,
final File localFile) throws SftpException {
String pwd = remoteFile;
- if (remoteFile.lastIndexOf('/') != -1) {
+ final int lastIndexOfFileSeparator = remoteFile.lastIndexOf('/');
+ if (lastIndexOfFileSeparator != -1) {
if (remoteFile.length() > 1) {
- pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/'));
+ if (lastIndexOfFileSeparator == 0) {
+ // the file path is of the form "/foo....." i.e. the file separator
+ // occurs at the start (and only there).
+ pwd = "/";
+ } else {
+ pwd = remoteFile.substring(0, lastIndexOfFileSeparator);
+ }
}
}
channel.cd(pwd);