1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(paths): create profile dir before calling ProfileLocker or Profile

Fix failure to create new profile due to profile dir not existing. Move
creation outside of Profile class due to ProfileLocker static functions.
This commit is contained in:
Anthony Bilinski 2018-12-16 01:30:15 -08:00
parent d683e3b57a
commit 92d3a3ef38
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 17 additions and 23 deletions

View File

@ -159,11 +159,6 @@ void createLogFile(const Paths& paths)
QFileInfo logFile{logFilePath}; QFileInfo logFile{logFilePath};
QDir logFileDir{logFile.dir()}; QDir logFileDir{logFile.dir()};
if (!logFileDir.mkpath(".")) {
qCritical() << "Couldn't create path for log file";
return;
}
QByteArray logFilePathLocal{logFile.absoluteFilePath().toLocal8Bit()}; QByteArray logFilePathLocal{logFile.absoluteFilePath().toLocal8Bit()};
FILE* mainLogFilePtr = fopen(logFilePathLocal.constData(), "a"); FILE* mainLogFilePtr = fopen(logFilePathLocal.constData(), "a");

View File

@ -101,7 +101,23 @@ Paths* Paths::makePaths(Portable mode)
Paths::Paths(const QString& basePath, bool portable) Paths::Paths(const QString& basePath, bool portable)
: basePath{basePath} : basePath{basePath}
, portable{portable} , portable{portable}
{} {
QStringList allDirs{
getGlobalSettingsPath(),
getLogFilePath(),
getProfilesDir(),
getToxSaveDir(),
getAvatarsDir(),
getTransfersDir(),
getScreenshotsDir()
};
allDirs += getThemeDirs();
for (auto& dir : allDirs) {
if (!QDir{}.mkpath(dir)) {
qCritical() << "Couldn't create dir:" << dir;
}
}
}
/** /**
* @brief Check if qTox is running in portable mode. * @brief Check if qTox is running in portable mode.

View File

@ -608,7 +608,6 @@ void Profile::saveAvatar(const ToxPk& owner, const QByteArray& avatar)
const QByteArray& pic = needEncrypt ? passkey->encrypt(avatar) : avatar; const QByteArray& pic = needEncrypt ? passkey->encrypt(avatar) : avatar;
QString path = avatarPath(owner); QString path = avatarPath(owner);
QDir{}.mkpath(Settings::getInstance().getPaths().getAvatarsDir());
if (pic.isEmpty()) { if (pic.isEmpty()) {
QFile::remove(path); QFile::remove(path);
} else { } else {

View File

@ -110,8 +110,6 @@ void Settings::loadGlobal()
if (loaded) if (loaded)
return; return;
createSettingsDir();
QString filePath = paths.getGlobalSettingsPath(); QString filePath = paths.getGlobalSettingsPath();
// If no settings file exist -- use the default one // If no settings file exist -- use the default one
@ -2314,19 +2312,6 @@ void Settings::createPersonal(QString basename)
ps.endGroup(); ps.endGroup();
} }
/**
* @brief Creates a path to the settings dir, if it doesn't already exist
*/
void Settings::createSettingsDir()
{
QMutexLocker locker{&bigLock};
QString dir = Settings::getSettingsDirPath();
QDir directory(dir);
if (!directory.exists() && !directory.mkpath(directory.absolutePath()))
qCritical() << "Error while creating directory " << dir;
}
/** /**
* @brief Waits for all asynchronous operations to complete * @brief Waits for all asynchronous operations to complete
*/ */

View File

@ -139,7 +139,6 @@ public:
~Settings() override; ~Settings() override;
static Settings& getInstance(); static Settings& getInstance();
void createSettingsDir();
void createPersonal(QString basename); void createPersonal(QString basename);
void savePersonal(); void savePersonal();