Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SftpFileSystem: Open Modes & FileChannel locks #389

Merged
merged 2 commits into from
Jun 5, 2023

Commits on Jun 5, 2023

  1. apacheGH-383: SFTP: tighten modes for file channels and streams

    As pointed out in apache#283, FileSystemProvider.newFileChannel(...) uses
    READ as default not only when no options are given, but always when
    neither WRITE nor APPEND are present.
    
    Also tighten some other rules, and fail if write modes are specified
    in newInputStream(...).
    
    Bug: apache#383
    tomaswolf committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    a14d27b View commit details
    Browse the repository at this point in the history
  2. apacheGH-384: SFTP: improve FileChannel locking

    SSH_FXP_BLOCK is available only in SFTPv6. It was introduced in draft
    08. Throw an UnsupportedOperationException if the negotiated SFTP
    version is lower.
    
    Respect the contract of FileChannel.lock(): a shared lock can be
    requested only if the channel was opened for reading, and an exclusive
    lock only if the channel is writable. Check this, and throw appropriate
    exceptions if the condition is violated.
    
    Pass on the correct lock flags to the server. At the server, repeat the
    version check, and respect the flags passed. Since Java does not have
    delete locks we map them to write locks. The draft RFC[1] is silent on
    what to do if no flags are passed at all: we use an exclusive  write
    lock if the handle was opened for writing, and a shared read lock
    otherwise. We cannot throw an exception since we must be able to support
    old Apache MINA sshd clients that sent zero as lock flags.
    
    [1] https://www.ietf.org/archive/id/draft-ietf-secsh-filexfer-13.txt
    
    Bug: apache#384
    tomaswolf committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    e225862 View commit details
    Browse the repository at this point in the history