mirror of
https://github.com/YACReader/yacreader
synced 2025-05-25 18:00:46 -04:00
Log libraries validation when YACReaderLibrary and YACReaderLibraryServer start
This commit is contained in:
parent
c5890ca7bf
commit
8f84fc7902
@ -1097,6 +1097,52 @@ bool DataBaseManagement::updateToCurrentVersion(const QString &libraryPath)
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
DatabaseAccess DataBaseManagement::getDatabaseAccess(const QString &libraryPath)
|
||||
{
|
||||
DatabaseAccess access = { false, false, false, false };
|
||||
|
||||
auto libraryDataPath = LibraryPaths::libraryDataPath(libraryPath);
|
||||
auto libraryDatabasePath = LibraryPaths::libraryDatabasePath(libraryPath);
|
||||
|
||||
QFile libraryDatabase(libraryDatabasePath);
|
||||
if (!libraryDatabase.exists()) {
|
||||
return access;
|
||||
}
|
||||
|
||||
access.libraryExists = true;
|
||||
|
||||
QDir libraryData(libraryDataPath);
|
||||
QFile testFile(libraryData.filePath("test"));
|
||||
if (testFile.open(QIODevice::WriteOnly)) {
|
||||
access.canWriteToFolder = true;
|
||||
testFile.close();
|
||||
testFile.remove();
|
||||
}
|
||||
|
||||
QString connectionName = "test";
|
||||
{
|
||||
QSqlDatabase db = DataBaseManagement::loadDatabaseFromFile(libraryDatabasePath);
|
||||
|
||||
QSqlQuery versionQuery(db);
|
||||
bool read = versionQuery.exec("SELECT version FROM db_info");
|
||||
|
||||
read = read && versionQuery.next();
|
||||
read = read && !versionQuery.record().value(0).toString().isEmpty();
|
||||
|
||||
access.canRead = read;
|
||||
|
||||
QSqlQuery writeQuery(db);
|
||||
bool write = db.transaction();
|
||||
write = write && writeQuery.exec("CREATE TABLE test_write (id INTEGER);");
|
||||
write = write && db.rollback();
|
||||
|
||||
access.canWrite = write;
|
||||
}
|
||||
QSqlDatabase::removeDatabase(connectionName);
|
||||
|
||||
return access;
|
||||
}
|
||||
|
||||
// COMICS_INFO_EXPORTER
|
||||
ComicsInfoExporter::ComicsInfoExporter()
|
||||
: QThread()
|
||||
|
@ -29,6 +29,27 @@ private:
|
||||
void run() override;
|
||||
};
|
||||
|
||||
struct DatabaseAccess {
|
||||
bool libraryExists;
|
||||
bool canRead; // db read
|
||||
bool canWrite; // db write
|
||||
bool canWriteToFolder; // disk write
|
||||
|
||||
operator QString() const
|
||||
{
|
||||
if (libraryExists && canRead && canWrite && canWriteToFolder) {
|
||||
return "OK";
|
||||
} else if (!libraryExists) {
|
||||
return "WARNING! Library does not exist on disk";
|
||||
} else {
|
||||
return QString("WARNING! DB read access: %1, DB write access: %2, can write to disk: %3")
|
||||
.arg(canRead ? "YES" : "NO")
|
||||
.arg(canWrite ? "YES" : "NO")
|
||||
.arg(canWriteToFolder ? "YES" : "NO");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class DataBaseManagement : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -58,6 +79,8 @@ public:
|
||||
static QString checkValidDB(const QString &fullPath); // retorna "" si la DB es inválida ó la versión si es válida.
|
||||
static int compareVersions(const QString &v1, const QString v2); // retorna <0 si v1 < v2, 0 si v1 = v2 y >0 si v1 > v2
|
||||
static bool updateToCurrentVersion(const QString &libraryPath);
|
||||
|
||||
static DatabaseAccess getDatabaseAccess(const QString &libraryPath);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "yacreader_http_server.h"
|
||||
#include "yacreader_local_server.h"
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_libraries.h"
|
||||
#include "exit_check.h"
|
||||
@ -85,7 +86,13 @@ void logSystemAndConfig()
|
||||
OpenGLChecker checker;
|
||||
QLOG_INFO() << "OpenGL version : " << checker.textVersionDescription();
|
||||
|
||||
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries();
|
||||
auto libraries = DBHelper::getLibraries().getLibraries();
|
||||
QLOG_INFO() << "Libraries: ";
|
||||
for (auto library : libraries) {
|
||||
QLOG_INFO() << " " << library;
|
||||
auto access = DataBaseManagement::getDatabaseAccess(library.getPath());
|
||||
QLOG_INFO() << " > STATUS: " << access;
|
||||
}
|
||||
QLOG_INFO() << "--------------------------------------------";
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QImageReader>
|
||||
|
||||
#include "comic_db.h"
|
||||
#include "data_base_management.h"
|
||||
#include "db_helper.h"
|
||||
#include "yacreader_http_server.h"
|
||||
#include "yacreader_global.h"
|
||||
@ -461,7 +462,14 @@ void logSystemAndConfig()
|
||||
for (const auto &line : globalInfo.split("\n")) {
|
||||
QLOG_INFO() << line;
|
||||
}
|
||||
QLOG_INFO() << "Libraries: " << DBHelper::getLibraries().getLibraries();
|
||||
|
||||
auto libraries = DBHelper::getLibraries().getLibraries();
|
||||
QLOG_INFO() << "Libraries: ";
|
||||
for (auto library : libraries) {
|
||||
QLOG_INFO() << " " << library;
|
||||
auto access = DataBaseManagement::getDatabaseAccess(library.getPath());
|
||||
QLOG_INFO() << " > STATUS: " << access;
|
||||
}
|
||||
QLOG_INFO() << "--------------------------------------------";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user