[SSHD-229] SFTP download reopen files issue Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/e6005dc3 Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/e6005dc3 Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/e6005dc3
Branch: refs/heads/master Commit: e6005dc315e0d879b5a9e20325d9598e4d66b8b9 Parents: ce434ed Author: Guillaume Nodet <[email protected]> Authored: Wed Jul 17 21:32:25 2013 +0200 Committer: Guillaume Nodet <[email protected]> Committed: Wed Jul 17 21:32:25 2013 +0200 ---------------------------------------------------------------------- .../main/java/org/apache/sshd/server/sftp/SftpSubsystem.java | 8 ++++++++ .../main/java/org/apache/sshd/sftp/subsystem/FileHandle.java | 8 ++++++++ 2 files changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e6005dc3/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java index 4758e9e..5615063 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/sftp/SftpSubsystem.java @@ -397,6 +397,7 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste long outputPos; InputStream input; long inputPos; + long length; public FileHandle(SshFile sshFile, int flags) { super(sshFile); @@ -408,14 +409,21 @@ public class SftpSubsystem implements Command, Runnable, SessionAware, FileSyste } public int read(byte[] data, long offset) throws IOException { + if (input != null && offset >= length) { + return -1; + } if (input != null && offset != inputPos) { IoUtils.closeQuietly(input); input = null; } if (input == null) { input = file.createInputStream(offset); + length = file.getSize(); inputPos = offset; } + if (offset >= length) { + return -1; + } int read = input.read(data); inputPos += read; return read; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/e6005dc3/sshd-sftp/src/main/java/org/apache/sshd/sftp/subsystem/FileHandle.java ---------------------------------------------------------------------- diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/subsystem/FileHandle.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/subsystem/FileHandle.java index b1b66af..fb0bb77 100644 --- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/subsystem/FileHandle.java +++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/subsystem/FileHandle.java @@ -32,6 +32,7 @@ public class FileHandle extends BaseHandle { long outputPos; InputStream input; long inputPos; + long length; public FileHandle(String id, SshFile sshFile, int flags) { super(id, sshFile); @@ -43,14 +44,21 @@ public class FileHandle extends BaseHandle { } public int read(byte[] data, long offset) throws IOException { + if (input != null && offset >= length) { + return -1; + } if (input != null && offset != inputPos) { IoUtils.closeQuietly(input); input = null; } if (input == null) { input = getFile().createInputStream(offset); + length = getFile().getSize(); inputPos = offset; } + if (offset >= length) { + return -1; + } int read = input.read(data); inputPos += read; return read;
