| 1 |
From 408b5b82b2d45e3f740200b4b11ff82a48f38d33 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Teddy <[email protected]> |
| 3 |
Date: Wed, 21 Jan 2026 20:09:41 +0000 |
| 4 |
Subject: [PATCH] Allow absolute path in dbfilename |
| 5 |
|
| 6 |
--- |
| 7 |
Storage/Sqlite.cpp | 27 ++++++++++++++------------- |
| 8 |
Utils/Utils.cpp | 26 ++++++++++++++++++++------ |
| 9 |
2 files changed, 34 insertions(+), 19 deletions(-) |
| 10 |
|
| 11 |
Index: railcontrol/Storage/Sqlite.cpp |
| 12 |
=================================================================== |
| 13 |
--- railcontrol.orig/Storage/Sqlite.cpp 2026-01-25 04:36:43.024717955 +0100 |
| 14 |
+++ railcontrol/Storage/Sqlite.cpp 2026-01-25 04:36:43.022113205 +0100 |
| 15 |
@@ -59,7 +59,7 @@ |
| 16 |
map<string, bool> tablenames; |
| 17 |
const char* query = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;"; |
| 18 |
bool ret = Execute(query, CallbackListTables, &tablenames); |
| 19 |
- if (ret == false) |
| 20 |
+ if (!ret) |
| 21 |
{ |
| 22 |
return; |
| 23 |
} |
| 24 |
@@ -68,7 +68,7 @@ |
| 25 |
if (tablenames["hardware"] == false) |
| 26 |
{ |
| 27 |
bool ret = CreateTableHardware(); |
| 28 |
- if (ret == false) |
| 29 |
+ if (!ret) |
| 30 |
{ |
| 31 |
return; |
| 32 |
} |
| 33 |
@@ -78,7 +78,7 @@ |
| 34 |
if (tablenames["objects"] == false) |
| 35 |
{ |
| 36 |
bool ret = CreateTableObjects(); |
| 37 |
- if (ret == false) |
| 38 |
+ if (!ret) |
| 39 |
{ |
| 40 |
return; |
| 41 |
} |
| 42 |
@@ -90,10 +90,11 @@ |
| 43 |
{ |
| 44 |
ret = CheckTableRelations(); |
| 45 |
} |
| 46 |
- else { |
| 47 |
+ else |
| 48 |
+ { |
| 49 |
ret = CreateTableRelations(tableNameRelations); |
| 50 |
} |
| 51 |
- if (ret == false) |
| 52 |
+ if (!ret) |
| 53 |
{ |
| 54 |
return; |
| 55 |
} |
| 56 |
@@ -102,7 +103,7 @@ |
| 57 |
if (tablenames["settings"] == false) |
| 58 |
{ |
| 59 |
bool ret = CreateTableSettings(); |
| 60 |
- if (ret == false) |
| 61 |
+ if (!ret) |
| 62 |
{ |
| 63 |
return; |
| 64 |
} |
| 65 |
@@ -112,7 +113,7 @@ |
| 66 |
|
| 67 |
SQLite::~SQLite() |
| 68 |
{ |
| 69 |
- if (db == nullptr) |
| 70 |
+ if (!db) |
| 71 |
{ |
| 72 |
return; |
| 73 |
} |
| 74 |
@@ -215,7 +216,7 @@ |
| 75 |
vector<TableInfo> tableInfos; |
| 76 |
string query = "PRAGMA table_info('relations');"; |
| 77 |
bool ret = Execute(query, CallbackTableInfo, &tableInfos); |
| 78 |
- if (ret == false) |
| 79 |
+ if (!ret) |
| 80 |
{ |
| 81 |
return false; |
| 82 |
} |
| 83 |
@@ -234,7 +235,7 @@ |
| 84 |
// FIXME: simple check, extend with check if each object really exists |
| 85 |
query = "DELETE FROM relations WHERE objectid1 like 0;"; |
| 86 |
ret = Execute(query); |
| 87 |
- if (ret == false) |
| 88 |
+ if (!ret) |
| 89 |
{ |
| 90 |
return false; |
| 91 |
} |
| 92 |
@@ -248,19 +249,19 @@ |
| 93 |
const string tableName = "relations"; |
| 94 |
const string tempTableName = "relations_temp"; |
| 95 |
bool ret = CreateTableRelations(tempTableName); |
| 96 |
- if (ret == false) |
| 97 |
+ if (!ret) |
| 98 |
{ |
| 99 |
return false; |
| 100 |
} |
| 101 |
logger->Info(Languages::TextCopyingFromTo, tableName, tempTableName); |
| 102 |
const string query = "INSERT INTO " + tempTableName + " SELECT objecttype1 * 8, objectid1, objecttype2, objectid2, priority, relation FROM " + tableName + ";"; |
| 103 |
ret = Execute(query); |
| 104 |
- if (ret == false) |
| 105 |
+ if (!ret) |
| 106 |
{ |
| 107 |
return false; |
| 108 |
} |
| 109 |
ret = DropTable(tableName); |
| 110 |
- if (ret == false) |
| 111 |
+ if (!ret) |
| 112 |
{ |
| 113 |
return false; |
| 114 |
} |
| 115 |
@@ -448,7 +449,7 @@ |
| 116 |
|
| 117 |
bool SQLite::Execute(const char* query, sqlite3_callback callback = nullptr, void* result = nullptr) |
| 118 |
{ |
| 119 |
- if (db == nullptr) |
| 120 |
+ if (!db) |
| 121 |
{ |
| 122 |
return false; |
| 123 |
} |
| 124 |
Index: railcontrol/Utils/Utils.cpp |
| 125 |
=================================================================== |
| 126 |
--- railcontrol.orig/Utils/Utils.cpp 2026-01-25 04:36:43.024717955 +0100 |
| 127 |
+++ railcontrol/Utils/Utils.cpp 2026-01-25 04:44:50.460364920 +0100 |
| 128 |
@@ -212,17 +212,30 @@ |
| 129 |
} |
| 130 |
|
| 131 |
void Utils::RemoveOldBackupFiles (Logger::Logger *logger, |
| 132 |
- const std::string &filename, |
| 133 |
+ const string &pathFile, |
| 134 |
unsigned int keepBackups) |
| 135 |
{ |
| 136 |
- DIR *dir = opendir("."); |
| 137 |
+ size_t posDirSeperator = pathFile.find_last_of('/'); |
| 138 |
+ DIR* dir; |
| 139 |
+ string path; |
| 140 |
+ string file; |
| 141 |
+ if (posDirSeperator == string::npos) |
| 142 |
+ { |
| 143 |
+ file = pathFile; |
| 144 |
+ } |
| 145 |
+ else |
| 146 |
+ { |
| 147 |
+ path = pathFile.substr(0, posDirSeperator + 1); |
| 148 |
+ file = pathFile.substr(posDirSeperator + 1); |
| 149 |
+ } |
| 150 |
+ dir= opendir(path.length() ? path.c_str() : "."); |
| 151 |
if (dir == nullptr) |
| 152 |
{ |
| 153 |
return; |
| 154 |
} |
| 155 |
struct dirent *ent; |
| 156 |
std::vector < string > fileNames; |
| 157 |
- const string filenameSearch = filename + "."; |
| 158 |
+ const string filenameSearch = file + "."; |
| 159 |
const size_t filenameSearchLength = filenameSearch.length() + 10; |
| 160 |
while (true) |
| 161 |
{ |
| 162 |
@@ -231,7 +244,7 @@ |
| 163 |
{ |
| 164 |
break; |
| 165 |
} |
| 166 |
- string fileName = ent->d_name; |
| 167 |
+ const string fileName = ent->d_name; |
| 168 |
if (fileName.length() != filenameSearchLength || fileName.find(filenameSearch) == string::npos) |
| 169 |
{ |
| 170 |
continue; |
| 171 |
@@ -257,8 +270,9 @@ |
| 172 |
} |
| 173 |
|
| 174 |
--removeBackups; |
| 175 |
- logger->Info(Languages::TextRemoveBackupFile, fileName); |
| 176 |
- remove(fileName.c_str()); |
| 177 |
+ const string fileToDelete(path + fileName); |
| 178 |
+ logger->Info(Languages::TextRemoveBackupFile, fileToDelete); |
| 179 |
+ remove(fileToDelete.c_str()); |
| 180 |
} |
| 181 |
} |
| 182 |
|