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 2015/10/22 13:15:06 UTC

mina-sshd git commit: Do not throw EOFException on end of SFTP directory listing - send FXF-EOF status directly

Repository: mina-sshd
Updated Branches:
  refs/heads/master 0c443af5c -> b70ce9927


Do not throw EOFException on end of SFTP directory listing - send FXF-EOF status directly

* Avoid flow-control via exceptions


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

Branch: refs/heads/master
Commit: b70ce9927041872606ac09f5808b29d4301fa73a
Parents: 0c443af
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Thu Oct 22 14:14:49 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Thu Oct 22 14:14:49 2015 +0300

----------------------------------------------------------------------
 .../server/subsystem/sftp/SftpSubsystem.java    |  6 ++--
 .../sshd/client/subsystem/sftp/SftpTest.java    | 34 ++++++++++++++++++--
 2 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b70ce992/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
index 2b2e8dd..e28554a 100644
--- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
+++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java
@@ -1687,7 +1687,8 @@ public class SftpSubsystem
         try {
             DirectoryHandle dh = validateHandle(handle, h, DirectoryHandle.class);
             if (dh.isDone()) {
-                throw new EOFException("Directory reading is done");
+                sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_EOF, "Directory reading is done");
+                return;
             }
 
             Path file = dh.getFile();
@@ -1728,7 +1729,8 @@ public class SftpSubsystem
             } else {
                 // empty directory
                 dh.markDone();
-                throw new EOFException("Empty directory");
+                sendStatus(BufferUtils.clear(buffer), id, SftpConstants.SSH_FX_EOF, "Empty directory");
+                return;
             }
 
             ValidateUtils.checkNotNull(reply, "No reply buffer created");

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/b70ce992/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
index 9a46f8e..eab0a54 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
@@ -36,9 +36,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.EnumSet;
 import java.util.Iterator;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.Vector;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -831,12 +833,40 @@ public class SftpTest extends AbstractSftpClientTestSupport {
         try {
             URI url = getClass().getClassLoader().getResource(SshClient.class.getName().replace('.', '/') + ".class").toURI();
             URI base = new File(System.getProperty("user.dir")).getAbsoluteFile().toURI();
-            String path = new File(base.relativize(url).getPath()).getParent() + "/";
+            File baseDir = new File(base.relativize(url).getPath());
+            String path = baseDir.getParent() + "/";
             path = path.replace('\\', '/');
+
             Vector<?> res = c.ls(path);
+            File dir = baseDir.getParentFile();
+            Collection<String> expNames = OsUtils.isUNIX()
+                                        ? new LinkedList<String>()
+                                        : new TreeSet<String>(String.CASE_INSENSITIVE_ORDER)
+                                        ;
+            String[] names = dir.list();
+            if (GenericUtils.length(names) > 0) {
+                for (String n : names) {
+                    if (".".equals(n) || "..".equals(n)) {
+                        continue;
+                    }
+
+                    assertTrue("Failed to accumulate " + n, expNames.add(n));
+                }
+            }
+
             for (Object f : res) {
-                System.out.append('\t').println(f.toString());
+                System.out.append('\t').println(f);
+
+                ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) f;
+                String name = entry.getFilename();
+                if (".".equals(name) || "..".equals(name)) {
+                    continue;
+                }
+
+                assertTrue("Entry not found: " + name, expNames.remove(name));
             }
+
+            assertTrue("Un-listed names: " + expNames, GenericUtils.isEmpty(expNames));
         } finally {
             c.disconnect();
         }