Commit 2c4cc6d9 authored by David Jarvie's avatar David Jarvie
Browse files

Prevent writing to calendar file if not in current KAlarm format

parent 29b6cab3
......@@ -47,8 +47,6 @@ KAlarmResource::KAlarmResource(const QString &id)
, mFileCompatibility(KACalendar::Incompatible)
, mVersion(KACalendar::MixedFormat)
, mFileVersion(KACalendar::IncompatibleFormat)
, mHaveReadFile(false)
, mFetchedAttributes(false)
{
qCDebug(KALARMRESOURCE_LOG) << id << "Starting";
KAlarmResourceCommon::initialise(this);
......@@ -222,6 +220,10 @@ void KAlarmResource::setCompatibility(KJob *j)
bool KAlarmResource::writeToFile(const QString &fileName)
{
qCDebug(KALARMRESOURCE_LOG) << identifier() << "writeToFile:" << fileName;
if (mCompatibility != KACalendar::Current && !mUpdatingFormat) {
qCDebug(KALARMRESOURCE_LOG) << identifier() << "Error: writeToFile: wrong format";
return false;
}
if (calendar() && calendar()->incidences().isEmpty()) {
// It's an empty file. Set up the KAlarm custom property.
KACalendar::setKAlarmVersion(calendar());
......@@ -324,7 +326,10 @@ void KAlarmResource::updateFormat(KJob *j)
const QString filename = fileStorage()->fileName();
qCDebug(KALARMRESOURCE_LOG) << identifier() << "updateFormat: Updating storage for" << filename;
KACalendar::setKAlarmVersion(fileStorage()->calendar());
if (!writeToFile(filename)) {
mUpdatingFormat = true;
bool ok = writeToFile(filename);
mUpdatingFormat = false;
if (!ok) {
qCWarning(KALARMRESOURCE_LOG) << identifier() << "updateFormat: Error updating calendar storage format";
break;
}
......
/*
* kalarmresource.h - Akonadi resource for KAlarm
* Program: kalarm
* Copyright © 2009-2019 by David Jarvie <djarvie@kde.org>
* Copyright © 2009-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
......@@ -64,8 +64,9 @@ private:
KACalendar::Compat mFileCompatibility; // calendar file compatibility found by readFromFile()
int mVersion; // calendar format version
int mFileVersion; // calendar format version found by readFromFile()
bool mHaveReadFile; // the calendar file has been read
bool mFetchedAttributes; // attributes have been fetched after initialisation
bool mHaveReadFile{false}; // the calendar file has been read
bool mFetchedAttributes{false}; // attributes have been fetched after initialisation
bool mUpdatingFormat{false}; // writeToFile() can ignore mCompatibility
};
#endif
/*
* kalarmresourcecommon.cpp - common functions for KAlarm Akonadi resources
* Program: kalarm
* Copyright © 2009-2014 by David Jarvie <djarvie@kde.org>
* Copyright © 2009-2019 David Jarvie <djarvie@kde.org>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Library General Public License as published by
......@@ -97,8 +97,7 @@ KACalendar::Compat getCompatibility(const FileStorage::Ptr &fileStorage, int &ve
*/
Item retrieveItem(const Akonadi::Item &item, KAEvent &event)
{
QString mime = CalEvent::mimeType(event.category());
event.setItemId(item.id());
const QString mime = CalEvent::mimeType(event.category());
if (item.hasAttribute<EventAttribute>()) {
event.setCommandError(item.attribute<EventAttribute>()->commandError());
}
......@@ -142,7 +141,7 @@ KAEvent checkItemChanged(const Akonadi::Item &item, QString &errorMsg)
*/
void setCollectionCompatibility(const Collection &collection, KACalendar::Compat compatibility, int version)
{
qDebug() << collection.id() << "->" << compatibility << version;
qDebug() << "KAlarmResourceCommon::setCollectionCompatibility:" << collection.id() << "->" << compatibility << version;
// Update the CompatibilityAttribute value only.
// Note that we can't supply 'collection' to CollectionModifyJob since
// that may also contain the CollectionAttribute value, which is read-only
......@@ -189,7 +188,7 @@ QString errorMessage(ErrorCode code, const QString &param)
*/
void Private::modifyCollectionJobDone(KJob *j)
{
qDebug();
qDebug() << "KAlarmResourceCommon::modifyCollectionJobDone";
if (j->error()) {
Collection collection = static_cast<CollectionModifyJob *>(j)->collection();
qCritical() << "Error: modifyCollectionJobDone: collection" << collection.id() << ":" << j->errorString();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment