Skip to content

Commit 73ca7d6

Browse files
authored
Merge branch 'master' into master
2 parents 03a0a9d + fe6c41b commit 73ca7d6

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

src/widgets/window.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -675,15 +675,22 @@ void Window::addTab(const QString &filepath, bool activeTab)
675675
}
676676
}
677677

678-
// check if have permission to read the file.
679-
bool bIsReadable = fileInfo.isReadable();
680-
qDebug() << "File readable:" << bIsReadable;
681-
682-
if (fileInfo.exists() && !bIsReadable) {
683-
qWarning() << "No permission to read file:" << filepath;
684-
DMessageManager::instance()->sendMessage(m_editorWidget->currentWidget(), QIcon(":/images/warning.svg")
685-
, QString(tr("You do not have permission to open %1")).arg(filepath));
686-
return;
678+
// Verify the file is actually readable by attempting to open it.
679+
// This is more reliable than QFileInfo::isReadable(), which can be incorrect
680+
// in some edge cases (e.g. setuid processes, certain filesystems).
681+
if (fileInfo.exists()) {
682+
QFile testFile(filepath);
683+
if (testFile.open(QIODevice::ReadOnly)) {
684+
testFile.close();
685+
} else if (testFile.error() == QFileDevice::PermissionsError) {
686+
qWarning() << "No permission to read file:" << filepath << "error:" << testFile.errorString();
687+
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
688+
DMessageManager::instance()->sendMessage(msgParent, QIcon(":/images/warning.svg"),
689+
QString(tr("You do not have permission to open %1")).arg(filepath));
690+
return;
691+
} else {
692+
qWarning() << "Failed to open file:" << filepath << "error:" << testFile.errorString();
693+
}
687694
}
688695

689696
if (StartManager::instance()->checkPath(filepath)) {

0 commit comments

Comments
 (0)