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

List:       kde-commits
Subject:    [kdepim-runtime] resources/maildir: Improve maildir by several factors: we can get dirty signals fro
From:       Andras Mantia <amantia () kde ! org>
Date:       2013-11-17 10:22:46
Message-ID: E1VhzV8-0005N5-Dz () scm ! kde ! org
[Download RAW message or body]

Git commit d55b5f0a39b32ff243c5d7c32f2b27df0f58cb25 by Andras Mantia.
Committed on 17/11/2013 at 10:22.
Pushed by amantia into branch 'master'.

Improve maildir by several factors: we can get dirty signals from the FS even if we \
stop the dir scan prior making changes, so detect if the signal was for a mail file \
we have just changed and ignore it. Also add some more error handling cases (that \
should not happen, but could help to avoid data losses).

M  +20   -4    resources/maildir/maildirresource.cpp
M  +3    -1    resources/maildir/maildirresource.h

http://commits.kde.org/kdepim-runtime/d55b5f0a39b32ff243c5d7c32f2b27df0f58cb25

diff --git a/resources/maildir/maildirresource.cpp \
b/resources/maildir/maildirresource.cpp index 9265352..3cfee66 100644
--- a/resources/maildir/maildirresource.cpp
+++ b/resources/maildir/maildirresource.cpp
@@ -281,6 +281,7 @@ void MaildirResource::itemAdded( const Akonadi::Item & item, \
const Akonadi::Coll  stopMaildirScan( dir );
 
     const QString rid = dir.addEntry( mail->encodedContent() );
+    mChangedFiles.insert( rid );
 
     if ( rid.isEmpty() ) {
       restartMaildirScan( dir );
@@ -352,6 +353,11 @@ void MaildirResource::itemChanged( const Akonadi::Item& item, \
                const QSet<QByteAr
             //only the head has changed, get the current version of the mail
             //replace the head and store the new mail in the file
             const QByteArray currentData = dir.readEntry( newItem.remoteId() );
+            if ( currentData.isEmpty() && !dir.lastError().isEmpty() ) {
+              restartMaildirScan( dir );
+              cancelTask( dir.lastError() );
+              return;
+            }
             const QByteArray newHead = mail->head();
             mail->setContent( currentData );
             mail->setHead( newHead );
@@ -363,6 +369,11 @@ void MaildirResource::itemChanged( const Akonadi::Item& item, \
const QSet<QByteAr  cancelTask( dir.lastError() );
             return;
           }
+          mChangedFiles.insert( newItem.remoteId() );
+        } else {
+            restartMaildirScan( dir );
+            cancelTask( i18n( "Maildir resource got a non-mail content!" ) );
+            return;
         }
       }
 
@@ -403,6 +414,8 @@ void MaildirResource::itemMoved( const Item &item, const \
Collection &source, con  
   const QString newRid = sourceDir.moveEntryTo( item.remoteId(), destDir );
 
+  mChangedFiles.insert( newRid );
+
   restartMaildirScan( sourceDir );
   restartMaildirScan( destDir );
 
@@ -691,7 +704,7 @@ void MaildirResource::slotDirChanged(const QString& dir)
 {
   QFileInfo fileInfo( dir );
   if ( fileInfo.isFile() ) {
-    slotFileChanged( dir );
+    slotFileChanged( fileInfo );
     return;
   }
 
@@ -739,11 +752,14 @@ void MaildirResource::fsWatchDirFetchResult(KJob* job)
   synchronizeCollection( cols.first().id() );
 }
 
-void MaildirResource::slotFileChanged( const QString& fileName )
+void MaildirResource::slotFileChanged( const QFileInfo& fileInfo )
 {
-  QFileInfo fileInfo( fileName );
+  const QString key = fileInfo.fileName();
+  if ( mChangedFiles.contains( key ) ) {
+    mChangedFiles.remove( key );
+    return;
+  }
 
-  QString key = fileInfo.fileName();
   QString path = fileInfo.path();
   if ( path.endsWith( QLatin1String( "/new" ) ) ) {
     path.remove( path.length() - 4, 4 );
diff --git a/resources/maildir/maildirresource.h \
b/resources/maildir/maildirresource.h index 10f03e9..8445100 100644
--- a/resources/maildir/maildirresource.h
+++ b/resources/maildir/maildirresource.h
@@ -23,6 +23,7 @@
 #include <akonadi/collection.h>
 #include <akonadi/resourcebase.h>
 
+class QFileInfo;
 class KDirWatch;
 namespace Akonadi_Maildir_Resource
 {
@@ -71,7 +72,7 @@ class MaildirResource : public Akonadi::ResourceBase, public \
Akonadi::AgentBase:  void configurationChanged();
     void slotItemsRetrievalResult(KJob* job);
     void slotDirChanged( const QString &dir );
-    void slotFileChanged( const QString &fileName );
+    void slotFileChanged( const QFileInfo &fileInfo );
     void fsWatchDirFetchResult( KJob* job );
     void fsWatchFileFetchResult( KJob* job );
     void fsWatchFileModifyResult( KJob* job );
@@ -95,6 +96,7 @@ private:
     Akonadi_Maildir_Resource::MaildirSettings *mSettings;
     KDirWatch *mFsWatcher;
     QHash<QString, KPIM::Maildir> mMaildirsForCollection;
+    QSet<QString> mChangedFiles; //files changed by the resource and that should be \
ignored in slotFileChanged  
 };
 


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

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