commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1813421 - in /commons/proper/vfs/trunk: commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/ src/changes/
Date Thu, 26 Oct 2017 15:54:18 GMT
Author: ggregory
Date: Thu Oct 26 15:54:18 2017
New Revision: 1813421

URL: http://svn.apache.org/viewvc?rev=1813421&view=rev
Log:
[VFS-589] SFTP moveTo operation hangs if the server does not support SSH channelExec.

Modified:
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
    commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
    commons/proper/vfs/trunk/src/changes/changes.xml

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java?rev=1813421&r1=1813420&r2=1813421&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java
Thu Oct 26 15:54:18 2017
@@ -89,9 +89,9 @@ public final class SftpClientFactory {
                 session.setPassword(new String(password));
             }
 
-            final Integer timeout = builder.getTimeout(fileSystemOptions);
-            if (timeout != null) {
-                session.setTimeout(timeout.intValue());
+            final Integer sessionTimeout = builder.getSessionTimeoutMillis(fileSystemOptions);
+            if (sessionTimeout != null) {
+                session.setTimeout(sessionTimeout.intValue());
             }
 
             final UserInfo userInfo = builder.getUserInfo(fileSystemOptions);

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java?rev=1813421&r1=1813420&r2=1813421&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
Thu Oct 26 15:54:18 2017
@@ -51,6 +51,8 @@ public class SftpFileSystem extends Abst
     // private final JSch jSch;
 
     private ChannelSftp idleChannel;
+    
+    private final int connectTimeoutMillis;
 
     /**
      * Cache for the user ID (-1 when not set)
@@ -66,6 +68,8 @@ public class SftpFileSystem extends Abst
             final FileSystemOptions fileSystemOptions) {
         super(rootName, null, fileSystemOptions);
         this.session = session;
+        final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
+        this.connectTimeoutMillis = builder.getConnectTimeoutMillis(fileSystemOptions);
     }
 
     @Override
@@ -98,7 +102,7 @@ public class SftpFileSystem extends Abst
                 idleChannel = null;
             } else {
                 channel = (ChannelSftp) session.openChannel("sftp");
-                channel.connect();
+                channel.connect(connectTimeoutMillis);
                 final Boolean userDirIsRoot = SftpFileSystemConfigBuilder.getInstance()
                         .getUserDirIsRoot(getFileSystemOptions());
                 final String workingDirectory = getRootName().getPath();
@@ -271,7 +275,7 @@ public class SftpFileSystem extends Abst
         channel.setInputStream(null);
         try (final InputStreamReader stream = new InputStreamReader(channel.getInputStream()))
{
             channel.setErrStream(System.err, true);
-            channel.connect();
+            channel.connect(connectTimeoutMillis);
 
             // Read the stream
             final char[] buffer = new char[EXEC_BUFFER_SIZE];

Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java?rev=1813421&r1=1813420&r2=1813421&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
(original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystemConfigBuilder.java
Thu Oct 26 15:54:18 2017
@@ -30,6 +30,10 @@ import com.jcraft.jsch.UserInfo;
  * The config builder for various SFTP configuration options.
  */
 public final class SftpFileSystemConfigBuilder extends FileSystemConfigBuilder {
+    
+    private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 0;
+    private static final int DEFAULT_SESSION_TIMEOUT_MILLIS = 0;
+
     /**
      * Proxy type.
      */
@@ -78,12 +82,31 @@ public final class SftpFileSystemConfigB
         }
     }
 
+    private static final String _PREFIX = SftpFileSystemConfigBuilder.class.getName();
+
+    private static final SftpFileSystemConfigBuilder BUILDER = new SftpFileSystemConfigBuilder();
+
+    private static final String COMPRESSION = _PREFIX + "COMPRESSION";
+
+    private static final String CONNECT_TIMEOUT_MILLIS = _PREFIX + ".CONNECT_TIMEOUT_MILLIS";
+    private static final String ENCODING = _PREFIX + ".ENCODING";
+    private static final String HOST_KEY_CHECK_ASK = "ask";
+    private static final String HOST_KEY_CHECK_NO = "no";
+    private static final String HOST_KEY_CHECK_YES = "yes";
+    private static final String IDENTITIES = _PREFIX + ".IDENTITIES";
+    private static final String IDENTITY_REPOSITORY_FACTORY = _PREFIX + "IDENTITY_REPOSITORY_FACTORY";
+    private static final String KNOWN_HOSTS = _PREFIX + ".KNOWN_HOSTS";
+    private static final String PREFERRED_AUTHENTICATIONS = _PREFIX + ".PREFERRED_AUTHENTICATIONS";
+    private static final String PROXY_COMMAND = _PREFIX + ".PROXY_COMMAND";
+
+    private static final String PROXY_HOST = _PREFIX + ".PROXY_HOST";
     /** HTTP Proxy. */
     public static final ProxyType PROXY_HTTP = new ProxyType("http");
-
+    private static final String PROXY_OPTIONS = _PREFIX + ".PROXY_OPTIONS";
+    private static final String PROXY_PASSWORD = _PREFIX + ".PROXY_PASSWORD";
+    private static final String PROXY_PORT = _PREFIX + ".PROXY_PORT";
     /** SOCKS Proxy. */
     public static final ProxyType PROXY_SOCKS5 = new ProxyType("socks");
-
     /**
      * Connects to the SFTP server through a remote host reached by SSH.
      * <p>
@@ -97,33 +120,11 @@ public final class SftpFileSystemConfigB
      */
     public static final ProxyType PROXY_STREAM = new ProxyType("stream");
 
-    private static final String _PREFIX = SftpFileSystemConfigBuilder.class.getName();
-    private static final SftpFileSystemConfigBuilder BUILDER = new SftpFileSystemConfigBuilder();
-    private static final String COMPRESSION = _PREFIX + "COMPRESSION";
-    private static final String HOST_KEY_CHECK_ASK = "ask";
-    private static final String HOST_KEY_CHECK_NO = "no";
-    private static final String HOST_KEY_CHECK_YES = "yes";
-    private static final String IDENTITIES = _PREFIX + ".IDENTITIES";
-    private static final String IDENTITY_REPOSITORY_FACTORY = _PREFIX + "IDENTITY_REPOSITORY_FACTORY";
-    private static final String KNOWN_HOSTS = _PREFIX + ".KNOWN_HOSTS";
-    private static final String PREFERRED_AUTHENTICATIONS = _PREFIX + ".PREFERRED_AUTHENTICATIONS";
-
-    private static final String PROXY_HOST = _PREFIX + ".PROXY_HOST";
-    private static final String PROXY_USER = _PREFIX + ".PROXY_USER";
-    private static final String PROXY_OPTIONS = _PREFIX + ".PROXY_OPTIONS";
     private static final String PROXY_TYPE = _PREFIX + ".PROXY_TYPE";
-    private static final String PROXY_PORT = _PREFIX + ".PROXY_PORT";
-    private static final String PROXY_PASSWORD = _PREFIX + ".PROXY_PASSWORD";
-    private static final String PROXY_COMMAND = _PREFIX + ".PROXY_COMMAND";
-
+    private static final String PROXY_USER = _PREFIX + ".PROXY_USER";
+    private static final String SESSION_TIMEOUT_MILLIS = _PREFIX + ".TIMEOUT";
     private static final String STRICT_HOST_KEY_CHECKING = _PREFIX + ".STRICT_HOST_KEY_CHECKING";
-    private static final String TIMEOUT = _PREFIX + ".TIMEOUT";
     private static final String USER_DIR_IS_ROOT = _PREFIX + ".USER_DIR_IS_ROOT";
-    private static final String ENCODING = _PREFIX + ".ENCODING";
-
-    private SftpFileSystemConfigBuilder() {
-        super("sftp.");
-    }
 
     /**
      * Gets the singleton builder.
@@ -134,6 +135,10 @@ public final class SftpFileSystemConfigB
         return BUILDER;
     }
 
+    private SftpFileSystemConfigBuilder() {
+        super("sftp.");
+    }
+
     /**
      * @param opts The FileSystem options.
      * @return The names of the compression algorithms, comma-separated.
@@ -149,6 +154,16 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * @param opts The FileSystem options.
+     * @return The connect timeout value in milliseconds.
+     * @see #setConnectTimeoutMillis
+     * @since 2.3
+     */
+    public Integer getConnectTimeoutMillis(final FileSystemOptions opts) {
+        return this.getInteger(opts, CONNECT_TIMEOUT_MILLIS, DEFAULT_CONNECT_TIMEOUT_MILLIS);
+    }
+
+    /**
      * Gets the file name encoding.
      *
      * @param opts The FileSystem options.
@@ -310,6 +325,16 @@ public final class SftpFileSystemConfigB
 
     /**
      * @param opts The FileSystem options.
+     * @return The session timeout value in milliseconds.
+     * @see #setSessionTimeoutMillis
+     * @since 2.3
+     */
+    public Integer getSessionTimeoutMillis(final FileSystemOptions opts) {
+        return this.getInteger(opts, SESSION_TIMEOUT_MILLIS, DEFAULT_SESSION_TIMEOUT_MILLIS);
+    }
+
+    /**
+     * @param opts The FileSystem options.
      * @return the option value The host key checking.
      * @see #setStrictHostKeyChecking(FileSystemOptions, String)
      */
@@ -321,9 +346,11 @@ public final class SftpFileSystemConfigB
      * @param opts The FileSystem options.
      * @return The timeout value in milliseconds.
      * @see #setTimeout
+     * @deprecated Use {@link #getSessionTimeoutMillis(FileSystemOptions)}
      */
+    @Deprecated
     public Integer getTimeout(final FileSystemOptions opts) {
-        return this.getInteger(opts, TIMEOUT);
+        return this.getInteger(opts, SESSION_TIMEOUT_MILLIS);
     }
 
     /**
@@ -364,6 +391,17 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Sets the timeout value to create a Jsch connection.
+     *
+     * @param opts The FileSystem options.
+     * @param timeout The connect timeout in milliseconds.
+     * @since 2.3
+     */
+    public void setConnectTimeoutMillis(final FileSystemOptions opts, final Integer timeout)
{
+        this.setParam(opts, CONNECT_TIMEOUT_MILLIS, timeout);
+    }
+
+    /**
      * Sets the file name encoding.
      *
      * @param opts The FileSystem options.
@@ -539,6 +577,17 @@ public final class SftpFileSystemConfigB
     }
 
     /**
+     * Sets the timeout value on Jsch session.
+     *
+     * @param opts The FileSystem options.
+     * @param timeout The session timeout in milliseconds.
+     * @since 2.3
+     */
+    public void setSessionTimeoutMillis(final FileSystemOptions opts, final Integer timeout)
{
+        this.setParam(opts, SESSION_TIMEOUT_MILLIS, timeout);
+    }
+
+    /**
      * Configures the host key checking to use.
      * <p>
      * Valid arguments are: {@code "yes"}, {@code "no"} and {@code "ask"}.
@@ -566,9 +615,11 @@ public final class SftpFileSystemConfigB
      *
      * @param opts The FileSystem options.
      * @param timeout The timeout in milliseconds.
+     * @deprecated Use {@link #setSessionTimeoutMillis(FileSystemOptions, Integer)}
      */
+    @Deprecated
     public void setTimeout(final FileSystemOptions opts, final Integer timeout) {
-        this.setParam(opts, TIMEOUT, timeout);
+        this.setParam(opts, SESSION_TIMEOUT_MILLIS, timeout);
     }
 
     /**

Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1813421&r1=1813420&r2=1813421&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Thu Oct 26 15:54:18 2017
@@ -53,6 +53,9 @@ The <action> type attribute can be add,u
       <action issue="VFS-646" dev="ggregory" type="update">
         Update Apache Commons Compress from 1.14 to 1.15.
       </action>
+      <action issue="VFS-589" dev="ggregory" type="add" due-to="L, Gary Gregory">
+        SFTP moveTo operation hangs if the server does not support SSH channelExec.
+      </action>
     </release>
     <release version="2.2" date="2017-10-06" description="New features and bug fix release.">
       <action issue="VFS-642" dev="pschumacher" type="update" due-to="ilangoldfeld">



Mime
View raw message