From a18ecfd633e9d94ccf5dbf03dda6317bfa42de2b Mon Sep 17 00:00:00 2001 From: t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r <88607531+t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r@users.noreply.github.com> Date: Sun, 8 Aug 2021 07:48:32 +0200 Subject: [PATCH 1/6] add access() --- core/include/db_manager.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/include/db_manager.h b/core/include/db_manager.h index fcc5f4a..1d3bd21 100644 --- a/core/include/db_manager.h +++ b/core/include/db_manager.h @@ -30,6 +30,17 @@ #include #include +#if defined(_WIN32) + #include + #define access(pathname, mode) _access(pathname, mode) + +#elif __unix__ + #include + +#else + #define access(pathname, mode) 1 + +#endif /** * @brief A class used to handle database interaction. * From 5bfce457678b31f30929f6b2955ef120853844fd Mon Sep 17 00:00:00 2001 From: t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r <88607531+t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r@users.noreply.github.com> Date: Sun, 8 Aug 2021 07:53:58 +0200 Subject: [PATCH 2/6] check if db is writable before using it clearer error messages --- core/src/db_manager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/db_manager.cpp b/core/src/db_manager.cpp index d8e2ace..d295749 100644 --- a/core/src/db_manager.cpp +++ b/core/src/db_manager.cpp @@ -20,6 +20,9 @@ DBManager::DBManager() : DRIVER("QSQLITE") { + if(!access("config/akashi.db", R_OK | W_OK)) + qCritical() << "Database Error: Missing permissions. Check if \"" + "config/akashi.db" "\" is writable.\n"; + db = QSqlDatabase::addDatabase(DRIVER); db.setDatabaseName("config/akashi.db"); if (!db.open()) From a94dce496da92e76476d67813edfad2e9436612e Mon Sep 17 00:00:00 2001 From: t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r <88607531+t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r@users.noreply.github.com> Date: Sun, 8 Aug 2021 07:57:13 +0200 Subject: [PATCH 3/6] sigh --- core/src/db_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/db_manager.cpp b/core/src/db_manager.cpp index d295749..66bd1be 100644 --- a/core/src/db_manager.cpp +++ b/core/src/db_manager.cpp @@ -21,7 +21,7 @@ DBManager::DBManager() : DRIVER("QSQLITE") { if(!access("config/akashi.db", R_OK | W_OK)) - qCritical() << "Database Error: Missing permissions. Check if \"" + "config/akashi.db" "\" is writable.\n"; + qCritical() << "Database Error: Missing permissions. Check if \"config/akashi.db\" is writable.\n"; db = QSqlDatabase::addDatabase(DRIVER); db.setDatabaseName("config/akashi.db"); From 23b5962e2a00f72a77c0e850dbceca8b16567bdd Mon Sep 17 00:00:00 2001 From: t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r <88607531+t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r@users.noreply.github.com> Date: Sun, 8 Aug 2021 08:04:02 +0200 Subject: [PATCH 4/6] defined --- core/include/db_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/include/db_manager.h b/core/include/db_manager.h index 1d3bd21..847faba 100644 --- a/core/include/db_manager.h +++ b/core/include/db_manager.h @@ -34,7 +34,7 @@ #include #define access(pathname, mode) _access(pathname, mode) -#elif __unix__ +#elif defined(__unix__) #include #else From a624fd502ac198abc07326f0dd784c063a2dcaa2 Mon Sep 17 00:00:00 2001 From: cancer Date: Sun, 8 Aug 2021 21:12:03 +0300 Subject: [PATCH 5/6] do it with qt --- core/include/db_manager.h | 12 +----------- core/src/db_manager.cpp | 6 +++++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/core/include/db_manager.h b/core/include/db_manager.h index 847faba..2e26f95 100644 --- a/core/include/db_manager.h +++ b/core/include/db_manager.h @@ -29,18 +29,8 @@ #include #include #include +#include -#if defined(_WIN32) - #include - #define access(pathname, mode) _access(pathname, mode) - -#elif defined(__unix__) - #include - -#else - #define access(pathname, mode) 1 - -#endif /** * @brief A class used to handle database interaction. * diff --git a/core/src/db_manager.cpp b/core/src/db_manager.cpp index 66bd1be..7acb899 100644 --- a/core/src/db_manager.cpp +++ b/core/src/db_manager.cpp @@ -20,8 +20,12 @@ DBManager::DBManager() : DRIVER("QSQLITE") { - if(!access("config/akashi.db", R_OK | W_OK)) + QFileInfo *db_info = new QFileInfo; + *db_info = QFileInfo("config/akashi.db"); + if(!(db_info->isReadable()) || !(db_info->isWritable())) qCritical() << "Database Error: Missing permissions. Check if \"config/akashi.db\" is writable.\n"; + delete db_info; + db = QSqlDatabase::addDatabase(DRIVER); db.setDatabaseName("config/akashi.db"); From fd250ee13d39a3d16bf673749de24be453edee86 Mon Sep 17 00:00:00 2001 From: t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r <88607531+t-h-i-s-u-s-e-r-n-a-m-e-i-s-c-a-n-c-e-r@users.noreply.github.com> Date: Mon, 9 Aug 2021 17:56:59 +0200 Subject: [PATCH 6/6] thanks Co-authored-by: oldmud0 --- core/src/db_manager.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/src/db_manager.cpp b/core/src/db_manager.cpp index 7acb899..7de8104 100644 --- a/core/src/db_manager.cpp +++ b/core/src/db_manager.cpp @@ -20,12 +20,10 @@ DBManager::DBManager() : DRIVER("QSQLITE") { - QFileInfo *db_info = new QFileInfo; - *db_info = QFileInfo("config/akashi.db"); - if(!(db_info->isReadable()) || !(db_info->isWritable())) - qCritical() << "Database Error: Missing permissions. Check if \"config/akashi.db\" is writable.\n"; - delete db_info; - + const QString db_filename = "config/akashi.db"; + QFileInfo db_info(db_filename); + if(!db_info.isReadable() || !db_info.isWritable()) + qCritical() << tr("Database Error: Missing permissions. Check if \"%1\" is writable.").arg(db_filename); db = QSqlDatabase::addDatabase(DRIVER); db.setDatabaseName("config/akashi.db");