Reject bundle index cache if version is not the current

This commit is contained in:
Allan Odgaard
2013-09-05 23:11:39 +02:00
parent 2107223460
commit e2660960e7

View File

@@ -29,6 +29,7 @@ static std::string read_link (std::string const& path)
namespace plist
{
int32_t const cache_t::kPropertyCacheFormatVersion = 2;
uint32_t const kCapnpCacheFormatVersion = 1;
void cache_t::load (std::string const& path)
{
@@ -93,7 +94,14 @@ namespace plist
if(fd != -1)
{
capnp::PackedFdMessageReader message(kj::AutoCloseFd{fd});
for(auto src : message.getRoot<Cache>().getEntries())
auto cache = message.getRoot<Cache>();
if(cache.getVersion() != kCapnpCacheFormatVersion)
{
fprintf(stderr, "skip %s version %u (expected %u)\n", path.c_str(), cache.getVersion(), kCapnpCacheFormatVersion);
return;
}
for(auto src : cache.getEntries())
{
entry_t entry(src.getPath().cStr());
switch(src.getType().which())
@@ -195,6 +203,7 @@ namespace plist
capnp::MallocMessageBuilder message;
auto cache = message.initRoot<Cache>();
cache.setVersion(kCapnpCacheFormatVersion);
auto entries = cache.initEntries(_cache.size());
size_t i = 0;