db/simple: migrate Mount() from class Error to C++ exceptions
This commit is contained in:
@@ -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)
|
|||||||
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)
|
|||||||
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,
|
|||||||
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,
|
|||||||
delete db;
|
delete db;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Database *
|
Database *
|
||||||
|
@@ -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);
|
||||||
|
Reference in New Issue
Block a user