READ default mode in SftpFileSystemProvider.newFileChannel() (#372)
According to upstream javadoc, the default mode is READ (only) when there is no mode specified.
diff --git a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java
index 06f5f30..9eb9246 100644
--- a/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java
+++ b/sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java
@@ -579,7 +579,7 @@
throws IOException {
Collection<OpenMode> modes = OpenMode.fromOpenOptions(options);
if (modes.isEmpty()) {
- modes = EnumSet.of(OpenMode.Read, OpenMode.Write);
+ modes = EnumSet.of(OpenMode.Read);
}
// TODO: process file attributes
SftpPath p = toSftpPath(path);
diff --git a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/fs/AbstractSftpFilesSystemSupport.java b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/fs/AbstractSftpFilesSystemSupport.java
index 9c71dfb..b589ac2 100644
--- a/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/fs/AbstractSftpFilesSystemSupport.java
+++ b/sshd-sftp/src/test/java/org/apache/sshd/sftp/client/fs/AbstractSftpFilesSystemSupport.java
@@ -33,6 +33,7 @@
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+import java.nio.file.StandardOpenOption;
import java.nio.file.attribute.AclEntry;
import java.nio.file.attribute.AclFileAttributeView;
import java.util.Collections;
@@ -189,11 +190,11 @@
}
protected static void testFileChannelLock(Path file) throws IOException {
- try (FileChannel channel = FileChannel.open(file)) {
+ try (FileChannel channel = FileChannel.open(file, StandardOpenOption.WRITE)) {
try (FileLock lock = channel.lock()) {
outputDebugMessage("Lock %s: %s", file, lock);
- try (FileChannel channel2 = FileChannel.open(file)) {
+ try (FileChannel channel2 = FileChannel.open(file, StandardOpenOption.WRITE)) {
try (FileLock lock2 = channel2.lock()) {
fail("Unexpected success in re-locking " + file + ": " + lock2);
} catch (OverlappingFileLockException e) {