[akonadi] New cleanup in "akonadictl fsck"
Rex Dieter
rdieter at fedoraproject.org
Thu Mar 15 14:48:17 UTC 2012
commit d28f28f866cc8135ccb65571996336d7a878ecd5
Author: Rex Dieter <rdieter at fedoraproject.org>
Date: Thu Mar 15 09:48:15 2012 -0500
New cleanup in "akonadictl fsck"
akonadi-cleanup_orphan_resources.patch | 114 ++++++++++++++++++++++++++++++++
akonadi.spec | 12 +++-
2 files changed, 125 insertions(+), 1 deletions(-)
---
diff --git a/akonadi-cleanup_orphan_resources.patch b/akonadi-cleanup_orphan_resources.patch
new file mode 100644
index 0000000..1398e79
--- /dev/null
+++ b/akonadi-cleanup_orphan_resources.patch
@@ -0,0 +1,114 @@
+commit 992096665110674e8e9bc5be6e91c5b78249266e
+Author: David Faure <faure at kde.org>
+Date: Fri Jan 20 00:23:55 2012 +0100
+
+ New cleanup in "akonadictl fsck": clean up orphan resources from the DB
+
+ The only way this can ever happen is when hacking agentsrc and removing
+ resources from it (or removing the whole ~/.config). But then you get
+ dead collection trees in kmail, always red, always unusable, and this is
+ the only way to clean this up.
+
+diff --git a/server/src/storagejanitor.cpp b/server/src/storagejanitor.cpp
+index ea520a8..0e26596 100644
+--- a/server/src/storagejanitor.cpp
++++ b/server/src/storagejanitor.cpp
+@@ -21,6 +21,7 @@
+
+ #include "storage/datastore.h"
+ #include "storage/selectquerybuilder.h"
++#include "resourcemanager.h"
+
+ #include <akdbus.h>
+ #include <akdebug.h>
+@@ -29,6 +30,8 @@
+ #include <libs/protocol_p.h>
+ #include <libs/xdgbasedirs_p.h>
+
++#include <agentmanagerinterface.h>
++
+ #include <QStringBuilder>
+ #include <QtDBus/QDBusConnection>
+ #include <QtSql/QSqlQuery>
+@@ -70,8 +73,11 @@ StorageJanitor::~StorageJanitor()
+ DataStore::self()->close();
+ }
+
+-void StorageJanitor::check()
++void StorageJanitor::check() // implementation of `akonadictl fsck`
+ {
++ inform( "Looking for resources in the DB not matching a configured resource..." );
++ findOrphanedResources();
++
+ inform( "Looking for collections not belonging to a valid resource..." );
+ findOrphanedCollections();
+
+@@ -106,6 +112,43 @@ void StorageJanitor::check()
+ inform( "Consistency check done." );
+ }
+
++void StorageJanitor::findOrphanedResources()
++{
++ SelectQueryBuilder<Resource> qbres;
++ OrgFreedesktopAkonadiAgentManagerInterface iface(
++ AkDBus::serviceName(AkDBus::Control),
++ QLatin1String( "/AgentManager" ),
++ QDBusConnection::sessionBus(),
++ this
++ );
++ if (!iface.isValid()) {
++ inform( QString::fromLatin1("ERROR: Couldn't talk to %1").arg(AkDBus::Control) );
++ return;
++ }
++ const QStringList knownResources = iface.agentInstances();
++ if (knownResources.isEmpty()) {
++ inform( QString::fromLatin1("ERROR: no known resources. This must be a mistake?") );
++ return;
++ }
++ akDebug() << "Known resources:" << knownResources;
++ qbres.addValueCondition( Resource::nameFullColumnName(), Query::NotIn, QVariant(knownResources) );
++ qbres.addValueCondition( Resource::idFullColumnName(), Query::NotEquals, 1 ); // skip akonadi_search_resource
++ qbres.exec();
++ //akDebug() << "SQL:" << qbres.query().lastQuery();
++ const Resource::List orphanResources = qbres.result();
++ if ( orphanResources.size() > 0 ) {
++ QStringList resourceNames;
++ foreach ( const Resource& resource, orphanResources ) {
++ resourceNames.append(resource.name());
++ }
++ inform( QString::fromLatin1( "Found %1 orphan resources: %2" ).arg( orphanResources.size() ). arg( resourceNames.join(QLatin1String(",")) ) );
++ foreach ( const QString& resourceName, resourceNames ) {
++ inform( QString::fromLatin1( "Removing resource %1" ).arg( resourceName ) );
++ ResourceManager::self()->removeResourceInstance( resourceName );
++ }
++ }
++}
++
+ void StorageJanitor::findOrphanedCollections()
+ {
+ SelectQueryBuilder<Collection> qb;
+@@ -137,7 +180,7 @@ void StorageJanitor::checkPathToRoot(const Akonadi::Collection& col)
+ + QLatin1Literal( ") belongs to a different resource than its parent." ) );
+ // can/should we actually fix that?
+ }
+-
++
+ checkPathToRoot( parent );
+ }
+
+diff --git a/server/src/storagejanitor.h b/server/src/storagejanitor.h
+index afc79c6..be3442e 100644
+--- a/server/src/storagejanitor.h
++++ b/server/src/storagejanitor.h
+@@ -63,6 +63,11 @@ class StorageJanitor : public QObject
+ void inform( const QString &msg );
+
+ /**
++ * Look for resources in the DB not existing in reality.
++ */
++ void findOrphanedResources();
++
++ /**
+ * Look for collections belonging to non-existent resources.
+ */
+ void findOrphanedCollections();
diff --git a/akonadi.spec b/akonadi.spec
index 2e34e55..3ecc441 100644
--- a/akonadi.spec
+++ b/akonadi.spec
@@ -9,7 +9,7 @@
Summary: PIM Storage Service
Name: akonadi
Version: 1.7.1
-Release: 1%{?dist}
+Release: 2%{?dist}
Group: System Environment/Libraries
License: LGPLv2+
@@ -24,6 +24,11 @@ Source0: http://download.kde.org/stable/akonadi/src/akonadi-%{version}.tar.bz2
%endif
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
+## upstream patches
+# https://projects.kde.org/projects/kdesupport/akonadi/repository/revisions/992096665110674e8e9bc5be6e91c5b78249266e
+# New cleanup in "akonadictl fsck"
+Patch100: akonadi-cleanup_orphan_resources.patch
+
%define mysql_conf_timestamp 20110629
BuildRequires: automoc4
@@ -71,6 +76,8 @@ Requires: %{name}%{?_isa} = %{version}-%{release}
%prep
%setup -q -n akonadi-%{version}
+%patch100 -p1 -b .cleanup_orphan_resources
+
%build
mkdir -p %{_target_platform}
@@ -171,6 +178,9 @@ fi
%changelog
+* Thu Mar 15 2012 Rex Dieter <rdieter at fedoraproject.org> 1.7.1-2
+- New cleanup in "akonadictl fsck"
+
* Tue Mar 06 2012 Rex Dieter <rdieter at fedoraproject.org> 1.7.1-1
- 1.7.1
More information about the scm-commits
mailing list