mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-23 03:18:49 +03:00
Merge pull request #405 from rnhmjoj/move-state
Write database to the DataLocation
This commit is contained in:
commit
fc76a939bb
2 changed files with 27 additions and 4 deletions
|
@ -169,13 +169,35 @@ Cache::setup()
|
||||||
|
|
||||||
nhlog::db()->debug("setting up cache");
|
nhlog::db()->debug("setting up cache");
|
||||||
|
|
||||||
cacheDirectory_ = QString("%1/%2%3")
|
// Previous location of the cache directory
|
||||||
|
auto oldCache = QString("%1/%2%3")
|
||||||
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
|
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
|
||||||
.arg(QString::fromUtf8(localUserId_.toUtf8().toHex()))
|
.arg(QString::fromUtf8(localUserId_.toUtf8().toHex()))
|
||||||
.arg(QString::fromUtf8(settings->profile().toUtf8().toHex()));
|
.arg(QString::fromUtf8(settings->profile().toUtf8().toHex()));
|
||||||
|
|
||||||
|
cacheDirectory_ = QString("%1/%2%3")
|
||||||
|
.arg(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))
|
||||||
|
.arg(QString::fromUtf8(localUserId_.toUtf8().toHex()))
|
||||||
|
.arg(QString::fromUtf8(settings->profile().toUtf8().toHex()));
|
||||||
|
|
||||||
bool isInitial = !QFile::exists(cacheDirectory_);
|
bool isInitial = !QFile::exists(cacheDirectory_);
|
||||||
|
|
||||||
|
// NOTE: If both cache directories exist it's better to do nothing: it
|
||||||
|
// could mean a previous migration failed or was interrupted.
|
||||||
|
bool needsMigration = isInitial && QFile::exists(oldCache);
|
||||||
|
|
||||||
|
if (needsMigration) {
|
||||||
|
nhlog::db()->info("found old state directory, migrating");
|
||||||
|
if (!QDir().rename(oldCache, cacheDirectory_)) {
|
||||||
|
throw std::runtime_error(("Unable to migrate the old state directory (" +
|
||||||
|
oldCache + ") to the new location (" +
|
||||||
|
cacheDirectory_ + ")")
|
||||||
|
.toStdString()
|
||||||
|
.c_str());
|
||||||
|
}
|
||||||
|
nhlog::db()->info("completed state migration");
|
||||||
|
}
|
||||||
|
|
||||||
env_ = lmdb::env::create();
|
env_ = lmdb::env::create();
|
||||||
env_.set_mapsize(DB_SIZE);
|
env_.set_mapsize(DB_SIZE);
|
||||||
env_.set_max_dbs(MAX_DBS);
|
env_.set_max_dbs(MAX_DBS);
|
||||||
|
|
|
@ -93,9 +93,9 @@ screenCenter(int width, int height)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
createCacheDirectory()
|
createStandardDirectory(QStandardPaths::StandardLocation path)
|
||||||
{
|
{
|
||||||
auto dir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
auto dir = QStandardPaths::writableLocation(path);
|
||||||
|
|
||||||
if (!QDir().mkpath(dir)) {
|
if (!QDir().mkpath(dir)) {
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
|
@ -188,7 +188,8 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
http::init();
|
http::init();
|
||||||
|
|
||||||
createCacheDirectory();
|
createStandardDirectory(QStandardPaths::CacheLocation);
|
||||||
|
createStandardDirectory(QStandardPaths::AppDataLocation);
|
||||||
|
|
||||||
registerSignalHandlers();
|
registerSignalHandlers();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue