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 2017/07/23 04:50:50 UTC

ant git commit: BZ-43271 BZ-59648 Change permissions on the correct remote file (path) that was transferred, instead of accidentally changing the permissions of the directory containing the transferred file

Repository: ant
Updated Branches:
  refs/heads/1.9.x 4e2e7d961 -> b9125733c


BZ-43271 BZ-59648 Change permissions on the correct remote file (path) that was transferred, instead of accidentally changing the permissions of the directory containing the transferred file


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/b9125733
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/b9125733
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/b9125733

Branch: refs/heads/1.9.x
Commit: b9125733c49256ea7349bba968d9eabd468a9223
Parents: 4e2e7d9
Author: Jaikiran Pai <ja...@gmail.com>
Authored: Sat Jul 22 14:29:59 2017 +0530
Committer: Jaikiran Pai <ja...@gmail.com>
Committed: Sun Jul 23 10:19:01 2017 +0530

----------------------------------------------------------------------
 CONTRIBUTORS                                    |  1 +
 WHATSNEW                                        |  5 ++++
 contributors.xml                                |  4 ++++
 .../optional/ssh/ScpToMessageBySftp.java        | 25 ++++++++++++++++----
 4 files changed, 30 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/b9125733/CONTRIBUTORS
----------------------------------------------------------------------
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 65a1cfa..efab5ab 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -162,6 +162,7 @@ Issa Gorissen
 Ivan Ivanov
 J Bleijenbergh
 Jack J. Woehr
+Jaikiran Pai
 James Duncan Davidson
 Jan Cumps
 Jan Matèrne

http://git-wip-us.apache.org/repos/asf/ant/blob/b9125733/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 42f49a7..beb2cd1 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,11 @@ Fixed bugs:
    value.
    Bugzilla Report 60767
 
+ * Bugzilla Reports 59648 and 43271 - Fixed the issue where the 
+   SCP based tasks would try to change the permissions on the
+   parent directory of a transferred file, instead of changing it
+   on the transferred file itself.
+
 Other changes:
 --------------
 

http://git-wip-us.apache.org/repos/asf/ant/blob/b9125733/contributors.xml
----------------------------------------------------------------------
diff --git a/contributors.xml b/contributors.xml
index fd404f8..5bdf467 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -674,6 +674,10 @@
     <last>Woehr</last>
   </name>
   <name>
+    <first>Jaikiran</first>
+    <last>Pai</last>
+  </name>  
+  <name>
     <first>James</first>
     <middle>Duncan</middle>
     <last>Davidson</last>

http://git-wip-us.apache.org/repos/asf/ant/blob/b9125733/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
index 2b32907..b9a8943 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java
@@ -135,11 +135,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
             try {
                 sendFileToRemote(channel, localFile, remotePath);
             } catch (final SftpException e) {
-                final JSchException schException = new JSchException("Could not send '" + localFile
+                throw new JSchException("Could not send '" + localFile
                         + "' to '" + remotePath + "' - "
-                        + e.toString());
-                schException.initCause(e);
-                throw schException;
+                        + e.toString(), e);
             }
         } finally {
             if (channel != null) {
@@ -250,7 +248,24 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
                 log("Sending: " + localFile.getName() + " : " + filesize);
             }
             channel.put(localFile.getAbsolutePath(), remotePath, monitor);
-            channel.chmod(getFileMode(), remotePath);
+            // set the fileMode on the transferred file. The "remotePath" can potentially be a directory
+            // into which the file got transferred, so we can't/shouldn't go ahead and try to change that directory's
+            // permissions. Instead we determine the path of the transferred file on remote.
+            final String transferredFileRemotePath;
+            if (channel.stat(remotePath).isDir()) {
+                // Note: It's correct to use "/" as the file separator without worrying about what the remote
+                // server's file separator is, since the SFTP spec expects "/" to be considered as file path
+                // separator. See section 6.2 "File Names" of the spec, which states:
+                // "This protocol represents file names as strings.  File names are
+                // assumed to use the slash ('/') character as a directory separator."
+                transferredFileRemotePath = remotePath + "/" + localFile.getName();
+            } else {
+                transferredFileRemotePath = remotePath;
+            }
+            if (this.getVerbose()) {
+                log("Setting file mode '" + Integer.toOctalString(getFileMode()) + "' on remote path " + transferredFileRemotePath);
+            }
+            channel.chmod(getFileMode(), transferredFileRemotePath);
         } finally {
             if (this.getVerbose()) {
                 final long endTime = System.currentTimeMillis();