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

List:       kde-commits
Subject:    [kdepim-runtime/KDE/4.12] resources/maildir: Improve maildir by several factors: we can get dirty si
From:       Andras Mantia <amantia () kde ! org>
Date:       2013-11-23 15:21:54
Message-ID: E1VkF1u-0003Ni-CE () scm ! kde ! org
[Download RAW message or body]

Git commit 9dfae10348ca00ed22679260205bd4ef5f9f6b2a by Andras Mantia.
Committed on 17/11/2013 at 10:22.
Pushed by amantia into branch 'KDE/4.12'.

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).

(cherry picked from commit d55b5f0a39b32ff243c5d7c32f2b27df0f58cb25)

Conflicts:
	resources/maildir/maildirresource.cpp

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

http://commits.kde.org/kdepim-runtime/9dfae10348ca00ed22679260205bd4ef5f9f6b2a

diff --git a/resources/maildir/maildirresource.cpp \
b/resources/maildir/maildirresource.cpp index bb3cf33..68a9506 100644
--- a/resources/maildir/maildirresource.cpp
+++ b/resources/maildir/maildirresource.cpp
@@ -282,6 +282,7 @@ void MaildirResource::itemAdded( const Akonadi::Item & item, \
const Akonadi::Coll  stopMaildirScan( dir );
 
     const QString rid = dir.addEntry( mail->encodedContent() );
+    mChangedFiles.insert( rid );
 
     restartMaildirScan( dir );
 
@@ -355,6 +356,11 @@ void MaildirResource::itemChanged( const Akonadi::Item& item, \
const QSet<QByteAr  data = mail->encodedContent();
           }
           dir.writeEntry( newItem.remoteId(), data );
+          mChangedFiles.insert( newItem.remoteId() );
+        } else {
+            restartMaildirScan( dir );
+            cancelTask( i18n( "Error: Unsupported type." ) );
+            return;
         }
       }
 
@@ -396,6 +402,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 );
 
@@ -685,7 +693,7 @@ void MaildirResource::slotDirChanged(const QString& dir)
 {
   QFileInfo fileInfo( dir );
   if ( fileInfo.isFile() ) {
-    slotFileChanged( dir );
+    slotFileChanged( fileInfo );
     return;
   }
 
@@ -733,11 +741,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