From de5ba7bd0c349c49fb5d794a8eb06faa38a8504e Mon Sep 17 00:00:00 2001 From: Oleg Shparber Date: Tue, 26 May 2020 01:37:32 -0400 Subject: [PATCH] fix(ui): fix docset storage writable check Checks if the directly is writable by attempting to write. Fixes #1036 and #1059. --- src/libs/ui/docsetsdialog.cpp | 24 +++++++++++++----------- src/libs/ui/docsetsdialog.h | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/libs/ui/docsetsdialog.cpp b/src/libs/ui/docsetsdialog.cpp index 99ec539..fd3f268 100644 --- a/src/libs/ui/docsetsdialog.cpp +++ b/src/libs/ui/docsetsdialog.cpp @@ -78,16 +78,7 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent) loadDocsetList(); -#ifdef Q_OS_WIN32 - qt_ntfs_permission_lookup++; -#endif - - const QFileInfo fi(m_application->settings()->docsetPath); - m_isStorageReadOnly = !fi.isWritable(); - -#ifdef Q_OS_WIN32 - qt_ntfs_permission_lookup--; -#endif + m_isStorageReadOnly = !isDirWritable(m_application->settings()->docsetPath); #ifdef Q_OS_MACOS ui->availableDocsetList->setAttribute(Qt::WA_MacShowFocusRect, false); @@ -96,6 +87,8 @@ DocsetsDialog::DocsetsDialog(Core::Application *app, QWidget *parent) ui->statusLabel->clear(); // Clear text shown in the designer mode. ui->storageStatusLabel->setVisible(m_isStorageReadOnly); + + const QFileInfo fi(m_application->settings()->docsetPath); ui->storageStatusLabel->setText(fi.exists() ? tr("Docset storage is read only.") : tr("Docset storage does not exist.")); @@ -636,7 +629,10 @@ void DocsetsDialog::enableControls() void DocsetsDialog::disableControls() { // Dialog buttons. - ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel); + if (!m_isStorageReadOnly) { + // Always show the close button if storage is read only. + ui->buttonBox->setStandardButtons(QDialogButtonBox::Cancel); + } // Installed docsets ui->addFeedButton->setEnabled(false); @@ -844,3 +840,9 @@ QString DocsetsDialog::cacheLocation(const QString &fileName) { return QDir(Core::Application::cacheLocation()).filePath(fileName); } + +bool DocsetsDialog::isDirWritable(const QString &path) +{ + auto file = std::make_unique(path + QLatin1String("/.zeal_writable_check_XXXXXX.tmp")); + return file->open(); +} diff --git a/src/libs/ui/docsetsdialog.h b/src/libs/ui/docsetsdialog.h index 4188ea5..f6557f8 100644 --- a/src/libs/ui/docsetsdialog.h +++ b/src/libs/ui/docsetsdialog.h @@ -125,6 +125,7 @@ private: static inline int percent(qint64 fraction, qint64 total); static QString cacheLocation(const QString &fileName); + static bool isDirWritable(const QString &path); }; } // namespace WidgetUi