[Kde-pim] Single file resources create new collection when re-reading backend file

David Jarvie djarvie at kde.org
Mon Aug 1 21:39:49 BST 2011


On Monday 01 August 2011 13:22:04 Kevin Krammer wrote:
> On Sunday, 2011-07-31, David Jarvie wrote:
> > The SingleFileResource base class does a clearCache() and synchronize()
> > when it re-reads the backend file (e.g. if it is changed by an external
> > process). This has the side effect that the resource's collection is
> > removed and a new one created. The way I've coded things in KAlarm, this
> > poses a problem, because KAlarm stores collection IDs to identify its
> > calendars. If a resource changes its collection ID, this makes KAlarm 
> > think that the calendar has been deleted, and a new one created, when all
> > that has really happened is that the calendar's contents have changed.
> > 
> > Is there a good reason to create a new collection in these circumstances,
> > or could this be changed to simply update the existing collection? If
> > recreating the collection is really a good thing, what is a better way of
> > keeping track of resources/collections within applications so that the
> > link between a resource and its data isn't broken when this happens?
> 
> I think this is rather a bug than done on purpose.
> If I remember correctly the resource would call synchronize() and thus asking 
> Akonadi to retrieve all information again.
> 
> The remote ID for the collection is the file name, IIRC, and thus should not 
> change, which in turn should result in the same collection just being update.
> 
> My guess is that whatever causes the original collection to be removed is the 
> culprit here.

The culprit is ResourceBase::clearCache(), called in SingleFileResourceBase::readLocalFile(), which AFAICS deletes the first collection for the resource (which is the only collection in the case of SingleFileResource). The actual deletion of the collection is done in ResourceBasePrivate::slotDeleteResourceCollectionDone(), which is reached indirectly via ResourceScheduler::scheduleResourceCollectionDeletion().

The solution is not to simply remove the call to clearCache() - things don't work at all then. It's the Items in the Collection which need to change, so the processing needs to be done at an Item level. I suspect that the correct way to do it would be to for the derived resource to read the updated backend file, and compare the items in it with the existing items from the old file. It would then remove existing ones which have disappeared, modify changed items, and add new ones. A somewhat cumbersome process, which would have to be implemented separately by each derived resource class, but is there a better way?

-- 
David Jarvie.
KDE developer.
KAlarm author -- http://www.astrojar.org.uk/kalarm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20110801/88c760f7/attachment.sig>
-------------- next part --------------
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/


More information about the kde-pim mailing list