Commit df142d4f authored by Max Kellermann's avatar Max Kellermann

db/simple: migrate Mount() from class Error to C++ exceptions

parent fac8edd4
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "Request.hxx" #include "Request.hxx"
#include "CommandError.hxx" #include "CommandError.hxx"
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/Error.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "fs/Traits.hxx" #include "fs/Traits.hxx"
#include "client/Client.hxx" #include "client/Client.hxx"
...@@ -211,11 +210,7 @@ handle_mount(Client &client, Request args, Response &r) ...@@ -211,11 +210,7 @@ handle_mount(Client &client, Request args, Response &r)
SimpleDatabase &db = *(SimpleDatabase *)_db; SimpleDatabase &db = *(SimpleDatabase *)_db;
try { try {
Error error; db.Mount(local_uri, remote_uri);
if (!db.Mount(local_uri, remote_uri, error)) {
composite.Unmount(local_uri);
return print_error(r, error);
}
} catch (...) { } catch (...) {
composite.Unmount(local_uri); composite.Unmount(local_uri);
throw; throw;
......
...@@ -395,9 +395,8 @@ IsUnsafeChar(char ch) ...@@ -395,9 +395,8 @@ IsUnsafeChar(char ch)
return !IsSafeChar(ch); return !IsSafeChar(ch);
} }
bool void
SimpleDatabase::Mount(const char *local_uri, const char *storage_uri, SimpleDatabase::Mount(const char *local_uri, const char *storage_uri)
Error &error)
{ {
if (cache_path.IsNull()) if (cache_path.IsNull())
throw DatabaseError(DatabaseErrorCode::NOT_FOUND, throw DatabaseError(DatabaseErrorCode::NOT_FOUND,
...@@ -406,9 +405,7 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri, ...@@ -406,9 +405,7 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
std::string name(storage_uri); std::string name(storage_uri);
std::replace_if(name.begin(), name.end(), IsUnsafeChar, '_'); std::replace_if(name.begin(), name.end(), IsUnsafeChar, '_');
const auto name_fs = AllocatedPath::FromUTF8(name.c_str(), error); const auto name_fs = AllocatedPath::FromUTF8Throw(name.c_str());
if (name_fs.IsNull())
return false;
#ifndef ENABLE_ZLIB #ifndef ENABLE_ZLIB
constexpr bool compress = false; constexpr bool compress = false;
...@@ -432,8 +429,6 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri, ...@@ -432,8 +429,6 @@ SimpleDatabase::Mount(const char *local_uri, const char *storage_uri,
delete db; delete db;
throw; throw;
} }
return true;
} }
Database * Database *
......
...@@ -98,9 +98,11 @@ public: ...@@ -98,9 +98,11 @@ public:
gcc_nonnull_all gcc_nonnull_all
void Mount(const char *uri, Database *db); void Mount(const char *uri, Database *db);
/**
* Throws #std::runtime_error on error.
*/
gcc_nonnull_all gcc_nonnull_all
bool Mount(const char *local_uri, const char *storage_uri, void Mount(const char *local_uri, const char *storage_uri);
Error &error);
gcc_nonnull_all gcc_nonnull_all
bool Unmount(const char *uri); bool Unmount(const char *uri);
......
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