diff --git a/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPContext.java b/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPContext.java index c7d1733..6b706cb 100644 --- a/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPContext.java +++ b/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPContext.java @@ -37,6 +37,7 @@ public class SFTPContext implements Closeable { @Override public void close() throws IOException { sshClient.stop(); + sshClient.close(); fileSystem.close(); } } diff --git a/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPFileService.java b/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPFileService.java index 3854a12..c556012 100644 --- a/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPFileService.java +++ b/files-sftp-fs/src/main/java/org/apache/sshd/fs/spi/SFTPFileService.java @@ -472,8 +472,4 @@ public class SFTPFileService implements FileService { } } } - - private T performWithoutClose(SFTPContext ctx, WithContext action) throws IOException { - return action.perform(ctx); - } } diff --git a/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/FileServiceProviderTest.java b/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/FileServiceProviderTest.java index 49a1038..90b17a0 100644 --- a/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/FileServiceProviderTest.java +++ b/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/FileServiceProviderTest.java @@ -1,18 +1,26 @@ package org.apache.sshd.fs.test; +import java.nio.file.Path; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.xbib.files.FileService; -import java.io.IOException; import java.util.Map; import java.util.logging.Logger; public class FileServiceProviderTest { @Test - public void testSFTP() throws IOException { + public void testSFTP() throws Exception { Map env = Map.of("username", "joerg"); FileService fs = FileService.newInstance("sftp://alkmene:22", env); - fs.list(".").forEach(p -> Logger.getAnonymousLogger().info(p.toString())); + // close() is essential! + try (Stream list = fs.list(".")) { + list.forEach(p -> Logger.getAnonymousLogger().info(p.toString())); + } + // see if a second run still works + try (Stream list = fs.list(".")) { + list.forEach(p -> Logger.getAnonymousLogger().info(p.toString())); + } } } diff --git a/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/SFTPFileSystemTest.java b/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/SFTPFileSystemTest.java index 4f2b7b8..296145f 100644 --- a/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/SFTPFileSystemTest.java +++ b/files-sftp-fs/src/test/java/org/apache/sshd/fs/test/SFTPFileSystemTest.java @@ -37,5 +37,6 @@ public class SFTPFileSystemTest { fileSystem.close(); // ... sshClient.stop(); + sshClient.close(); } } diff --git a/files-sftp/src/main/java/org/apache/sshd/client/SshClient.java b/files-sftp/src/main/java/org/apache/sshd/client/SshClient.java index 6156106..1a0858a 100644 --- a/files-sftp/src/main/java/org/apache/sshd/client/SshClient.java +++ b/files-sftp/src/main/java/org/apache/sshd/client/SshClient.java @@ -652,7 +652,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa protected SshFutureListener createConnectCompletionListener( ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, boolean useDefaultIdentities) { - return new SshFutureListener() { + return new SshFutureListener<>() { @Override @SuppressWarnings("synthetic-access") public void operationComplete(IoConnectFuture future) { @@ -660,7 +660,6 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa connectFuture.cancel(); return; } - Throwable t = future.getException(); if (t != null) { connectFuture.setException(t); diff --git a/files-sftp/src/main/java/org/apache/sshd/common/Closeable.java b/files-sftp/src/main/java/org/apache/sshd/common/Closeable.java index 5c6957c..196c8ae 100644 --- a/files-sftp/src/main/java/org/apache/sshd/common/Closeable.java +++ b/files-sftp/src/main/java/org/apache/sshd/common/Closeable.java @@ -20,7 +20,6 @@ package org.apache.sshd.common; import java.io.IOException; import java.net.SocketTimeoutException; -import java.nio.channels.Channel; import java.time.Duration; import org.apache.sshd.common.future.CloseFuture; diff --git a/gradle.properties b/gradle.properties index 679ab81..db9b33d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ group = org.xbib name = files -version = 4.4.0 +version = 4.5.0