From d8a166ea60bfb959377042fdb097fbcdcc1ede94 Mon Sep 17 00:00:00 2001
From: Salanto <62221668+Salanto@users.noreply.github.com>
Date: Mon, 4 Oct 2021 22:17:24 +0200
Subject: [PATCH] Fix database permission error when database is first created

It was apparently perfectly acceptable to some that it shows an error when the file did not even have a chance to exist.
---
 core/src/db_manager.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/core/src/db_manager.cpp b/core/src/db_manager.cpp
index 8666596..0fd3a4d 100644
--- a/core/src/db_manager.cpp
+++ b/core/src/db_manager.cpp
@@ -22,8 +22,14 @@ DBManager::DBManager() :
 {
     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);
+    if (!db_info.exists()) {
+        qWarning().noquote() << tr("Database Info: Database not found. Attempting to create new database.");
+    }
+    else {
+        //We should only check if a file is readable/writeable when it actually exists.
+        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");