nedit-ng icon indicating copy to clipboard operation
nedit-ng copied to clipboard

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

Open unixwork opened this issue 11 months ago • 1 comments

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);

unixwork avatar Jan 21 '25 11:01 unixwork

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

eteran avatar Jan 22 '25 01:01 eteran