db/Interface: Open() throws exception on error

This commit is contained in:
Max Kellermann 2016-03-18 22:17:46 +01:00
parent 6c2b532ae3
commit f55bdf07d3
7 changed files with 15 additions and 27 deletions

View File

@ -214,8 +214,7 @@ glue_db_init_and_load(void)
"because the database does not need it");
}
if (!instance->database->Open(error))
FatalError(error);
instance->database->Open();
if (!instance->database->IsPlugin(simple_db_plugin))
return true;

View File

@ -55,9 +55,10 @@ public:
/**
* Open the database. Read it into memory if applicable.
*
* Throws #DatabaseError or std::runtime_error on error.
*/
virtual bool Open(gcc_unused Error &error) {
return true;
virtual void Open() {
}
/**

View File

@ -113,7 +113,7 @@ public:
const ConfigBlock &block,
Error &error);
virtual bool Open(Error &error) override;
virtual void Open() override;
virtual void Close() override;
virtual const LightSong *GetSong(const char *uri_utf8,
Error &error) const override;
@ -362,14 +362,12 @@ ProxyDatabase::Configure(const ConfigBlock &block, gcc_unused Error &error)
return true;
}
bool
ProxyDatabase::Open(gcc_unused Error &error)
void
ProxyDatabase::Open()
{
Connect();
update_stamp = 0;
return true;
}
void

View File

@ -184,8 +184,8 @@ SimpleDatabase::Load(Error &error)
return true;
}
bool
SimpleDatabase::Open(gcc_unused Error &error)
void
SimpleDatabase::Open()
{
assert(prefixed_light_song == nullptr);
@ -216,8 +216,6 @@ SimpleDatabase::Open(gcc_unused Error &error)
root = Directory::NewRoot();
}
return true;
}
void
@ -459,10 +457,7 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
name_fs.c_str()),
compress);
try {
if (!db->Open(error)) {
delete db;
return false;
}
db->Open();
} catch (...) {
delete db;
throw;

View File

@ -107,7 +107,7 @@ public:
bool Unmount(const char *uri);
/* virtual methods from class Database */
virtual bool Open(Error &error) override;
virtual void Open() override;
virtual void Close() override;
const LightSong *GetSong(const char *uri_utf8,

View File

@ -80,7 +80,7 @@ public:
const ConfigBlock &block,
Error &error);
virtual bool Open(Error &error) override;
virtual void Open() override;
virtual void Close() override;
virtual const LightSong *GetSong(const char *uri_utf8,
Error &error) const override;
@ -168,8 +168,8 @@ UpnpDatabase::Configure(const ConfigBlock &, Error &)
return true;
}
bool
UpnpDatabase::Open(gcc_unused Error &error)
void
UpnpDatabase::Open()
{
UpnpClientGlobalInit(handle);
@ -181,8 +181,6 @@ UpnpDatabase::Open(gcc_unused Error &error)
UpnpClientGlobalFinish();
throw;
}
return true;
}
void

View File

@ -136,10 +136,7 @@ try {
AtScopeExit(db) { delete db; };
if (!db->Open(error)) {
cerr << error.GetMessage() << endl;
return EXIT_FAILURE;
}
db->Open();
AtScopeExit(db) { db->Close(); };