Merge pull request #19 from realm/tg-file-upgrade-checker

Added support for suppressing file format upgrades.
This commit is contained in:
Thomas Goyne 2015-12-09 16:23:17 -08:00
commit e897b31b7e
2 changed files with 10 additions and 1 deletions

View File

@ -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<SharedGroup>(*m_history, durability, m_config.encryption_key.data());
m_shared_group = std::make_unique<SharedGroup>(*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() {

View File

@ -49,6 +49,7 @@ namespace realm {
bool read_only = false;
bool in_memory = false;
bool cache = true;
bool disable_format_upgrade = false;
std::vector<char> encryption_key;
std::unique_ptr<Schema> 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)) {}