Git commit e38b776219bc0af6b06eff34a502cb4c80f232b4 by Andras Mantia. Committed on 15/11/2013 at 20:18. Pushed by amantia into branch 'master'. Improve error handling (fixes after review). REVIEW: 113890 M +6 -7 resources/maildir/libmaildir/maildir.cpp M +9 -5 resources/mixedmaildir/mixedmaildirstore.cpp http://commits.kde.org/kdepim-runtime/e38b776219bc0af6b06eff34a502cb4c80f23= 2b4 diff --git a/resources/maildir/libmaildir/maildir.cpp b/resources/maildir/l= ibmaildir/maildir.cpp index 712994d..dc202cc 100644 --- a/resources/maildir/libmaildir/maildir.cpp +++ b/resources/maildir/libmaildir/maildir.cpp @@ -559,10 +559,9 @@ bool Maildir::writeEntry( const QString& key, const QB= yteArray& data ) d->lastError =3D i18n( "Cannot locate mail file %1." ).arg( key ); return false; } - bool result; QFile f( realKey ); - result =3D f.open( QIODevice::WriteOnly ); - result &=3D ( f.write( data ) !=3D -1 ); + bool result =3D f.open( QIODevice::WriteOnly ); + result =3D result & ( f.write( data ) !=3D -1 ); f.close(); if ( !result) { d->lastError =3D i18n( "Cannot write to mail file %1." ).arg( realK= ey ); @@ -587,10 +586,9 @@ QString Maildir::addEntry( const QByteArray& data ) curKey =3D d->path + QLatin1String( "/cur/" ) + uniqueKey; } while ( QFile::exists( key ) || QFile::exists( finalKey ) || QFile::= exists( curKey ) ); = - bool result; QFile f( key ); - result =3D f.open( QIODevice::WriteOnly ); - result &=3D ( f.write( data ) !=3D -1 ); + bool result =3D f.open( QIODevice::WriteOnly ); + result =3D result & ( f.write( data ) !=3D -1 ); f.close(); if ( !result) { d->lastError =3D i18n( "Cannot write to mail file %1." ).arg( key ); @@ -699,7 +697,7 @@ QString Maildir::changeEntryFlags(const QString& key, c= onst Akonadi::Item::Flags = if ( !f.rename( finalKey ) ) { qWarning() << "Maildir: Failed to rename entry: " << f.fileName() = << " to " << finalKey << "! Error: " << f.errorString(); - d->lastError =3D i18n("Failed to update the file name %1 to %2 on = the disk. The error was: %3.").arg(f.fileName()).arg(finalKey).arg(f.errorS= tring()); + d->lastError =3D i18n( "Failed to update the file name %1 to %2 on= the disk. The error was: %3." ).arg( f.fileName(), finalKey, f.errorString= () ); return QString(); } = @@ -774,6 +772,7 @@ QString Maildir::moveEntryTo( const QString &key, const= Maildir &destination ) { const QString realKey( d->findRealKey( key ) ); if ( realKey.isEmpty() ) { + kWarning() << "Unable to find: " << key; d->lastError =3D i18n( "Cannot locate mail file %1." ).arg( key ); return QString(); } diff --git a/resources/mixedmaildir/mixedmaildirstore.cpp b/resources/mixed= maildir/mixedmaildirstore.cpp index 80f5735..103dcdd 100644 --- a/resources/mixedmaildir/mixedmaildirstore.cpp +++ b/resources/mixedmaildir/mixedmaildirstore.cpp @@ -318,10 +318,11 @@ class MaildirContext QString addEntry( const QByteArray &data ) { const QString result =3D mMaildir.addEntry( data ); if ( !result.isEmpty() && mHasIndexData ) { - //TODO: use the error string? - kWarning() << mMaildir.lastError(); mIndexData.insert( result, KMIndexDataPtr( new KMIndexData ) ); Q_ASSERT( mIndexData.value( result )->isEmpty() ); + } else { + //TODO: use the error string? + kWarning() << mMaildir.lastError(); } = return result; @@ -346,8 +347,6 @@ class MaildirContext QString moveEntryTo( const QString &key, MaildirContext &destination )= { const QString result =3D mMaildir.moveEntryTo( key, destination.mMai= ldir ); if ( !result.isEmpty() ) { - //TODO error handling? - kWarning() << mMaildir.lastError(); if ( mHasIndexData ) { mIndexData.remove( key ); } @@ -355,6 +354,9 @@ class MaildirContext if ( destination.mHasIndexData ) { destination.mIndexData.insert( result, KMIndexDataPtr( new KMInd= exData ) ); } + } else { + //TODO error handling? + kWarning() << mMaildir.lastError(); } = return result; @@ -370,7 +372,9 @@ class MaildirContext = bool isValid( QString &error ) const { bool result =3D mMaildir.isValid(); - if ( !result ) error =3D mMaildir.lastError(); + if ( !result ) { + error =3D mMaildir.lastError(); + } return result; } =20