From 4d62e4b82a2c797e5fec8c24c7715790fd7cddd7 Mon Sep 17 00:00:00 2001 From: Martin Kleusberg Date: Mon, 13 Jul 2020 22:54:20 +0200 Subject: [PATCH] dbhub: Make sure the directories for the remote code exist When the directories for the cloned remote databases or for our meta database do not yet exist create them. See issue #2327. --- src/PreferencesDialog.cpp | 2 +- src/RemoteDatabase.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PreferencesDialog.cpp b/src/PreferencesDialog.cpp index dc29050f..fcedaf99 100644 --- a/src/PreferencesDialog.cpp +++ b/src/PreferencesDialog.cpp @@ -644,7 +644,7 @@ void PreferencesDialog::chooseRemoteCloneDirectory() tr("Choose a directory"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - if(!s.isEmpty()) + if(!s.isEmpty() && QDir().mkpath(s)) ui->editRemoteCloneDirectory->setText(s); } diff --git a/src/RemoteDatabase.cpp b/src/RemoteDatabase.cpp index 666bed7d..8b9d82ce 100644 --- a/src/RemoteDatabase.cpp +++ b/src/RemoteDatabase.cpp @@ -646,14 +646,18 @@ void RemoteDatabase::localAssureOpened() if(m_dbLocal) return; - // Open file - QString database_file = QStandardPaths::writableLocation( + // Make sure the directory exists + QString database_directory = QStandardPaths::writableLocation( #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) QStandardPaths::AppDataLocation #else QStandardPaths::GenericDataLocation #endif - ) + "/remotedbs.db"; + ); + QDir().mkpath(database_directory); + + // Open file + QString database_file = database_directory + "/remotedbs.db"; if(sqlite3_open_v2(database_file.toUtf8(), &m_dbLocal, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr) != SQLITE_OK) { QMessageBox::warning(nullptr, qApp->applicationName(), tr("Error opening local databases list.\n%1").arg(QString::fromUtf8(sqlite3_errmsg(m_dbLocal))));