aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autotests/test_kconf_update.cpp78
-rw-r--r--src/kconf_update/README.kconf_update4
-rw-r--r--src/kconf_update/kconf_update.cpp19
3 files changed, 94 insertions, 7 deletions
diff --git a/autotests/test_kconf_update.cpp b/autotests/test_kconf_update.cpp
index d4f5c52d..e4e2b416 100644
--- a/autotests/test_kconf_update.cpp
+++ b/autotests/test_kconf_update.cpp
@@ -82,6 +82,8 @@ void TestKConfUpdate::test_data()
QTest::addColumn<QString>("newConfName");
QTest::addColumn<QString>("expectedNewConfContent");
QTest::addColumn<QString>("expectedOldConfContent");
+ QTest::addColumn<bool>("useVersion5");
+ QTest::addColumn<bool>("shouldUpdateWork");
QTest::newRow("moveKeysSameFile")
<<
@@ -104,6 +106,8 @@ void TestKConfUpdate::test_data()
"new=value\n"
<<
""
+ << true
+ << true
;
QTest::newRow("moveKeysOtherFile")
<<
@@ -132,6 +136,8 @@ void TestKConfUpdate::test_data()
"\n"
"[stay]\n"
"foo=bar\n"
+ << true
+ << true
;
QTest::newRow("allKeys")
<<
@@ -161,6 +167,8 @@ void TestKConfUpdate::test_data()
"foo=bar\n"
<<
""
+ << true
+ << true
;
QTest::newRow("allKeysSubGroup")
<<
@@ -198,6 +206,8 @@ void TestKConfUpdate::test_data()
"foo=bar\n"
<<
""
+ << true
+ << true
;
QTest::newRow("removeGroup")
<<
@@ -221,6 +231,8 @@ void TestKConfUpdate::test_data()
"key=value\n"
<<
""
+ << true
+ << true
;
QTest::newRow("moveKeysSameFileDontExist")
<<
@@ -247,6 +259,50 @@ void TestKConfUpdate::test_data()
"key1=value1\n"
<<
""
+ << true
+ << true
+ ;
+ QTest::newRow("DontMigrateWhenFileDoesntHaveVersion")
+ <<
+ "File=testrc\n"
+ "Group=group\n"
+ "Key=old,new\n"
+ "Options=overwrite\n"
+ <<
+ "testrc"
+ <<
+ "[group]\n"
+ "old=value\n"
+ <<
+ "testrc"
+ <<
+ "[group]\n"
+ "old=value\n"
+ <<
+ ""
+ << false
+ << false
+ ;
+
+ QTest::newRow("DontMigrateWhenUpdateCantDoItMissingFilename")
+ <<
+ "Group=group\n"
+ "Key=old,new\n"
+ "Options=overwrite\n"
+ <<
+ "testrc"
+ <<
+ "[group]\n"
+ "old=value\n"
+ <<
+ "testrc"
+ <<
+ "[group]\n"
+ "old=value\n"
+ <<
+ ""
+ << true
+ << false
;
}
@@ -258,9 +314,14 @@ void TestKConfUpdate::test()
QFETCH(QString, newConfName);
QFETCH(QString, expectedNewConfContent);
QFETCH(QString, expectedOldConfContent);
+ QFETCH(bool, useVersion5);
+ QFETCH(bool, shouldUpdateWork);
- // Prepend the Id= field to the upd content
- updContent = QString("Id=%1\n").arg(QTest::currentDataTag()) + updContent;
+ // Prepend Version and the Id= field to the upd content
+ const QString header = QString("Id=%1\n").arg(QTest::currentDataTag());
+ updContent = header + updContent;
+ if (useVersion5)
+ updContent.prepend("Version=5\n");
QString oldConfPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + oldConfName;
QString newConfPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QLatin1Char('/') + newConfName;
@@ -278,12 +339,16 @@ void TestKConfUpdate::test()
.arg(QTest::currentDataTag());
QString newConfContentAfter = readFile(newConfPath);
- expectedNewConfContent = expectedNewConfContent.arg(updateInfo);
+ if (shouldUpdateWork) {
+ expectedNewConfContent = expectedNewConfContent.arg(updateInfo);
+ }
QCOMPARE(newConfContentAfter, expectedNewConfContent);
if (oldConfName != newConfName) {
QString oldConfContentAfter = readFile(oldConfPath);
- expectedOldConfContent = expectedOldConfContent.arg(updateInfo);
+ if (shouldUpdateWork) {
+ expectedOldConfContent = expectedOldConfContent.arg(updateInfo);
+ }
QCOMPARE(oldConfContentAfter, expectedOldConfContent);
}
}
@@ -548,8 +613,8 @@ void TestKConfUpdate::testScript()
QFETCH(QString, oldConfContent);
QFETCH(QString, expectedNewConfContent);
- // Prepend the Id= field to the upd content
- updContent = QString("Id=%1\n").arg(QTest::currentDataTag()) + updContent;
+ // Prepend the Version and Id= field to the upd content
+ updContent = QString("Version=5\nId=%1\n").arg(QTest::currentDataTag()) + updContent;
QSharedPointer<QTemporaryFile> updFile(writeUpdFile(updContent));
@@ -573,3 +638,4 @@ void TestKConfUpdate::testScript()
QCOMPARE(newConfContent, expectedNewConfContent);
}
+
diff --git a/src/kconf_update/README.kconf_update b/src/kconf_update/README.kconf_update
index 281fb9e5..72509286 100644
--- a/src/kconf_update/README.kconf_update
+++ b/src/kconf_update/README.kconf_update
@@ -51,6 +51,9 @@ Commas (,) are used to seperate fields and may not occur as part
of any field and all of the keywords are case-sensitive, i.e. you
cannot say "key" instead of "Key" for example.
+Starting from KDE Frameworks 5 make sure to put Version=5 before the first "Id=" otherwise the upd file
+will be skipped and the config file will not be updated.
+
For the rest the file is parsed and executed sequentially from top to bottom.
Each line can contain one entry. The following entries are recognized:
@@ -161,6 +164,7 @@ Example update file
===================
# This is comment
+Version=5
Id=kde2.2
File=kioslaverc,kio_httprc
Group=Proxy Settings
diff --git a/src/kconf_update/kconf_update.cpp b/src/kconf_update/kconf_update.cpp
index 255a382e..309bc3c2 100644
--- a/src/kconf_update/kconf_update.cpp
+++ b/src/kconf_update/kconf_update.cpp
@@ -29,6 +29,7 @@
#include <QCoreApplication>
#include <QtCore/QDir>
#include <QProcess>
+#include <QDebug>
#include <kconfig.h>
#include <kconfiggroup.h>
@@ -239,13 +240,21 @@ bool KonfUpdate::checkFile(const QString &filename)
int lineCount = 0;
resetOptions();
QString id;
+ bool foundVersion = false;
while (!ts.atEnd()) {
const QString line = ts.readLine().trimmed();
- lineCount++;
+ if (line.startsWith("Version=5")) {
+ foundVersion = true;
+ }
+ ++lineCount;
if (line.isEmpty() || (line[0] == '#')) {
continue;
}
if (line.startsWith("Id=")) {
+ if (!foundVersion) {
+ qDebug() << QStringLiteral("Missing \"Version=5\", file \'%1\' will be skipped.").arg(filename);
+ return true;
+ }
id = m_currentFilename + ':' + line.mid(3);
} else if (line.startsWith("File=")) {
checkGotFile(line.mid(5), id);
@@ -315,13 +324,21 @@ bool KonfUpdate::updateFile(const QString &filename)
ts.setCodec(QTextCodec::codecForName("ISO-8859-1"));
m_lineCount = 0;
resetOptions();
+ bool foundVersion = false;
while (!ts.atEnd()) {
m_line = ts.readLine().trimmed();
+ if (m_line.startsWith("Version=5")) {
+ foundVersion = true;
+ }
m_lineCount++;
if (m_line.isEmpty() || (m_line[0] == QLatin1Char('#'))) {
continue;
}
if (m_line.startsWith(QLatin1String("Id="))) {
+ if (!foundVersion) {
+ qDebug() << QStringLiteral("Missing \"Version=5\", file \'%1\' will be skipped.").arg(filename);
+ break;
+ }
gotId(m_line.mid(3));
} else if (m_skip) {
continue;