diff --git a/shared_realm.cpp b/shared_realm.cpp index 28bb81b6..d5a7257f 100644 --- a/shared_realm.cpp +++ b/shared_realm.cpp @@ -38,6 +38,7 @@ Realm::Config::Config(const Config& c) , read_only(c.read_only) , in_memory(c.in_memory) , cache(c.cache) +, disable_format_upgrade(c.disable_format_upgrade) , encryption_key(c.encryption_key) , schema_version(c.schema_version) , migration_function(c.migration_function) @@ -71,7 +72,7 @@ Realm::Realm(Config config) m_history = realm::make_client_history(m_config.path, m_config.encryption_key.data()); SharedGroup::DurabilityLevel durability = m_config.in_memory ? SharedGroup::durability_MemOnly : SharedGroup::durability_Full; - m_shared_group = std::make_unique(*m_history, durability, m_config.encryption_key.data()); + m_shared_group = std::make_unique(*m_history, durability, m_config.encryption_key.data(), !m_config.disable_format_upgrade); } } catch (util::File::PermissionDenied const& ex) { @@ -92,6 +93,11 @@ Realm::Realm(Config config) "Realm file is currently open in another process " "which cannot share access with this process. All processes sharing a single file must be the same architecture."); } + catch (FileFormatUpgradeRequired const& ex) { + throw RealmFileException(RealmFileException::Kind::FormatUpgradeRequired, m_config.path, + "The Realm file format must be allowed to be upgraded " + "in order to proceed."); + } } Realm::~Realm() { diff --git a/shared_realm.hpp b/shared_realm.hpp index 67b4f3a5..97399f59 100644 --- a/shared_realm.hpp +++ b/shared_realm.hpp @@ -49,6 +49,7 @@ namespace realm { bool read_only = false; bool in_memory = false; bool cache = true; + bool disable_format_upgrade = false; std::vector encryption_key; std::unique_ptr schema; @@ -162,6 +163,8 @@ namespace realm { process which cannot share with the current process due to an architecture mismatch. */ IncompatibleLockFile, + /** Thrown if the file needs to be upgraded to a new format, but upgrades have been explicitly disabled. */ + FormatUpgradeRequired, }; RealmFileException(Kind kind, std::string path, std::string message) : std::runtime_error(std::move(message)), m_kind(kind), m_path(std::move(path)) {}