Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,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 @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include <QRegularExpression>

Check failure on line 7 in src/gui/syncrunfilelog.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/syncrunfilelog.cpp:7:10 [clang-diagnostic-error]

'QRegularExpression' file not found

#include "syncrunfilelog.h"
#include "common/utility.h"
Expand All @@ -24,7 +24,7 @@
{
const qint64 logfileMaxSize = 10 * 1024 * 1024; // 10MiB

const QString logpath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
const QString logpath = QStandardPaths::writableLocation(QStandardPaths::StateLocation);

Check warning on line 27 in src/gui/syncrunfilelog.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/syncrunfilelog.cpp:27:19 [cppcoreguidelines-init-variables]

variable 'logpath' is not initialized
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 @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "theme.h"

Check failure on line 7 in src/gui/updater/ocupdater.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/updater/ocupdater.cpp:7:10 [clang-diagnostic-error]

'theme.h' file not found
#include "configfile.h"
#include "common/utility.h"
#include "accessmanager.h"
Expand Down Expand Up @@ -219,7 +219,7 @@
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
18 changes: 17 additions & 1 deletion src/libsync/account.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2013 ownCloud GmbH
Expand Down Expand Up @@ -400,9 +400,25 @@
jar->setParent(oldParent); // takes it back
}

void Account::tryMigrateCookieJar()
{
QString oldCookieJarPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/cookies" + id() + ".db";
if (QFile::exists(oldCookieJarPath))
{
if (QFile::exists(cookieJarPath()))
{
qWarning() << "Both old cookie jar and new cookie jar exists. Abort migration";
return;
}
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 @@ -301,6 +301,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 @@ -4,7 +4,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "config.h"

Check failure on line 7 in src/libsync/configfile.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/configfile.cpp:7:10 [clang-diagnostic-error]

'config.h' file not found

#include "configfile.h"
#include "theme.h"
Expand Down Expand Up @@ -1118,7 +1118,7 @@

QString ConfigFile::logDir() const
{
const auto defaultLogDir = QString(configPath() + QStringLiteral("/logs"));
const auto defaultLogDir = QString(QStandardPaths::writableLocation(QStandardPaths::StateLocation) + QStringLiteral("/logs"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we change the log location, existing log files should be migrated to the new place
otherwise people may loose logs that may be important for them

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Application::setupLogging() is the good place for log migration routine? Looks like it's entry point for logDir() usage.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brainrom
yes
I think so
sorry for the delay

QSettings settings(configFile(), QSettings::IniFormat);
return settings.value(QLatin1String(logDirC), defaultLogDir).toString();
}
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ nextcloud_add_test(FileTagModel)
nextcloud_add_test(SyncConflictsModel)
nextcloud_add_test(DateFieldBackend)
nextcloud_add_test(ClientStatusReporting)
nextcloud_add_test(CookieJarMigration)

nextcloud_add_test(FileSystem)

Expand Down
85 changes: 85 additions & 0 deletions test/testcookiejarmigration.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
This software is in the public domain, furnished "as is", without technical
support, and with no warranty, express or implied, as to its usefulness for
any purpose.
*/

#include <QtTest>

Check failure on line 7 in test/testcookiejarmigration.cpp

View workflow job for this annotation

GitHub Actions / build

test/testcookiejarmigration.cpp:7:10 [clang-diagnostic-error]

'QtTest' file not found

#include "account.h"
#include "accountmanager.h"
#include "logger.h"

using namespace OCC;

class TestCookieJarMigration : public QObject

Check warning on line 15 in test/testcookiejarmigration.cpp

View workflow job for this annotation

GitHub Actions / build

test/testcookiejarmigration.cpp:15:7 [cppcoreguidelines-pro-type-member-init]

constructor does not initialize these fields: AccountPtr, oldCookieJarPath,
{
Q_OBJECT
AccountPtr _account;
QString oldCookieJarPath;

private slots:
void initTestCase()
{
OCC::Logger::instance()->setLogFlush(true);
OCC::Logger::instance()->setLogDebug(true);

QStandardPaths::setTestModeEnabled(true);
// Create directories used in test, since Qt doesn't create its automatically
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::StateLocation));
QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));

_account = Account::create();
AccountManager::instance()->addAccount(_account);
oldCookieJarPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/cookies" + _account->id() + ".db";
}
void testNoAction()
{
QFile jarFile(_account->cookieJarPath());
jarFile.open(QFile::WriteOnly);
jarFile.write("1", 1); // Write one byte to file
jarFile.close();
_account->tryMigrateCookieJar();

QVERIFY(!QFile::exists(oldCookieJarPath)); // Check that old file doesn't exits
QCOMPARE(QFileInfo(_account->cookieJarPath()).size(), 1); // Check that this byte present in new file
QFile::remove(_account->cookieJarPath()); // Cleanup
}
void testSimpleMigration()
{
QFile oldJarFile(oldCookieJarPath);
oldJarFile.open(QFile::WriteOnly);
oldJarFile.write("1", 1); // Write one byte to file
oldJarFile.close();

_account->tryMigrateCookieJar();
QVERIFY(!QFile::exists(oldCookieJarPath)); // Check that old file is deleted

QCOMPARE(QFileInfo(_account->cookieJarPath()).size(), 1); // Check that this byte present in new file
QFile::remove(_account->cookieJarPath()); // Cleanup
}
void testNotOverwrite()
{
QFile oldJarFile(oldCookieJarPath);
oldJarFile.open(QFile::WriteOnly);
oldJarFile.write("1", 1); // Write one byte to file
oldJarFile.close();

QFile newJarFile(_account->cookieJarPath());
oldJarFile.open(QFile::WriteOnly);
oldJarFile.write("123", 3); // Write three bytes to file
oldJarFile.close();


_account->tryMigrateCookieJar();

QCOMPARE(QFileInfo(_account->cookieJarPath()).size(), 3); // Check that these bytes still present

// Cleanup
QFile::remove(_account->cookieJarPath());
QFile::remove(oldCookieJarPath);
}
};

QTEST_APPLESS_MAIN(TestCookieJarMigration)

Check warning on line 84 in test/testcookiejarmigration.cpp

View workflow job for this annotation

GitHub Actions / build

test/testcookiejarmigration.cpp:84:20 [cppcoreguidelines-avoid-non-const-global-variables]

variable 'TestCookieJarMigration' is non-const and globally accessible, consider making it const
#include "testcookiejarmigration.moc"
Loading