creation of the directory is no a separate method

This commit is contained in:
Blue 2022-12-17 13:06:37 +03:00
parent 6ff22c9377
commit 6ae32e38b6
Signed by: blue
GPG Key ID: 9B203B252A63EE38
2 changed files with 24 additions and 10 deletions

View File

@ -51,16 +51,7 @@ void DataBase::open()
{
if (!opened) {
mdb_env_create(&environment);
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
path += "/" + getName();
QDir cache(path);
if (!cache.exists()) {
bool res = cache.mkpath(path);
if (!res) {
throw Directory(path.toStdString());
}
}
QString path = createDirectory();
mdb_env_set_maxdbs(environment, tables.size());
mdb_env_set_mapsize(environment, size * 1024UL * 1024UL);
@ -98,6 +89,27 @@ bool DataBase::removeDirectory()
}
}
QString DataBase::createDirectory()
{
if (opened) {
throw Opened(name, "create database directory");
}
QString path(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
path += "/" + getName();
QDir cache(path);
if (!cache.exists()) {
bool res = cache.mkpath(path);
if (!res) {
throw Directory(path.toStdString());
}
}
return path;
}
QString DataBase::getName() const
{
return QString::fromStdString(name);

View File

@ -44,9 +44,11 @@ public:
void close();
bool ready() const;
bool removeDirectory();
QString createDirectory();
QString getName() const;
void drop();
template <class K, class V>
Table<K, V>* addTable(const std::string& name);