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

SftpFileSystemProvider.newFileChannel() uses wrong default mode #383

Closed
tomaswolf opened this issue May 29, 2023 · 5 comments · Fixed by #389
Closed

SftpFileSystemProvider.newFileChannel() uses wrong default mode #383

tomaswolf opened this issue May 29, 2023 · 5 comments · Fixed by #389
Labels
bug An issue describing a bug in the code
Milestone

Comments

@tomaswolf
Copy link
Member

Version

master

Bug description

According to the contract of FileSystemProvider.newFileChannel() per its javadoc, the channel is opened read-only if no OpenOptions are passed.

SftpFileSystemProvider opens the channel in read-write mode in this case.

Actual behavior

Channel is opened read-write, which fails if the remote file is read-only.

Expected behavior

Channel is opened read-only if SftpFileSystemProvider.newFileChannel(path) is called without OpenOptions.

Relevant log output

No response

Other information

No response

@tomaswolf tomaswolf added this to the 2.10.1 milestone May 29, 2023
@tomaswolf tomaswolf added the bug An issue describing a bug in the code label May 29, 2023
@hannibal218bc
Copy link
Contributor

Hi,

thank you for taking care of this issue. Sorry for nickpicking, but the description "the channel is opened read-only if no OpenOptions are passed" is not correct.

The contract actually is "If neither option (WRITE or APPEND, ed.) is contained in the array then the file is opened for reading".

@tomaswolf
Copy link
Member Author

Yes, but I would not read this too literally. All the other options imply write access, don't they?

@hannibal218bc
Copy link
Contributor

Yes, but I would not read this too literally. All the other options imply write access, don't they?

I thought specs are meant to be taken literally ;-) but yes, I agree that e.g. SYNC probably isn't useful on a read-only file. However, I think with e.g. CREATE it is not that clear.

@tomaswolf
Copy link
Member Author

No sure there's a use case for CREATE, READ. For now I think your change #372 is fine (setting READ if no options). We can change it later to "set READ if neither WRITE nor APPEND present", if needed, but then that should probably be done in other places as well.

Do you want to fix the failing tests? I prefer to have master working at any commit, so if you could amend your commit, that'd be great; then I could merge it.

@hannibal218bc
Copy link
Contributor

Sure, I've just force-pushed faf88ec , could you please approve the action workflow run? 👍

tomaswolf added a commit to tomaswolf/mina-sshd that referenced this issue Jun 3, 2023
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 added a commit to tomaswolf/mina-sshd that referenced this issue Jun 5, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue describing a bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants