-
Notifications
You must be signed in to change notification settings - Fork 871
Chaning directories for logs and state files #7868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
edf5451
3117b43
70a04ed
aeb4ec9
47ce2ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* SPDX-License-Identifier: GPL-2.0-or-later | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "configfile.h" | ||
#include "theme.h" | ||
|
@@ -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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @brainrom |
||
QSettings settings(configFile(), QSettings::IniFormat); | ||
return settings.value(QLatin1String(logDirC), defaultLogDir).toString(); | ||
} | ||
|
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> | ||
|
||
#include "account.h" | ||
#include "accountmanager.h" | ||
#include "logger.h" | ||
|
||
using namespace OCC; | ||
|
||
class TestCookieJarMigration : public QObject | ||
{ | ||
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
|
||
#include "testcookiejarmigration.moc" |
Uh oh!
There was an error while loading. Please reload this page.