db/Interface: remove IsPlugin(), use `dynamic_cast` instead
This commit is contained in:
parent
ed9ece5ea3
commit
bda77ffc5b
|
@ -216,17 +216,17 @@ glue_db_init_and_load(const ConfigData &config)
|
|||
std::throw_with_nested(std::runtime_error("Failed to open database plugin"));
|
||||
}
|
||||
|
||||
if (!instance->database->IsPlugin(simple_db_plugin))
|
||||
auto *db = dynamic_cast<SimpleDatabase *>(instance->database);
|
||||
if (db == nullptr)
|
||||
return true;
|
||||
|
||||
SimpleDatabase &db = *(SimpleDatabase *)instance->database;
|
||||
instance->update = new UpdateService(config,
|
||||
instance->event_loop, db,
|
||||
instance->event_loop, *db,
|
||||
static_cast<CompositeStorage &>(*instance->storage),
|
||||
*instance);
|
||||
|
||||
/* run database update after daemonization? */
|
||||
return db.FileExists();
|
||||
return db->FileExists();
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
@ -209,12 +209,9 @@ handle_mount(Client &client, Request args, Response &r)
|
|||
instance.EmitIdle(IDLE_MOUNT);
|
||||
|
||||
#ifdef ENABLE_DATABASE
|
||||
Database *_db = instance.database;
|
||||
if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
|
||||
SimpleDatabase &db = *(SimpleDatabase *)_db;
|
||||
|
||||
if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
|
||||
try {
|
||||
db.Mount(local_uri, remote_uri);
|
||||
db->Mount(local_uri, remote_uri);
|
||||
} catch (...) {
|
||||
composite.Unmount(local_uri);
|
||||
throw;
|
||||
|
@ -256,11 +253,8 @@ handle_unmount(Client &client, Request args, Response &r)
|
|||
destroy here */
|
||||
instance.update->CancelMount(local_uri);
|
||||
|
||||
Database *_db = instance.database;
|
||||
if (_db != nullptr && _db->IsPlugin(simple_db_plugin)) {
|
||||
SimpleDatabase &db = *(SimpleDatabase *)_db;
|
||||
|
||||
if (db.Unmount(local_uri))
|
||||
if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
|
||||
if (db->Unmount(local_uri))
|
||||
// TODO: call Instance::OnDatabaseModified()?
|
||||
instance.EmitIdle(IDLE_DATABASE);
|
||||
}
|
||||
|
|
|
@ -52,10 +52,6 @@ public:
|
|||
return plugin;
|
||||
}
|
||||
|
||||
bool IsPlugin(const DatabasePlugin &other) const noexcept {
|
||||
return &plugin == &other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the database. Read it into memory if applicable.
|
||||
*
|
||||
|
|
|
@ -94,11 +94,9 @@ UpdateService::CancelMount(const char *uri)
|
|||
cancel_current = next.IsDefined() && next.storage == storage2;
|
||||
}
|
||||
|
||||
Database &_db2 = *lr.directory->mounted_database;
|
||||
if (_db2.IsPlugin(simple_db_plugin)) {
|
||||
SimpleDatabase &db2 = static_cast<SimpleDatabase &>(_db2);
|
||||
queue.Erase(db2);
|
||||
cancel_current |= next.IsDefined() && next.db == &db2;
|
||||
if (auto *db2 = dynamic_cast<SimpleDatabase *>(lr.directory->mounted_database)) {
|
||||
queue.Erase(*db2);
|
||||
cancel_current |= next.IsDefined() && next.db == db2;
|
||||
}
|
||||
|
||||
if (cancel_current && walk != nullptr) {
|
||||
|
@ -190,12 +188,10 @@ UpdateService::Enqueue(const char *path, bool discard)
|
|||
/* follow the mountpoint, update the mounted
|
||||
database */
|
||||
|
||||
Database &_db2 = *lr.directory->mounted_database;
|
||||
if (!_db2.IsPlugin(simple_db_plugin))
|
||||
db2 = dynamic_cast<SimpleDatabase *>(lr.directory->mounted_database);
|
||||
if (db2 == nullptr)
|
||||
throw std::runtime_error("Cannot update this type of database");
|
||||
|
||||
db2 = static_cast<SimpleDatabase *>(&_db2);
|
||||
|
||||
if (lr.uri == nullptr) {
|
||||
storage2 = storage.GetMount(path);
|
||||
path = "";
|
||||
|
|
|
@ -106,10 +106,9 @@ storage_state_restore(const char *line, TextFile &file, Instance &instance)
|
|||
return true;
|
||||
}
|
||||
|
||||
Database *db = instance.database;
|
||||
if (db != nullptr && db->IsPlugin(simple_db_plugin)) {
|
||||
if (auto *db = dynamic_cast<SimpleDatabase *>(instance.database)) {
|
||||
try {
|
||||
((SimpleDatabase *)db)->Mount(uri.c_str(), url.c_str());
|
||||
db->Mount(uri.c_str(), url.c_str());
|
||||
} catch (...) {
|
||||
FormatError(std::current_exception(),
|
||||
"Failed to restore mount to %s",
|
||||
|
|
Loading…
Reference in New Issue