You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/02/15 05:52:46 UTC

mina-sshd git commit: Fixed SCP behavior in case permissions not requested to be preserved

Repository: mina-sshd
Updated Branches:
  refs/heads/master 36cf309c0 -> 3ad079a6c


Fixed SCP behavior in case permissions not requested to be preserved


Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/3ad079a6
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/3ad079a6
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/3ad079a6

Branch: refs/heads/master
Commit: 3ad079a6cec798f5ee3696d553abac8089e1a874
Parents: 36cf309
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Wed Feb 14 19:36:06 2018 +0200
Committer: Goldstein Lyor <ly...@c-b4.com>
Committed: Thu Feb 15 07:52:39 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/common/scp/ScpHelper.java   |  4 ++--
 .../java/org/apache/sshd/client/scp/ScpTest.java     | 15 ++++-----------
 2 files changed, 6 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3ad079a6/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
index 366e296..dfa83c9 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/scp/ScpHelper.java
@@ -519,7 +519,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
 
         Set<PosixFilePermission> perms = EnumSet.copyOf(resolver.getPermissions());
-        String octalPerms = (preserve || GenericUtils.isEmpty(perms)) ? DEFAULT_FILE_OCTAL_PERMISSIONS : getOctalPermissions(perms);
+        String octalPerms = ((!preserve) || GenericUtils.isEmpty(perms)) ? DEFAULT_FILE_OCTAL_PERMISSIONS : getOctalPermissions(perms);
         String fileName = resolver.getFileName();
         String cmd = "C" + octalPerms + " " + fileSize + " " + fileName;
         if (log.isDebugEnabled()) {
@@ -614,7 +614,7 @@ public class ScpHelper extends AbstractLoggingBean implements SessionHolder<Sess
         }
 
         Set<PosixFilePermission> perms = opener.getLocalFilePermissions(path, options);
-        String octalPerms = (preserve || GenericUtils.isEmpty(perms)) ? DEFAULT_DIR_OCTAL_PERMISSIONS : getOctalPermissions(perms);
+        String octalPerms = ((!preserve) || GenericUtils.isEmpty(perms)) ? DEFAULT_DIR_OCTAL_PERMISSIONS : getOctalPermissions(perms);
         String cmd = "D" + octalPerms + " " + "0" + " " + Objects.toString(path.getFileName(), null);
         if (log.isDebugEnabled()) {
             log.debug("sendDir({})[{}] send 'D' command: {}", this, path, cmd);

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/3ad079a6/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index 643e238..66bb99b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -958,7 +958,7 @@ public class ScpTest extends BaseTestSupport {
         ));
 
         ch.ethz.ssh2.log.Logger.enabled = true;
-        final Connection conn = new Connection(TEST_LOCALHOST, port);
+        Connection conn = new Connection(TEST_LOCALHOST, port);
         try {
             ConnectionInfo info = conn.connect(null, (int) TimeUnit.SECONDS.toMillis(5L), (int) TimeUnit.SECONDS.toMillis(11L));
             outputDebugMessage("Connected: kex=%s, key-type=%s, c2senc=%s, s2cenc=%s, c2mac=%s, s2cmac=%s",
@@ -1003,9 +1003,7 @@ public class ScpTest extends BaseTestSupport {
             os.flush();
 
             String header = readLine(is);
-            Collection<PosixFilePermission> perms = IoUtils.getPermissions(target.toPath());
-            String octalPerms = ScpHelper.getOctalPermissions(perms);
-            String expHeader = "C" + octalPerms + " " + target.length() + " " + fileName;
+            String expHeader = "C" + ScpHelper.DEFAULT_FILE_OCTAL_PERMISSIONS + " " + target.length() + " " + fileName;
             assertEquals("Mismatched header for " + path, expHeader, header);
 
             String lenValue = header.substring(6, header.indexOf(' ', 6));
@@ -1038,18 +1036,13 @@ public class ScpTest extends BaseTestSupport {
             os.flush();
 
             String header = readLine(is);
-            File parent = target.getParentFile();
-            Collection<PosixFilePermission> perms = IoUtils.getPermissions(parent.toPath());
-            String octalPerms = ScpHelper.getOctalPermissions(perms);
-            String expPrefix = "D" + octalPerms + " 0 ";
+            String expPrefix = "D" + ScpHelper.DEFAULT_DIR_OCTAL_PERMISSIONS + " 0 ";
             assertTrue("Bad header prefix for " + path + ": " + header, header.startsWith(expPrefix));
             os.write(0);
             os.flush();
 
             header = readLine(is);
-            perms = IoUtils.getPermissions(target.toPath());
-            octalPerms = ScpHelper.getOctalPermissions(perms);
-            String expHeader = "C" + octalPerms + " " + target.length() + " " + target.getName();
+            String expHeader = "C" + ScpHelper.DEFAULT_FILE_OCTAL_PERMISSIONS + " " + target.length() + " " + target.getName();
             assertEquals("Mismatched dir header for " + path, expHeader, header);
             int length = Integer.parseInt(header.substring(6, header.indexOf(' ', 6)));
             os.write(0);