[patch] for Bug 50462: mail is permanently lost if disk is full
Martin Koller <[email protected]>
| Newsgroups | gmane.comp.kde.devel.kmail |
|---|---|
| Message-ID | <[email protected]> |
Hi list,
attached you find a patch which tries to fix this very high voted issue (>900
votes) - which should also work around the same problem noted here:
Bug 122028: [CRITICAL] KMail corrupts it's index files after a crash. Some/All
mails get "No Subject" lines after viewing them. Mails LOST
It basically automatically recreates the index whenever a "should never
happen" situation occurs in getting data from the index and retries to get
the requested information.
I hope someone with deep knowledge about this index stuff can review my patch
and tell me if this is something feasible.
I checked this by corrupting an .index file (with khexedit) by inserting
arbitrary data or truncating the file at an arbitrary position.
--
Best regards/Schöne Grüße
Martin () ascii ribbon campaign - against html mail
/\ - against microsoft attachments
Computers and Internet gave you freedom.
TCPA would TAKE your FREEDOM! http://www.againsttcpa.com
_______________________________________________
KMail developers mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/kmail-devel
50462.patch
(text/x-diff, 2.4 KB)
Index: kmmsgbase.cpp
===================================================================
--- kmmsgbase.cpp (revision 651637)
+++ kmmsgbase.cpp (working copy)
@@ -1109,6 +1109,7 @@
//-----------------------------------------------------------------------------
QString KMMsgBase::getStringPart(MsgPartType t) const
{
+retry:
QString ret;
g_chunk_offset = 0;
@@ -1145,7 +1146,12 @@
type = (MsgPartType) tmp;
if(g_chunk_offset + l > mIndexLength) {
kdDebug(5006) << "This should never happen.. " << __FILE__ << ":" << __LINE__ << endl;
- break;
+ if(using_mmap) {
+ g_chunk_length = 0;
+ g_chunk = 0;
+ }
+ storage()->recreateIndex();
+ goto retry;
}
if(type == t) {
// This works because the QString constructor does a memcpy.
@@ -1178,6 +1184,7 @@
//-----------------------------------------------------------------------------
off_t KMMsgBase::getLongPart(MsgPartType t) const
{
+retry:
off_t ret = 0;
g_chunk_offset = 0;
@@ -1217,7 +1224,12 @@
if (g_chunk_offset + l > mIndexLength) {
kdDebug(5006) << "This should never happen.. " << __FILE__ << ":" << __LINE__ << endl;
- break;
+ if(using_mmap) {
+ g_chunk_length = 0;
+ g_chunk = 0;
+ }
+ storage()->recreateIndex();
+ goto retry;
}
if(type == t) {
assert(sizeOfLong == l);
Index: kmfolderindex.h
===================================================================
--- kmfolderindex.h (revision 651637)
+++ kmfolderindex.h (working copy)
@@ -80,6 +80,8 @@
virtual QString indexLocation() const;
virtual int writeIndex( bool createEmptyIndex = false );
+ void recreateIndex();
+
public slots:
/** Incrementally update the index if possible else call writeIndex */
virtual int updateIndex();
Index: kmfolderindex.cpp
===================================================================
--- kmfolderindex.cpp (revision 651637)
+++ kmfolderindex.cpp (working copy)
@@ -479,4 +479,16 @@
return msgInfo;
}
+void KMFolderIndex::recreateIndex()
+{
+ kapp->setOverrideCursor(KCursor::arrowCursor());
+ KMessageBox::error(0,
+ i18n("The mail index for '%1' is corrupted and will be regenerated now, "
+ "but some information, including status flags, will be lost.").arg(name()));
+ kapp->restoreOverrideCursor();
+ createIndexFromContents();
+ readIndex();
+}
+
+
#include "kmfolderindex.moc"