patch for KABC file plugin
Carsten Pfeiffer
carpdjih at mailbox.tu-berlin.de
Thu Feb 16 16:49:01 GMT 2006
Hi,
while trying to find the cause for http://bugs.kde.org/show_bug.cgi?id=87163
"kaddressbook empties resource on some conditions (data lost)", I found
several problems in the KABC file plugin.
From looking at my log files, the problem in #87163 seems to be that KDirWatch
notifies a change in the addressbook file (ResourceFile::fileChanged()),
which causes the addresses to be cleared and asyncLoad() to be called. This
loading apparently never succeeds during KDE shutdown, so the resource
remains empty. A little later, the resource is saved again and the file is
zeroed.
A fix for this is clear()ing the resource only right before loading the file,
after all async IO has succeeded (clearAndLoad() in the patch). Additionally
this prevents successive load() or loadAsync() calls from accumulating
address entries (unless there are measures against this somewhere else). For
extra safety, one could make a copy of mAddrMap before clear()ing and
restoring it if format->load() doesn't succeed. Should we do this?
- "stale temp file detected"
After downloading with KIO, the KTempFile was not deleted, leading to the
above debug message upon the next asyncLoad().
- always use KSaveFile for saving
- make sure to properly stop and start KDirWatch in all cases
- Synchronization issues:
Tickets are used to synchronize the saving of files. This should work with
synchronous loading, but with async saving the ticket is released as soon as
asyncSave returns. (See AddressBook::asyncSave()).
I have added a check to abort saving, if it's still in progress, but this
obviously only helps this current ResourceFile instance, so a better solution
is needed. Don't know who's affected by this.
Calling load() before loadAsync() has finished might also lead to troubles, so
I added a guard for this.
Attached is a patch for the 3.5 branch. I'll also fix the net plugin later,
which has similar issues.
Any comments?
Cheers
Carsten
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kabc.patch
Type: text/x-diff
Size: 5641 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20060216/dfce15ed/attachment.patch>
More information about the kde-core-devel
mailing list