Commit 7e5ce623 authored by Max Kellermann's avatar Max Kellermann

db/simple: throw C++ exception on init error

parent e17805f2
...@@ -51,14 +51,20 @@ ...@@ -51,14 +51,20 @@
static constexpr Domain simple_db_domain("simple_db"); static constexpr Domain simple_db_domain("simple_db");
inline SimpleDatabase::SimpleDatabase() inline SimpleDatabase::SimpleDatabase(const ConfigBlock &block)
:Database(simple_db_plugin), :Database(simple_db_plugin),
path(AllocatedPath::Null()), path(block.GetPath("path")),
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
compress(true), compress(block.GetBlockValue("compress", true)),
#endif #endif
cache_path(AllocatedPath::Null()), cache_path(block.GetPath("cache_directory")),
prefixed_light_song(nullptr) {} prefixed_light_song(nullptr)
{
if (path.IsNull())
throw std::runtime_error("No \"path\" parameter specified");
path_utf8 = path.ToUTF8();
}
inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path, inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
#ifndef ENABLE_ZLIB #ifndef ENABLE_ZLIB
...@@ -80,25 +86,7 @@ SimpleDatabase::Create(gcc_unused EventLoop &loop, ...@@ -80,25 +86,7 @@ SimpleDatabase::Create(gcc_unused EventLoop &loop,
gcc_unused DatabaseListener &listener, gcc_unused DatabaseListener &listener,
const ConfigBlock &block, Error &) const ConfigBlock &block, Error &)
{ {
SimpleDatabase *db = new SimpleDatabase(); return new SimpleDatabase(block);
db->Configure(block);
return db;
}
void
SimpleDatabase::Configure(const ConfigBlock &block)
{
path = block.GetPath("path");
if (path.IsNull())
throw std::runtime_error("No \"path\" parameter specified");
path_utf8 = path.ToUTF8();
cache_path = block.GetPath("cache_directory");
#ifdef ENABLE_ZLIB
compress = block.GetBlockValue("compress", compress);
#endif
} }
void void
......
...@@ -67,7 +67,7 @@ class SimpleDatabase : public Database { ...@@ -67,7 +67,7 @@ class SimpleDatabase : public Database {
mutable unsigned borrowed_song_count; mutable unsigned borrowed_song_count;
#endif #endif
SimpleDatabase(); SimpleDatabase(const ConfigBlock &block);
SimpleDatabase(AllocatedPath &&_path, bool _compress); SimpleDatabase(AllocatedPath &&_path, bool _compress);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment