[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    kmail crash on first startup with existing Mail dir and folders
From:       Don Sanders <sanders () trolltech ! com>
Date:       2001-07-06 14:41:41
[Download RAW message or body]

Attached patched should work around the problem.

If an entry in an old index file is null then create the 
entire index from the folder contents.

Ultimately it would be nice to know how the index got 
corrupted.

In the diff I'm halfway through working on fixing the 
inefficient syncing problem.

Don.

["nullindex.diff" (text/x-c)]

Index: kmfolder.h
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolder.h,v
retrieving revision 1.54
diff -u -r1.54 kmfolder.h
--- kmfolder.h	2001/06/25 14:29:51	1.54
+++ kmfolder.h	2001/07/06 14:44:43
@@ -167,6 +167,9 @@
     others still use it (e.g. other mail reader windows). */
   virtual void close(bool force=FALSE);
 
+  /* sync buffers to disk */
+  virtual void sync();
+
   /** Test if folder is opened. */
   bool isOpened() const { return (mOpenCount>0); }
 
@@ -338,7 +341,7 @@
   virtual KMMessage* readMsg(int idx);
 
   /** Read index file and fill the message-info list mMsgList. */
-  virtual void readIndex();
+  virtual bool readIndex();
 
   /** Read index header. Called from within readIndex(). */
     virtual bool readIndexHeader(int *gv=NULL);
Index: kmfolder.cpp
===================================================================
RCS file: /home/kde/kdenetwork/kmail/kmfolder.cpp,v
retrieving revision 1.173
diff -u -r1.173 kmfolder.cpp
--- kmfolder.cpp	2001/06/25 23:54:43	1.173
+++ kmfolder.cpp	2001/07/06 14:44:44
@@ -229,7 +229,8 @@
     if (!mIndexStream)
       rc = createIndexFromContents();
     else
-      readIndex();
+      if (!readIndex())
+	rc = createIndexFromContents();
   }
   else
   {
@@ -333,6 +334,18 @@
 
 
 //-----------------------------------------------------------------------------
+void KMFolder::sync()
+{
+  if (mOpenCount > 0)
+    if (!mStream || !fsync(fileno(mStream)) ||
+	!mIndexStream || !fsync(fileno(mIndexStream))) {
+	kdDebug(5006) << "Error: Could not sync folder" << endl;
+	kdDebug(5006) << "Abnormally terminating to prevent data loss, now." << endl;
+	exit(1);
+    }
+}
+
+//-----------------------------------------------------------------------------
 int KMFolder::lock()
 {
   int rc;
@@ -839,7 +852,7 @@
 
 
 //-----------------------------------------------------------------------------
-void KMFolder::readIndex()
+bool KMFolder::readIndex()
 {
   int len, offs;
   KMMsgInfo* mi;
@@ -848,7 +861,7 @@
 
   mMsgList.clear();
   int version;
-  if (!readIndexHeader(&version)) return;
+  if (!readIndexHeader(&version)) return false;
 
   mUnreadMsgs = 0;
   mDirty = FALSE;
@@ -869,7 +882,12 @@
       QCString line(MAX_LINE);
       fgets(line.data(), MAX_LINE, mIndexStream);
       if (feof(mIndexStream)) break;
-
+      if (*line.data() == '\0') {
+	  fclose(mIndexStream);
+	  mIndexStream = NULL;
+	  mMsgList.clear();
+	  return false;
+      }
       mi = new KMMsgInfo(this);
       mi->compat_fromOldIndexString(line, mConvertToUtf8);
     }	
@@ -904,6 +922,7 @@
     mDirty = TRUE;
     writeIndex();
   }
+  return true;
 }
 
 

_______________________________________________
Kmail Developers mailing list
Kmail@master.kde.org
http://master.kde.org/mailman/listinfo/kmail


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic