| 82 | } |
| 83 | |
| 84 | VersioningDatabase::VersioningDatabase() { |
| 85 | auto assets = Root::singleton().assets(); |
| 86 | |
| 87 | for (auto const& pair : assets->json("/versioning.config").iterateObject()) |
| 88 | m_currentVersions[pair.first] = pair.second.toUInt(); |
| 89 | |
| 90 | for (auto const& scriptFile : assets->scan("/versioning/", ".lua")) { |
| 91 | try { |
| 92 | auto scriptParts = File::baseName(scriptFile).splitAny("_."); |
| 93 | if (scriptParts.size() != 4) |
| 94 | throw VersioningDatabaseException::format("Script file '{}' filename not of the form <identifier>_<fromversion>_<toversion>.lua", scriptFile); |
| 95 | |
| 96 | String identifier = scriptParts.at(0); |
| 97 | VersionNumber fromVersion = lexicalCast<VersionNumber>(scriptParts.at(1)); |
| 98 | VersionNumber toVersion = lexicalCast<VersionNumber>(scriptParts.at(2)); |
| 99 | |
| 100 | m_versionUpdateScripts[identifier.toLower()].append({scriptFile, fromVersion, toVersion}); |
| 101 | } catch (StarException const&) { |
| 102 | throw VersioningDatabaseException::format("Error parsing version information from versioning script '{}'", scriptFile); |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Sort each set of update scripts first by fromVersion, and then in |
| 107 | // *reverse* order of toVersion. This way, the first matching script for a |
| 108 | // given fromVersion should take the json to the *furthest* toVersion. |
| 109 | for (auto& pair : m_versionUpdateScripts) { |
| 110 | pair.second.sort([](VersionUpdateScript const& lhs, VersionUpdateScript const& rhs) { |
| 111 | if (lhs.fromVersion != rhs.fromVersion) |
| 112 | return lhs.fromVersion < rhs.fromVersion; |
| 113 | else |
| 114 | return lhs.toVersion < rhs.toVersion; |
| 115 | }); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | VersionedJson VersioningDatabase::makeCurrentVersionedJson(String const& identifier, Json const& content) const { |
| 120 | RecursiveMutexLocker locker(m_mutex); |
nothing calls this directly
no test coverage detected