Record the previous generation in the index selector

CURRENT moves to schema 3 with an explicit previous file name. Restore
accepts schemas 1-3 (migrating 2), validates the recorded name as a
plain file name and recovers from it when the current generation is
missing. Registered index tests cover the migration, recovery through
a renamed previous generation and rejection of an escaping name.
This commit is contained in:
faumaray committed 2026-12-06 00:14:16 +03:00
1 parent 4b534c61ae
commit 75ff3d4a9d
3 files changed
+57 -5

No files matched your search

+28 -1
View File
@@ -305,7 +305,7 @@ VOID_TEST(SymbolIndex, generation_selector_migrates_from_the_legacy_format) {
expect(restored->status == SymbolIndex::LoadStatus::loaded);
std::ifstream selector{root / "CURRENT", std::ios::binary};
const std::string text{std::istreambuf_iterator<char>{selector}, {}};
expect(text.find("\"schema\":2") != std::string::npos);
expect(text.find("\"schema\":3") != std::string::npos);
{
std::ofstream stream{root / "CURRENT", std::ios::binary | std::ios::trunc};
stream << "future.json\n";
@@ -502,3 +502,30 @@ VOID_TEST(SymbolIndex, rejects_an_oversized_signature) {
signed_record.signature = std::string(400, 'x');
expect(!index.publish(context("debug:unit", {signed_record})));
}
VOID_TEST(SymbolIndex, selector_records_the_previous_generation_name) {
Void::FileSystem::TempDir temp{"vls_symbol_index_"};
const auto root = temp.path() / "index";
SymbolIndex index;
require(index.publish(context("debug:a", {record("a", "/project/a.cpp", 1)})));
require(index.save_generation(root));
require(index.publish(context("debug:b", {record("b", "/project/b.cpp", 2)})));
require(index.save_generation(root));
fs::rename(root / "snapshot.prev.json", root / "older.json");
{
std::ofstream stream{root / "CURRENT", std::ios::binary | std::ios::trunc};
stream << R"({"schema":3,"file":"snapshot.json","previous":"older.json"})";
}
fs::remove(root / "snapshot.json");
SymbolIndex recovered;
const auto restored = recovered.restore_generation(root);
require(restored.has_value());
expect(restored->status == SymbolIndex::LoadStatus::loaded);
expect(count(recovered.find({.name = "a"})) == 1);
{
std::ofstream stream{root / "CURRENT", std::ios::binary | std::ios::trunc};
stream << R"({"schema":3,"file":"snapshot.json","previous":"../escape.json"})";
}
SymbolIndex rejected;
expect(!rejected.restore_generation(root).has_value());
}