mirror of
https://github.com/matrix-construct/construct
synced 2025-02-18 09:40:12 +01:00
ircd::db: Minor cleanup.
This commit is contained in:
parent
31c3dea483
commit
14b7a088ee
1 changed files with 43 additions and 15 deletions
58
ircd/db.cc
58
ircd/db.cc
|
@ -87,7 +87,11 @@ static void
|
||||||
ircd::db::init_directory()
|
ircd::db::init_directory()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
const auto dbdir(fs::get(fs::DB));
|
const auto dbdir
|
||||||
|
{
|
||||||
|
fs::get(fs::DB)
|
||||||
|
};
|
||||||
|
|
||||||
if(fs::mkdir(dbdir))
|
if(fs::mkdir(dbdir))
|
||||||
log.notice("Created new database directory at `%s'", dbdir);
|
log.notice("Created new database directory at `%s'", dbdir);
|
||||||
else
|
else
|
||||||
|
@ -260,9 +264,20 @@ try
|
||||||
{
|
{
|
||||||
// Existing columns at path. If any are left the descriptor set did not
|
// Existing columns at path. If any are left the descriptor set did not
|
||||||
// describe all of the columns found in the database at path.
|
// describe all of the columns found in the database at path.
|
||||||
const auto opts{make_dbopts(std::string(this->optstr))};
|
const auto opts
|
||||||
const auto required{db::column_names(path, opts)};
|
{
|
||||||
std::set<string_view> existing{begin(required), end(required)};
|
make_dbopts(std::string(this->optstr))
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto required
|
||||||
|
{
|
||||||
|
db::column_names(path, opts)
|
||||||
|
};
|
||||||
|
|
||||||
|
std::set<string_view> existing
|
||||||
|
{
|
||||||
|
begin(required), end(required)
|
||||||
|
};
|
||||||
|
|
||||||
// The names of the columns extracted from the descriptor set
|
// The names of the columns extracted from the descriptor set
|
||||||
std::vector<string_view> ret(descriptors.size());
|
std::vector<string_view> ret(descriptors.size());
|
||||||
|
@ -274,9 +289,13 @@ try
|
||||||
});
|
});
|
||||||
|
|
||||||
for(const auto &remain : existing)
|
for(const auto &remain : existing)
|
||||||
throw error("Failed to describe existing column '%s' (and %zd others...)",
|
throw error
|
||||||
remain,
|
{
|
||||||
existing.size() - 1);
|
"Failed to describe existing column '%s' (and %zd others...)",
|
||||||
|
remain,
|
||||||
|
existing.size() - 1
|
||||||
|
};
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}()}
|
}()}
|
||||||
,column_index{[this]
|
,column_index{[this]
|
||||||
|
@ -291,7 +310,10 @@ try
|
||||||
{
|
{
|
||||||
bool fsck{false};
|
bool fsck{false};
|
||||||
bool read_only{false};
|
bool read_only{false};
|
||||||
auto opts(make_dbopts(this->optstr, &read_only, &fsck));
|
auto opts
|
||||||
|
{
|
||||||
|
make_dbopts(this->optstr, &read_only, &fsck)
|
||||||
|
};
|
||||||
|
|
||||||
// Setup sundry
|
// Setup sundry
|
||||||
opts.create_if_missing = true;
|
opts.create_if_missing = true;
|
||||||
|
@ -386,10 +408,13 @@ try
|
||||||
|
|
||||||
for(size_t i(0); i < this->columns.size(); ++i)
|
for(size_t i(0); i < this->columns.size(); ++i)
|
||||||
if(db::id(*this->columns[i]) != i)
|
if(db::id(*this->columns[i]) != i)
|
||||||
throw error("Columns misaligned: expecting id[%zd] got id[%u] '%s'",
|
throw error
|
||||||
i,
|
{
|
||||||
db::id(*this->columns[i]),
|
"Columns misaligned: expecting id[%zd] got id[%u] '%s'",
|
||||||
db::name(*this->columns[i]));
|
i,
|
||||||
|
db::id(*this->columns[i]),
|
||||||
|
db::name(*this->columns[i])
|
||||||
|
};
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -437,9 +462,12 @@ try
|
||||||
}
|
}
|
||||||
catch(const std::exception &e)
|
catch(const std::exception &e)
|
||||||
{
|
{
|
||||||
throw error("Failed to open db '%s': %s",
|
throw error
|
||||||
this->name,
|
{
|
||||||
e.what());
|
"Failed to open db '%s': %s",
|
||||||
|
this->name,
|
||||||
|
e.what()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::db::database::~database()
|
ircd::db::database::~database()
|
||||||
|
|
Loading…
Add table
Reference in a new issue