Browse Source

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

master
Jaikiran Pai 8 years ago
parent
commit
b9125733c4
4 changed files with 30 additions and 5 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +5
    -0
      WHATSNEW
  3. +4
    -0
      contributors.xml
  4. +20
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java

+ 1
- 0
CONTRIBUTORS View File

@@ -162,6 +162,7 @@ Issa Gorissen
Ivan Ivanov
J Bleijenbergh
Jack J. Woehr
Jaikiran Pai
James Duncan Davidson
Jan Cumps
Jan Matèrne


+ 5
- 0
WHATSNEW View File

@@ -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:
--------------



+ 4
- 0
contributors.xml View File

@@ -673,6 +673,10 @@
<middle>J.</middle>
<last>Woehr</last>
</name>
<name>
<first>Jaikiran</first>
<last>Pai</last>
</name>
<name>
<first>James</first>
<middle>Duncan</middle>


+ 20
- 5
src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java View File

@@ -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();


Loading…
Cancel
Save