Skip to content

Commit

Permalink
READ default mode in SftpFileSystemProvider.newFileChannel()
Browse files Browse the repository at this point in the history
According to upstream javadoc, the default mode is READ (only) when there is no mode specified.
  • Loading branch information
hannibal218bc committed May 31, 2023
1 parent 4f36d87 commit faf88ec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public FileChannel newFileChannel(Path path, Set<? extends OpenOption> options,
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -189,11 +190,11 @@ protected static void testSymbolicLinks(Path link, Path relPath) throws IOExcept
}

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) {
Expand Down

0 comments on commit faf88ec

Please sign in to comment.