Skip to content

Commit

Permalink
logs and cookies moved to state path
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Chelyadin <ilya77105@gmail.com>
  • Loading branch information
brainrom committed Feb 17, 2025
1 parent 120505b commit edf5451
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ AccountManager::AccountsRestoreResult AccountManager::restore(const bool alsoRes
const auto jar = qobject_cast<CookieJar*>(acc->_networkAccessManager->cookieJar());
Q_ASSERT(jar);
if (jar) {
acc->tryMigrateCookieJar();
jar->restore(acc->cookieJarPath());
}
addAccountState(accState);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/syncrunfilelog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void SyncRunFileLog::start(const QString &folderPath)
{
const qint64 logfileMaxSize = 10 * 1024 * 1024; // 10MiB

const QString logpath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QString logpath = QStandardPaths::writableLocation(QStandardPaths::StateLocation);
if(!QDir(logpath).exists()) {
QDir().mkdir(logpath);
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void OCUpdater::slotStartInstaller()
return QDir::toNativeSeparators(path);
};

QString msiLogFile = cfg.configPath() + "msi.log";
QString msiLogFile = cfg.logDir() + "msi.log";
QString command = QStringLiteral("&{msiexec /i '%1' /L*V '%2'| Out-Null ; &'%3'}")
.arg(preparePathForPowershell(updateFile))
.arg(preparePathForPowershell(msiLogFile))
Expand Down
13 changes: 12 additions & 1 deletion src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,20 @@ void Account::lendCookieJarTo(QNetworkAccessManager *guest)
jar->setParent(oldParent); // takes it back
}

void Account::tryMigrateCookieJar()
{
QString oldCookieJarPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/cookies" + id() + ".db";
if (QFile::exists(oldCookieJarPath))
{
qDebug() << "Migrating cookie jar from "<< oldCookieJarPath << "to " << cookieJarPath();
if (!QFile::rename(oldCookieJarPath, cookieJarPath()))
qWarning() << "Failed to migrate cookie jar";
}
}

QString Account::cookieJarPath()
{
return QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/cookies" + id() + ".db";
return QStandardPaths::writableLocation(QStandardPaths::StateLocation) + "/cookies" + id() + ".db";
}

void Account::resetNetworkAccessManager()
Expand Down
1 change: 1 addition & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject

void clearCookieJar();
void lendCookieJarTo(QNetworkAccessManager *guest);
void tryMigrateCookieJar();
QString cookieJarPath();

void resetNetworkAccessManager();
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/configfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ void ConfigFile::setAutomaticLogDir(bool enabled)

QString ConfigFile::logDir() const
{
const auto defaultLogDir = QString(configPath() + QStringLiteral("/logs"));
const auto defaultLogDir = QString(QStandardPaths::writableLocation(QStandardPaths::StateLocation) + QStringLiteral("/logs"));
QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(logDirC), defaultLogDir).toString();
}
Expand Down

0 comments on commit edf5451

Please sign in to comment.