Commit 654566558031b3a9f84ac7587eec6f4182d1d49a
1 parent
ce161b1f
Start converting session file to v2, for properties
Showing
4 changed files
with
24 additions
and
11 deletions
persistencefile.cpp
| @@ -320,3 +320,8 @@ void PersistenceFile::closeFile() | @@ -320,3 +320,8 @@ void PersistenceFile::closeFile() | ||
| 320 | throw std::runtime_error(formatString("Saving '%s' failed: rename of temp file to target failed with: %s", filePath.c_str(), strerror(errno))); | 320 | throw std::runtime_error(formatString("Saving '%s' failed: rename of temp file to target failed with: %s", filePath.c_str(), strerror(errno))); |
| 321 | } | 321 | } |
| 322 | } | 322 | } |
| 323 | + | ||
| 324 | +const std::string &PersistenceFile::getFilePath() const | ||
| 325 | +{ | ||
| 326 | + return this->filePath; | ||
| 327 | +} |
persistencefile.h
| @@ -87,6 +87,8 @@ public: | @@ -87,6 +87,8 @@ public: | ||
| 87 | void openWrite(const std::string &versionString); | 87 | void openWrite(const std::string &versionString); |
| 88 | void openRead(); | 88 | void openRead(); |
| 89 | void closeFile(); | 89 | void closeFile(); |
| 90 | + | ||
| 91 | + const std::string &getFilePath() const; | ||
| 90 | }; | 92 | }; |
| 91 | 93 | ||
| 92 | #endif // PERSISTENCEFILE_H | 94 | #endif // PERSISTENCEFILE_H |
sessionsandsubscriptionsdb.cpp
| @@ -41,7 +41,7 @@ SessionsAndSubscriptionsDB::SessionsAndSubscriptionsDB(const std::string &filePa | @@ -41,7 +41,7 @@ SessionsAndSubscriptionsDB::SessionsAndSubscriptionsDB(const std::string &filePa | ||
| 41 | 41 | ||
| 42 | void SessionsAndSubscriptionsDB::openWrite() | 42 | void SessionsAndSubscriptionsDB::openWrite() |
| 43 | { | 43 | { |
| 44 | - PersistenceFile::openWrite(MAGIC_STRING_SESSION_FILE_V1); | 44 | + PersistenceFile::openWrite(MAGIC_STRING_SESSION_FILE_V2); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void SessionsAndSubscriptionsDB::openRead() | 47 | void SessionsAndSubscriptionsDB::openRead() |
| @@ -50,11 +50,13 @@ void SessionsAndSubscriptionsDB::openRead() | @@ -50,11 +50,13 @@ void SessionsAndSubscriptionsDB::openRead() | ||
| 50 | 50 | ||
| 51 | if (detectedVersionString == MAGIC_STRING_SESSION_FILE_V1) | 51 | if (detectedVersionString == MAGIC_STRING_SESSION_FILE_V1) |
| 52 | readVersion = ReadVersion::v1; | 52 | readVersion = ReadVersion::v1; |
| 53 | + else if (detectedVersionString == MAGIC_STRING_SESSION_FILE_V2) | ||
| 54 | + readVersion = ReadVersion::v2; | ||
| 53 | else | 55 | else |
| 54 | throw std::runtime_error("Unknown file version."); | 56 | throw std::runtime_error("Unknown file version."); |
| 55 | } | 57 | } |
| 56 | 58 | ||
| 57 | -SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readDataV1() | 59 | +SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readDataV2() |
| 58 | { | 60 | { |
| 59 | SessionsAndSubscriptionsResult result; | 61 | SessionsAndSubscriptionsResult result; |
| 60 | 62 | ||
| @@ -74,11 +76,11 @@ SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readDataV1() | @@ -74,11 +76,11 @@ SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readDataV1() | ||
| 74 | if (eofFound) | 76 | if (eofFound) |
| 75 | continue; | 77 | continue; |
| 76 | 78 | ||
| 77 | - std::vector<char> reserved(RESERVED_SPACE_SESSIONS_DB_V1); | 79 | + std::vector<char> reserved(RESERVED_SPACE_SESSIONS_DB_V2); |
| 78 | 80 | ||
| 79 | for (uint32_t i = 0; i < nrOfSessions; i++) | 81 | for (uint32_t i = 0; i < nrOfSessions; i++) |
| 80 | { | 82 | { |
| 81 | - readCheck(buf.data(), 1, RESERVED_SPACE_SESSIONS_DB_V1, f); | 83 | + readCheck(buf.data(), 1, RESERVED_SPACE_SESSIONS_DB_V2, f); |
| 82 | 84 | ||
| 83 | uint32_t usernameLength = readUint32(eofFound); | 85 | uint32_t usernameLength = readUint32(eofFound); |
| 84 | readCheck(buf.data(), 1, usernameLength, f); | 86 | readCheck(buf.data(), 1, usernameLength, f); |
| @@ -188,8 +190,8 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector<std::unique_ptr<Sess | @@ -188,8 +190,8 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector<std::unique_ptr<Sess | ||
| 188 | if (!f) | 190 | if (!f) |
| 189 | return; | 191 | return; |
| 190 | 192 | ||
| 191 | - char reserved[RESERVED_SPACE_SESSIONS_DB_V1]; | ||
| 192 | - std::memset(reserved, 0, RESERVED_SPACE_SESSIONS_DB_V1); | 193 | + char reserved[RESERVED_SPACE_SESSIONS_DB_V2]; |
| 194 | + std::memset(reserved, 0, RESERVED_SPACE_SESSIONS_DB_V2); | ||
| 193 | 195 | ||
| 194 | const int64_t start_stamp = Session::getProgramStartedAtUnixTimestamp(); | 196 | const int64_t start_stamp = Session::getProgramStartedAtUnixTimestamp(); |
| 195 | logger->logf(LOG_DEBUG, "Saving program first start time stamp as %ld", start_stamp); | 197 | logger->logf(LOG_DEBUG, "Saving program first start time stamp as %ld", start_stamp); |
| @@ -203,7 +205,7 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector<std::unique_ptr<Sess | @@ -203,7 +205,7 @@ void SessionsAndSubscriptionsDB::saveData(const std::vector<std::unique_ptr<Sess | ||
| 203 | 205 | ||
| 204 | writeRowHeader(); | 206 | writeRowHeader(); |
| 205 | 207 | ||
| 206 | - writeCheck(reserved, 1, RESERVED_SPACE_SESSIONS_DB_V1, f); | 208 | + writeCheck(reserved, 1, RESERVED_SPACE_SESSIONS_DB_V2, f); |
| 207 | 209 | ||
| 208 | writeUint32(ses->username.length()); | 210 | writeUint32(ses->username.length()); |
| 209 | writeCheck(ses->username.c_str(), 1, ses->username.length(), f); | 211 | writeCheck(ses->username.c_str(), 1, ses->username.length(), f); |
| @@ -294,7 +296,9 @@ SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readData() | @@ -294,7 +296,9 @@ SessionsAndSubscriptionsResult SessionsAndSubscriptionsDB::readData() | ||
| 294 | return defaultResult; | 296 | return defaultResult; |
| 295 | 297 | ||
| 296 | if (readVersion == ReadVersion::v1) | 298 | if (readVersion == ReadVersion::v1) |
| 297 | - return readDataV1(); | 299 | + logger->logf(LOG_WARNING, "File '%s' is version 1, an internal development version that was never finalized. Not reading.", getFilePath().c_str()); |
| 300 | + if (readVersion == ReadVersion::v2) | ||
| 301 | + return readDataV2(); | ||
| 298 | 302 | ||
| 299 | return defaultResult; | 303 | return defaultResult; |
| 300 | } | 304 | } |
sessionsandsubscriptionsdb.h
| @@ -25,7 +25,8 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>. | @@ -25,7 +25,8 @@ License along with FlashMQ. If not, see <https://www.gnu.org/licenses/>. | ||
| 25 | #include "session.h" | 25 | #include "session.h" |
| 26 | 26 | ||
| 27 | #define MAGIC_STRING_SESSION_FILE_V1 "FlashMQRetainedDBv1" | 27 | #define MAGIC_STRING_SESSION_FILE_V1 "FlashMQRetainedDBv1" |
| 28 | -#define RESERVED_SPACE_SESSIONS_DB_V1 32 | 28 | +#define MAGIC_STRING_SESSION_FILE_V2 "FlashMQRetainedDBv2" |
| 29 | +#define RESERVED_SPACE_SESSIONS_DB_V2 32 | ||
| 29 | 30 | ||
| 30 | /** | 31 | /** |
| 31 | * @brief The SubscriptionForSerializing struct contains the fields we're interested in when saving a subscription. | 32 | * @brief The SubscriptionForSerializing struct contains the fields we're interested in when saving a subscription. |
| @@ -51,12 +52,13 @@ class SessionsAndSubscriptionsDB : public PersistenceFile | @@ -51,12 +52,13 @@ class SessionsAndSubscriptionsDB : public PersistenceFile | ||
| 51 | enum class ReadVersion | 52 | enum class ReadVersion |
| 52 | { | 53 | { |
| 53 | unknown, | 54 | unknown, |
| 54 | - v1 | 55 | + v1, |
| 56 | + v2 | ||
| 55 | }; | 57 | }; |
| 56 | 58 | ||
| 57 | ReadVersion readVersion = ReadVersion::unknown; | 59 | ReadVersion readVersion = ReadVersion::unknown; |
| 58 | 60 | ||
| 59 | - SessionsAndSubscriptionsResult readDataV1(); | 61 | + SessionsAndSubscriptionsResult readDataV2(); |
| 60 | void writeRowHeader(); | 62 | void writeRowHeader(); |
| 61 | public: | 63 | public: |
| 62 | SessionsAndSubscriptionsDB(const std::string &filePath); | 64 | SessionsAndSubscriptionsDB(const std::string &filePath); |