Skip to content

Commit faf88ec

Browse files
committed
READ default mode in SftpFileSystemProvider.newFileChannel()
According to upstream javadoc, the default mode is READ (only) when there is no mode specified.
1 parent 4f36d87 commit faf88ec

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

sshd-sftp/src/main/java/org/apache/sshd/sftp/client/fs/SftpFileSystemProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options,
506506
throws IOException {
507507
Collection<OpenMode> modes = OpenMode.fromOpenOptions(options);
508508
if (modes.isEmpty()) {
509-
modes = EnumSet.of(OpenMode.Read, OpenMode.Write);
509+
modes = EnumSet.of(OpenMode.Read);
510510
}
511511
// TODO: process file attributes
512512
SftpPath p = toSftpPath(path);

sshd-sftp/src/test/java/org/apache/sshd/sftp/client/fs/AbstractSftpFilesSystemSupport.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.nio.file.NoSuchFileException;
3434
import java.nio.file.Path;
3535
import java.nio.file.StandardCopyOption;
36+
import java.nio.file.StandardOpenOption;
3637
import java.nio.file.attribute.AclEntry;
3738
import java.nio.file.attribute.AclFileAttributeView;
3839
import java.util.Collections;
@@ -189,11 +190,11 @@ protected static void testSymbolicLinks(Path link, Path relPath) throws IOExcept
189190
}
190191

191192
protected static void testFileChannelLock(Path file) throws IOException {
192-
try (FileChannel channel = FileChannel.open(file)) {
193+
try (FileChannel channel = FileChannel.open(file, StandardOpenOption.WRITE)) {
193194
try (FileLock lock = channel.lock()) {
194195
outputDebugMessage("Lock %s: %s", file, lock);
195196

196-
try (FileChannel channel2 = FileChannel.open(file)) {
197+
try (FileChannel channel2 = FileChannel.open(file, StandardOpenOption.WRITE)) {
197198
try (FileLock lock2 = channel2.lock()) {
198199
fail("Unexpected success in re-locking " + file + ": " + lock2);
199200
} catch (OverlappingFileLockException e) {

0 commit comments

Comments
 (0)