Repository: mina-sshd
Updated Branches:
  refs/heads/master e313d8809 -> b91da7d13


[SSHD-353] The close method on the stream returned by DefaultSftpClient#read() 
should be idemptotent

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

Branch: refs/heads/master
Commit: b5b05d1b92f20682047262bc283c219eae75790e
Parents: e313d88
Author: Guillaume Nodet <[email protected]>
Authored: Thu Sep 25 16:25:29 2014 +0200
Committer: Guillaume Nodet <[email protected]>
Committed: Thu Sep 25 16:25:29 2014 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/client/sftp/DefaultSftpClient.java  | 8 +++++++-
 sshd-core/src/test/java/org/apache/sshd/SftpTest.java        | 1 +
 2 files changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b5b05d1b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
----------------------------------------------------------------------
diff --git 
a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java 
b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
index 6e39489..4f4921b 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/sftp/DefaultSftpClient.java
@@ -657,6 +657,9 @@ public class DefaultSftpClient implements SftpClient {
             }
             @Override
             public int read(byte[] b, int off, int len) throws IOException {
+                if (handle == null) {
+                    throw new IOException("Stream closed");
+                }
                 int idx = off;
                 while (len > 0) {
                     if (index >= available) {
@@ -684,7 +687,10 @@ public class DefaultSftpClient implements SftpClient {
             }
             @Override
             public void close() throws IOException {
-                DefaultSftpClient.this.close(handle);
+                if (handle != null) {
+                    DefaultSftpClient.this.close(handle);
+                    handle = null;
+                }
             }
         };
     }

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b5b05d1b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java 
b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
index b36c514..ff6aadb 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
@@ -135,6 +135,7 @@ public class SftpTest extends BaseTest {
         is.read(new byte[1024 * 128]);
         int i = is.read();
         is.close();
+        is.close();
 
         SftpClient.Attributes attributes = 
sftp.stat("target/sftp/client/test.txt");
         assertTrue(attributes.isRegularFile());

Reply via email to