From 477f7b1f33843becacbbbee4704206357a783907 Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Thu, 5 May 2016 19:39:50 -0700 Subject: [PATCH] add hook for detecting file format upgrade --- src/shared_realm.cpp | 15 ++++++++++----- src/shared_realm.hpp | 7 +++++-- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/shared_realm.cpp b/src/shared_realm.cpp index bdc2b1fd..bff52bce 100644 --- a/src/shared_realm.cpp +++ b/src/shared_realm.cpp @@ -43,13 +43,15 @@ Realm::Config::Config(const Config& c) , cache(c.cache) , disable_format_upgrade(c.disable_format_upgrade) , automatic_change_notifications(c.automatic_change_notifications) +, upgrade_final_version(0) +, upgrade_initial_version(0) { if (c.schema) { schema = std::make_unique(*c.schema); } } -Realm::Config::Config() : schema_version(ObjectStore::NotVersioned) { } +Realm::Config::Config() : schema_version(ObjectStore::NotVersioned), upgrade_initial_version(0), upgrade_final_version(0) { } Realm::Config::Config(Config&&) = default; Realm::Config::~Config() = default; @@ -71,7 +73,7 @@ Realm::Realm(Config config) } } -void Realm::open_with_config(const Config& config, +void Realm::open_with_config(Config& config, std::unique_ptr& history, std::unique_ptr& shared_group, std::unique_ptr& read_only_group) @@ -85,9 +87,12 @@ void Realm::open_with_config(const Config& config, throw InvalidEncryptionKeyException(); } history = realm::make_client_history(config.path, config.encryption_key.data()); - SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : - SharedGroup::durability_Full; - shared_group = std::make_unique(*history, durability, config.encryption_key.data(), !config.disable_format_upgrade); + SharedGroup::DurabilityLevel durability = config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full; + shared_group = std::make_unique(*history, durability, config.encryption_key.data(), !config.disable_format_upgrade, + [&](int from_version, int to_version) { + config.upgrade_initial_version = from_version; + config.upgrade_final_version = to_version; + }); } } catch (util::File::PermissionDenied const& ex) { diff --git a/src/shared_realm.hpp b/src/shared_realm.hpp index ecd1efae..20cb630c 100644 --- a/src/shared_realm.hpp +++ b/src/shared_realm.hpp @@ -82,7 +82,10 @@ namespace realm { // everything can be done deterministically on one thread, and // speeds up tests that don't need notifications. bool automatic_change_notifications = true; - + // File format versions populated when a file format updrade takes place + // during realm opening + int upgrade_initial_version, upgrade_final_version; + Config(); Config(Config&&); Config(const Config& c); @@ -156,7 +159,7 @@ namespace realm { static _impl::RealmCoordinator& get_coordinator(Realm& realm) { return *realm.m_coordinator; } }; - static void open_with_config(const Config& config, + static void open_with_config(Config& config, std::unique_ptr& history, std::unique_ptr& shared_group, std::unique_ptr& read_only_group);