[Kde-pim] KDE/kdepim/kmail

Jaroslaw Staniek js at iidea.pl
Thu May 8 17:28:12 BST 2008


SVN commit 805447 by staniek:

-KMFolderIndex::openInternal(): added bool checkIfIndexTooOld arg which allows 
 to skip message "The index of folder .. seems to be out of date" for maildir folders
 This can probbaly fix recently reported issues with displaying the message for maildir folders.

-int KMFolderIndex::writeMessages( KMMsgBase* msg, bool flush, FILE* indexStream ):
 added overload with indexStream arg, which simplifies KMFolderIndex::writeIndex() code
 and avoids dangerous side effects
 (note: this apparently was not a source of problems, though)

CCMAIL:kde-pim at kde.org



 M  +15 -17    kmfolderindex.cpp  
 M  +7 -1      kmfolderindex.h  
 M  +2 -2      kmfolderindex_common.cpp  
 M  +1 -1      kmfoldermaildir.cpp  
 M  +1 -1      kmfoldermbox.cpp  


--- trunk/KDE/kdepim/kmail/kmfolderindex.cpp #805446:805447
@@ -105,10 +105,7 @@
 
   int fError = 0;
   if ( !createEmptyIndex ) {
-    FILE *oldIndexStream = mIndexStream; //save
-    mIndexStream = tmpIndexStream; // needed because writeMessages() operates on mIndexStream
-    fError = writeMessages( 0/*all*/, false /* !flush */ );
-    mIndexStream = oldIndexStream; //restore
+    fError = writeMessages( 0/*all*/, false /* !flush */, tmpIndexStream );
 /* moved to writeMessages()
     KMMsgBase* msgBase;
     int len;
@@ -482,40 +479,41 @@
   return readIndex();
 }
 
-int KMFolderIndex::writeMessages( KMMsgBase* msg, bool flush )
+int KMFolderIndex::writeMessages( KMMsgBase* msg, bool flush, FILE* indexStream )
 {
-  // ### This only works if the size of mMsgList is > 0, otherwise msg will
-  //     not be written at all, because the loop is not executed.
-  Q_ASSERT( msg == 0 || mMsgList.high() > 0 );
-
   const uint high = mMsgList.high();
-  for ( uint i = 0; i < high; i++ )
+  for ( uint i = 0; i < high || msg; i++ )
   {
     KMMsgBase* msgBase = msg ? msg : mMsgList.at(i);
     if ( !msgBase )
       continue;
     int len;
     const uchar *buffer = msgBase->asIndexString( len );
-    if ( fwrite( &len, sizeof( len ), 1, mIndexStream ) != 1 )
+    if ( fwrite( &len, sizeof( len ), 1, indexStream ) != 1 )
       return 1;
-    off_t offset = KDE_ftell( mIndexStream );
-    if ( fwrite( buffer, len, 1, mIndexStream ) != 1 ) {
+    off_t offset = KDE_ftell( indexStream );
+    msgBase->setIndexOffset( offset );
+    msgBase->setIndexLength( len );
+    if ( fwrite( buffer, len, 1, indexStream ) != 1 ) {
       kDebug() << "Whoa!";
       return 1;
     }
-    msgBase->setIndexOffset( offset );
-    msgBase->setIndexLength( len );
     if ( msg )
       break; // only one
   }
   if ( flush )
-    fflush( mIndexStream );
-  int error = ferror( mIndexStream );
+    fflush( indexStream );
+  int error = ferror( indexStream );
   if ( error != 0 )
     return error;
   return 0;
 }
 
+int KMFolderIndex::writeMessages( KMMsgBase* msg, bool flush )
+{
+  return writeMessages( msg, flush, mIndexStream );
+}
+
 #endif // !KMAIL_SQLITE_INDEX
 
 #include "kmfolderindex.moc"
--- trunk/KDE/kdepim/kmail/kmfolderindex.h #805446:805447
@@ -133,9 +133,15 @@
   */
   int writeMessages( KMMsgBase* msg, bool flush = true );
 
+  /** @overload writeMessages( KMMsgBase* msg, bool flush ) 
+   Allows to specify index stream to use. */
+  int writeMessages( KMMsgBase* msg, bool flush, FILE* indexStream );
+
   /** Opens index stream (or database) without creating it.
+   If @a checkIfIndexTooOld is true, message "The index of folder .. seems 
+   to be out of date" is displayed.
    Called by KMFolderMaildir::open() and KMFolderMbox::open(). */
-  int openInternal();
+  int openInternal( bool checkIfIndexTooOld );
 
   /** Creates index stream (or database).
    Called by KMFolderMaildir::create() and KMFolderMbox::create(). */
--- trunk/KDE/kdepim/kmail/kmfolderindex_common.cpp #805446:805447
@@ -73,7 +73,7 @@
 #include <sys/stat.h>
 #include <sys/file.h>
 
-int KMFolderIndex::openInternal()
+int KMFolderIndex::openInternal( bool checkIfIndexTooOld )
 {
   int rc = 0;
   if ( folder()->path().isEmpty() )
@@ -86,7 +86,7 @@
     KMFolderIndex::IndexStatus index_status = indexStatus();
     if ( KMFolderIndex::IndexOk != index_status ) // test if contents file has changed
     {
-      if ( KMFolderIndex::IndexTooOld == index_status ) {
+      if ( checkIfIndexTooOld && KMFolderIndex::IndexTooOld == index_status ) {
          QString msg = i18n("<qt><p>The index of folder '%2' seems "
                             "to be out of date. To prevent message "
                             "corruption the index will be "
--- trunk/KDE/kdepim/kmail/kmfoldermaildir.cpp #805446:805447
@@ -129,7 +129,7 @@
   if ( !canAccess() )
     return 1;
 
-  int rc = openInternal();
+  int rc = openInternal( false /* !checkIfIndexTooOld */ );
 /* moved to openInternal()
   if (!folder()->path().isEmpty())
   {
--- trunk/KDE/kdepim/kmail/kmfoldermbox.cpp #805446:805447
@@ -134,7 +134,7 @@
 
   lock();
 
-  rc = openInternal();
+  rc = openInternal( true /*checkIfIndexTooOld*/ );
 /* moved to openInternal()
   if ( !folder()->path().isEmpty() ) {
      KMFolderIndex::IndexStatus index_status = indexStatus();
_______________________________________________
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