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