Browse Source

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.
reviewable/pr6649/r7
Anthony Bilinski 7 years ago
parent
commit
92d3a3ef38
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 5
      src/main.cpp
  2. 18
      src/persistence/paths.cpp
  3. 1
      src/persistence/profile.cpp
  4. 15
      src/persistence/settings.cpp
  5. 1
      src/persistence/settings.h

5
src/main.cpp

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

18
src/persistence/paths.cpp

@ -101,7 +101,23 @@ Paths* Paths::makePaths(Portable mode) @@ -101,7 +101,23 @@ Paths* Paths::makePaths(Portable mode)
Paths::Paths(const QString& basePath, bool portable)
: basePath{basePath}
, 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.

1
src/persistence/profile.cpp

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

15
src/persistence/settings.cpp

@ -110,8 +110,6 @@ void Settings::loadGlobal() @@ -110,8 +110,6 @@ void Settings::loadGlobal()
if (loaded)
return;
createSettingsDir();
QString filePath = paths.getGlobalSettingsPath();
// If no settings file exist -- use the default one
@ -2314,19 +2312,6 @@ void Settings::createPersonal(QString basename) @@ -2314,19 +2312,6 @@ void Settings::createPersonal(QString basename)
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
*/

1
src/persistence/settings.h

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

Loading…
Cancel
Save