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

With some remote file systems, files can only be opened as read only #372

Open
unixwork opened this issue Jan 21, 2025 · 1 comment
Open

Comments

@unixwork
Copy link

With some file systems, for example SFTP mounted via GVFS, you can only open a file in Read Only mode, because the detection, if a file is writeable, doesn't work.

The reason is, in this case, the file system doesn't support opening a file in read/write mode, so something like open(path, O_O_RDWR) will fail with EOPNOTSUPP. However, opening the file in write only mode works, so the file is definitely writeable.

The responsible code in nedit-ng is in DocumentWidget.cpp in the DocumentWidget::doOpen method:

// detect if the file is readable, but not writable
QFile file(fullname);
if (file.open(QIODevice::ReadWrite) || file.open(QIODevice::ReadOnly)) {
	info_->lockReasons.setPermLocked(!file.isWritable());
}

The first file.open() will fail here.

A possible solution would be, to just check if the file can be opened as WriteOnly.

// detect if the file is writable
QFile file(fullname);
if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) {
	info_->lockReasons.setPermLocked(true);
}

Interestingly this is a regression, that I also had in xnedit. The original nedit is not affected, because the file is only opened in read mode, and write permissions are checked with access():

if ((fp = fopen(fullname, "r")) != NULL) {
	if(access(fullname, W_OK) != 0)
		SET_PERM_LOCKED(window->lockReasons, TRUE);
@eteran
Copy link
Owner

eteran commented Jan 22, 2025

Thanks for the heads up fellow nedit fork developer! :-) I'll take a look when I get the chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants