From 408b5b82b2d45e3f740200b4b11ff82a48f38d33 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 21 Jan 2026 20:09:41 +0000 Subject: [PATCH] Allow absolute path in dbfilename --- Storage/Sqlite.cpp | 27 ++++++++++++++------------- Utils/Utils.cpp | 26 ++++++++++++++++++++------ 2 files changed, 34 insertions(+), 19 deletions(-) Index: railcontrol/Storage/Sqlite.cpp =================================================================== --- railcontrol.orig/Storage/Sqlite.cpp 2026-01-25 04:36:43.024717955 +0100 +++ railcontrol/Storage/Sqlite.cpp 2026-01-25 04:36:43.022113205 +0100 @@ -59,7 +59,7 @@ map tablenames; const char* query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; bool ret = Execute(query, CallbackListTables, &tablenames); - if (ret == false) + if (!ret) { return; } @@ -68,7 +68,7 @@ if (tablenames["hardware"] == false) { bool ret = CreateTableHardware(); - if (ret == false) + if (!ret) { return; } @@ -78,7 +78,7 @@ if (tablenames["objects"] == false) { bool ret = CreateTableObjects(); - if (ret == false) + if (!ret) { return; } @@ -90,10 +90,11 @@ { ret = CheckTableRelations(); } - else { + else + { ret = CreateTableRelations(tableNameRelations); } - if (ret == false) + if (!ret) { return; } @@ -102,7 +103,7 @@ if (tablenames["settings"] == false) { bool ret = CreateTableSettings(); - if (ret == false) + if (!ret) { return; } @@ -112,7 +113,7 @@ SQLite::~SQLite() { - if (db == nullptr) + if (!db) { return; } @@ -215,7 +216,7 @@ vector tableInfos; string query = "PRAGMA table_info('relations');"; bool ret = Execute(query, CallbackTableInfo, &tableInfos); - if (ret == false) + if (!ret) { return false; } @@ -234,7 +235,7 @@ // FIXME: simple check, extend with check if each object really exists query = "DELETE FROM relations WHERE objectid1 like 0;"; ret = Execute(query); - if (ret == false) + if (!ret) { return false; } @@ -248,19 +249,19 @@ const string tableName = "relations"; const string tempTableName = "relations_temp"; bool ret = CreateTableRelations(tempTableName); - if (ret == false) + if (!ret) { return false; } logger->Info(Languages::TextCopyingFromTo, tableName, tempTableName); const string query = "INSERT INTO " + tempTableName + " SELECT objecttype1 * 8, objectid1, objecttype2, objectid2, priority, relation FROM " + tableName + ";"; ret = Execute(query); - if (ret == false) + if (!ret) { return false; } ret = DropTable(tableName); - if (ret == false) + if (!ret) { return false; } @@ -448,7 +449,7 @@ bool SQLite::Execute(const char* query, sqlite3_callback callback = nullptr, void* result = nullptr) { - if (db == nullptr) + if (!db) { return false; } Index: railcontrol/Utils/Utils.cpp =================================================================== --- railcontrol.orig/Utils/Utils.cpp 2026-01-25 04:36:43.024717955 +0100 +++ railcontrol/Utils/Utils.cpp 2026-01-25 04:44:50.460364920 +0100 @@ -212,17 +212,30 @@ } void Utils::RemoveOldBackupFiles (Logger::Logger *logger, - const std::string &filename, + const string &pathFile, unsigned int keepBackups) { - DIR *dir = opendir("."); + size_t posDirSeperator = pathFile.find_last_of('/'); + DIR* dir; + string path; + string file; + if (posDirSeperator == string::npos) + { + file = pathFile; + } + else + { + path = pathFile.substr(0, posDirSeperator + 1); + file = pathFile.substr(posDirSeperator + 1); + } + dir= opendir(path.length() ? path.c_str() : "."); if (dir == nullptr) { return; } struct dirent *ent; std::vector < string > fileNames; - const string filenameSearch = filename + "."; + const string filenameSearch = file + "."; const size_t filenameSearchLength = filenameSearch.length() + 10; while (true) { @@ -231,7 +244,7 @@ { break; } - string fileName = ent->d_name; + const string fileName = ent->d_name; if (fileName.length() != filenameSearchLength || fileName.find(filenameSearch) == string::npos) { continue; @@ -257,8 +270,9 @@ } --removeBackups; - logger->Info(Languages::TextRemoveBackupFile, fileName); - remove(fileName.c_str()); + const string fileToDelete(path + fileName); + logger->Info(Languages::TextRemoveBackupFile, fileToDelete); + remove(fileToDelete.c_str()); } }