You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/09/10 11:56:44 UTC

git commit: [SSHD-345] Add isDirectory, isSymbolicLink, isRegularFile, and isOther methods to Attributes

Repository: mina-sshd
Updated Branches:
  refs/heads/master 9009c91fc -> da8bbf6b2


[SSHD-345] Add isDirectory, isSymbolicLink, isRegularFile, and isOther methods to Attributes

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

Branch: refs/heads/master
Commit: da8bbf6b28f987ab6a39d189763eeacb22f767b5
Parents: 9009c91
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Sep 10 11:56:33 2014 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Sep 10 11:56:33 2014 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/sshd/client/SftpClient.java    | 12 ++++++++++++
 sshd-core/src/test/java/org/apache/sshd/SftpTest.java   |  6 ++++++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/da8bbf6b/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java
index 021c494..8e516e1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SftpClient.java
@@ -105,6 +105,18 @@ public interface SftpClient {
             this.mtime = mtime;
             return this;
         }
+        public boolean isRegularFile() {
+            return (perms & S_IFMT) == S_IFREG;
+        }
+        public boolean isDirectory() {
+            return (perms & S_IFMT) == S_IFDIR;
+        }
+        public boolean isSymbolicLink() {
+            return (perms & S_IFMT) == S_IFLNK;
+        }
+        public boolean isOther() {
+            return !isRegularFile() && !isDirectory() && !isSymbolicLink();
+        }
     }
 
     public static class DirEntry {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/da8bbf6b/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 7d3a95e..b36c514 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
@@ -136,6 +136,12 @@ public class SftpTest extends BaseTest {
         int i = is.read();
         is.close();
 
+        SftpClient.Attributes attributes = sftp.stat("target/sftp/client/test.txt");
+        assertTrue(attributes.isRegularFile());
+
+        attributes = sftp.stat("target/sftp/client");
+        assertTrue(attributes.isDirectory());
+
         int nb = 0;
         for (SftpClient.DirEntry entry : sftp.readDir("target/sftp/client")) {
             nb++;