Skip to content

Commit

Permalink
READ default mode in SftpFileSystemProvider.newFileChannel() (#372)
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 authored Jun 3, 2023
1 parent aa592cd commit 99a7923
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 @@ -579,7 +579,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 99a7923

Please sign in to comment.