redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2005-2009 Patrick Ohly <patrick.ohly@gmx.de>
|
|
|
|
* Copyright (C) 2009 Intel Corporation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) version 3.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "EvolutionSyncSource.h"
|
2010-02-22 16:19:12 +01:00
|
|
|
#include <syncevo/SmartPtr.h>
|
2014-04-02 14:57:56 +02:00
|
|
|
#include <syncevo/Exception.h>
|
2013-05-23 17:38:04 +02:00
|
|
|
#include <syncevo/GLibSupport.h>
|
|
|
|
|
2013-05-24 09:42:13 +02:00
|
|
|
#ifdef USE_EDS_CLIENT
|
|
|
|
#include <syncevo/GValueSupport.h>
|
2013-05-23 17:38:04 +02:00
|
|
|
SE_GLIB_TYPE(GKeyFile, g_key_file)
|
2013-05-24 09:42:13 +02:00
|
|
|
#endif
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
|
2009-10-05 14:49:32 +02:00
|
|
|
#include <syncevo/declarations.h>
|
2009-10-02 17:23:53 +02:00
|
|
|
SE_BEGIN_CXX
|
|
|
|
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
#ifdef HAVE_EDS
|
|
|
|
|
2012-07-24 10:25:20 +02:00
|
|
|
#ifdef USE_EDS_CLIENT
|
|
|
|
|
|
|
|
void EvolutionSyncSource::getDatabasesFromRegistry(SyncSource::Databases &result,
|
|
|
|
const char *extension,
|
|
|
|
ESource *(*refDef)(ESourceRegistry *))
|
|
|
|
{
|
2012-12-03 11:44:01 +01:00
|
|
|
ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry();
|
2012-07-24 10:25:20 +02:00
|
|
|
ESourceListCXX sources(e_source_registry_list_sources(registry, extension));
|
|
|
|
ESourceCXX def(refDef ? refDef(registry) : NULL,
|
2013-05-13 21:33:34 +02:00
|
|
|
TRANSFER_REF);
|
2018-01-16 10:58:04 +01:00
|
|
|
for (ESource *source: sources) {
|
2012-07-24 10:25:20 +02:00
|
|
|
result.push_back(Database(e_source_get_display_name(source),
|
|
|
|
e_source_get_uid(source),
|
|
|
|
e_source_equal(def, source)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void handleErrorCB(EClient */*client*/, const gchar *error_msg, gpointer user_data)
|
|
|
|
{
|
|
|
|
EvolutionSyncSource *that = static_cast<EvolutionSyncSource *>(user_data);
|
2013-04-08 19:17:36 +02:00
|
|
|
SE_LOG_ERROR(that->getDisplayName(), "%s", error_msg);
|
2012-07-24 10:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EClientCXX EvolutionSyncSource::openESource(const char *extension,
|
|
|
|
ESource *(*refBuiltin)(ESourceRegistry *),
|
2018-01-16 17:17:34 +01:00
|
|
|
const std::function<EClient *(ESource *, GError **gerror)> &newClient)
|
2012-07-24 10:25:20 +02:00
|
|
|
{
|
|
|
|
EClientCXX client;
|
|
|
|
GErrorCXX gerror;
|
2012-12-03 11:44:01 +01:00
|
|
|
ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry();
|
2012-07-24 10:25:20 +02:00
|
|
|
ESourceListCXX sources(e_source_registry_list_sources(registry, extension));
|
|
|
|
string id = getDatabaseID();
|
|
|
|
ESource *source = findSource(sources, id);
|
|
|
|
|
|
|
|
if (!source) {
|
|
|
|
if (refBuiltin && (id.empty() || id == "<<system>>")) {
|
2013-05-13 21:33:34 +02:00
|
|
|
ESourceCXX builtin(refBuiltin(registry), TRANSFER_REF);
|
2012-07-24 10:25:20 +02:00
|
|
|
client = EClientCXX::steal(newClient(builtin, gerror));
|
|
|
|
// } else if (!id.compare(0, 7, "file://")) {
|
|
|
|
// TODO: create source
|
|
|
|
// m_calendar = ECalClientCXX::steal(e_cal_client_new_from_uri(id.c_str(), sourceType(), gerror));
|
|
|
|
} else {
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(SE_HERE, string("database not found: '") + id + "'");
|
2012-07-24 10:25:20 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
client = EClientCXX::steal(newClient(source, gerror));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!client) {
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(SE_HERE, "accessing database", gerror);
|
2012-07-24 10:25:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Listen for errors
|
|
|
|
g_signal_connect (client, "backend-error", G_CALLBACK(handleErrorCB), this);
|
|
|
|
g_signal_connect_after(client,
|
|
|
|
"backend-died",
|
2014-04-02 14:57:56 +02:00
|
|
|
G_CALLBACK(Exception::fatalError),
|
2012-07-24 10:25:20 +02:00
|
|
|
(void *)"Evolution Data Server has died unexpectedly.");
|
|
|
|
|
|
|
|
|
2018-01-01 15:05:12 +01:00
|
|
|
int retries = 0;
|
2013-04-02 16:36:21 +02:00
|
|
|
while (true) {
|
|
|
|
// Always allow EDS to create the database. "only-if-exists =
|
|
|
|
// true" does not make sense.
|
|
|
|
if (!e_client_open_sync(client, false, NULL, gerror)) {
|
2018-01-01 15:05:12 +01:00
|
|
|
if (retries < 5) {
|
|
|
|
// EDS 3.18 and 3.26 have various race conditions during startup.
|
|
|
|
// Try a few times.
|
|
|
|
// https://bugzilla.gnome.org/show_bug.cgi?id=791306
|
|
|
|
SE_LOG_DEBUG(NULL, "Opening EDS source: ignoring error, trying again: %s", gerror->message);
|
2013-04-02 16:36:21 +02:00
|
|
|
gerror.clear();
|
|
|
|
sleep(1);
|
2018-01-01 15:05:12 +01:00
|
|
|
retries++;
|
2013-04-02 16:36:21 +02:00
|
|
|
} else {
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(SE_HERE, "opening database", gerror);
|
2012-07-24 10:25:20 +02:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-02 16:36:21 +02:00
|
|
|
// Success!
|
|
|
|
break;
|
2012-07-24 10:25:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-13 17:57:28 +02:00
|
|
|
// record result for SyncSource::getDatabase()
|
|
|
|
source = e_client_get_source(client);
|
|
|
|
if (source) {
|
|
|
|
Database database(e_source_get_display_name(source),
|
|
|
|
e_source_get_uid(source));
|
|
|
|
setDatabase(database);
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:25:20 +02:00
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
2012-09-13 17:57:28 +02:00
|
|
|
SyncSource::Database EvolutionSyncSource::createDatabase(const Database &database)
|
|
|
|
{
|
2013-05-23 17:38:04 +02:00
|
|
|
// We'll need this later. Create it before doing any real work.
|
|
|
|
ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry();
|
|
|
|
|
|
|
|
// Clone the system DB. This allows the distro to change the
|
|
|
|
// configuration (backend, extensions (= in particular
|
|
|
|
// the contacts DB summary fields)) without having to
|
|
|
|
// modify SyncEvolution.
|
|
|
|
ESourceCXX systemSource = refSystemDB();
|
|
|
|
gsize len;
|
|
|
|
PlainGStr ini(e_source_to_string(systemSource, &len));
|
|
|
|
|
|
|
|
// Modify the entries in the key file directly. We can't
|
|
|
|
// instantiate an ESource (no API for it), copying the values from
|
|
|
|
// the key file into a fresh ESource is difficult (would have to
|
|
|
|
// reimplement EDS internal encoding/decoding), and copying from
|
|
|
|
// systemSource is hard (don't know which extensions it has,
|
|
|
|
// cannot instantiate extensions of unknown types, because
|
|
|
|
// e_source_get_extension() only works for types that were
|
|
|
|
// created).
|
|
|
|
static const char *mainSection = "Data Source";
|
|
|
|
GKeyFileCXX keyfile(g_key_file_new(), TRANSFER_REF);
|
2012-09-13 17:57:28 +02:00
|
|
|
GErrorCXX gerror;
|
2013-05-23 17:38:04 +02:00
|
|
|
if (!g_key_file_load_from_data(keyfile, ini, len, G_KEY_FILE_NONE, gerror)) {
|
2014-04-02 14:57:56 +02:00
|
|
|
gerror.throwError(SE_HERE, "parsing ESource .ini data");
|
2012-09-13 17:57:28 +02:00
|
|
|
}
|
2013-06-28 11:05:13 +02:00
|
|
|
PlainGStrArray keys(g_key_file_get_keys(keyfile, mainSection, NULL, gerror));
|
|
|
|
if (!keys) {
|
2014-04-02 14:57:56 +02:00
|
|
|
gerror.throwError(SE_HERE, "listing keys in main section");
|
2013-06-28 11:05:13 +02:00
|
|
|
}
|
|
|
|
for (int i = 0; keys.at(i); i++) {
|
2013-10-18 09:50:18 +02:00
|
|
|
if (boost::starts_with(keys.at(i), "DisplayName[")) {
|
2013-06-28 11:05:13 +02:00
|
|
|
if (!g_key_file_remove_key(keyfile, mainSection, keys.at(i), gerror)) {
|
2014-04-02 14:57:56 +02:00
|
|
|
gerror.throwError(SE_HERE, "remove key");
|
2013-06-28 11:05:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-23 17:38:04 +02:00
|
|
|
g_key_file_set_string(keyfile, mainSection, "DisplayName", database.m_name.c_str());
|
|
|
|
g_key_file_set_boolean(keyfile, mainSection, "Enabled", true);
|
|
|
|
ini = g_key_file_to_data(keyfile, &len, NULL);
|
|
|
|
const char *configDir = g_get_user_config_dir();
|
|
|
|
int fd;
|
|
|
|
std::string filename;
|
|
|
|
std::string uid;
|
|
|
|
|
|
|
|
// Create sources dir. It might have been removed (for example, while
|
|
|
|
// testing) without having been recreated by evolution-source-registry.
|
|
|
|
std::string sourceDir = StringPrintf("%s/evolution/sources",
|
|
|
|
configDir);
|
|
|
|
mkdir_p(sourceDir);
|
|
|
|
|
|
|
|
// Create unique ID if necessary.
|
|
|
|
while (true) {
|
|
|
|
uid = database.m_uri.empty() ?
|
|
|
|
UUID() :
|
|
|
|
database.m_uri;
|
|
|
|
filename = StringPrintf("%s/%s.source", sourceDir.c_str(), uid.c_str());
|
|
|
|
fd = ::open(filename.c_str(),
|
|
|
|
O_WRONLY|O_CREAT|O_EXCL,
|
|
|
|
S_IRUSR|S_IWUSR);
|
|
|
|
if (fd >= 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (errno == EEXIST) {
|
|
|
|
if (!database.m_uri.empty()) {
|
|
|
|
SE_THROW(StringPrintf("ESource UUID %s already in use", database.m_uri.c_str()));
|
|
|
|
} else {
|
|
|
|
// try again with new random UUID
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SE_THROW(StringPrintf("creating %s failed: %s", filename.c_str(), strerror(errno)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ssize_t written = write(fd, ini.get(), len);
|
|
|
|
int res = ::close(fd);
|
2013-05-24 09:42:13 +02:00
|
|
|
if (written != (ssize_t)len || res) {
|
2013-05-23 17:38:04 +02:00
|
|
|
SE_THROW(StringPrintf("writing to %s failed: %s", filename.c_str(), strerror(errno)));
|
2013-02-28 16:39:24 +01:00
|
|
|
}
|
|
|
|
|
2013-05-23 17:38:04 +02:00
|
|
|
// We need to wait until ESourceRegistry notices the new file.
|
|
|
|
SE_LOG_DEBUG(getDisplayName(), "waiting for ESourceRegistry to notice new ESource %s", uid.c_str());
|
|
|
|
while (!ESourceCXX(e_source_registry_ref_source(registry, uid.c_str()), TRANSFER_REF)) {
|
|
|
|
// This will block forever if called from the non-main-thread.
|
|
|
|
// Don't do that...
|
|
|
|
g_main_context_iteration(NULL, true);
|
2012-09-13 17:57:28 +02:00
|
|
|
}
|
2013-05-23 17:38:04 +02:00
|
|
|
SE_LOG_DEBUG(getDisplayName(), "ESourceRegistry has new ESource %s", uid.c_str());
|
|
|
|
|
|
|
|
// Try triggering that by attempting to create an ESource with the same
|
|
|
|
// UUID. Does not work! evolution-source-registry simply overwrites the
|
|
|
|
// file that we created earlier.
|
|
|
|
// ESourceCXX source(e_source_new_with_uid(uid.c_str(),
|
|
|
|
// NULL, gerror),
|
|
|
|
// TRANSFER_REF);
|
|
|
|
// e_source_set_display_name(source, "syncevolution-fake");
|
|
|
|
// e_source_set_parent(source, "local-stub");
|
|
|
|
// ESourceListCXX sources;
|
|
|
|
// sources.push_back(source.ref()); // ESourceListCXX unrefs sources it points to
|
|
|
|
// if (!e_source_registry_create_sources_sync(registry,
|
|
|
|
// sources,
|
|
|
|
// NULL,
|
|
|
|
// gerror)) {
|
2014-04-02 14:57:56 +02:00
|
|
|
// gerror.throwError(SE_HERE, StringPrintf("creating EDS database of type %s with name '%s'%s%s",
|
2013-05-23 17:38:04 +02:00
|
|
|
// sourceExtension(),
|
|
|
|
// database.m_name.c_str(),
|
|
|
|
// database.m_uri.empty() ? "" : " and URI ",
|
|
|
|
// database.m_uri.c_str()));
|
|
|
|
// } else {
|
|
|
|
// SE_THROW("creating syncevolution-fake ESource succeeded although it should have failed");
|
|
|
|
// }
|
|
|
|
|
|
|
|
return Database(database.m_name, uid);
|
2012-09-13 17:57:28 +02:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:42:13 +02:00
|
|
|
void EvolutionSyncSource::deleteDatabase(const std::string &uri, RemoveData removeData)
|
2012-09-13 17:57:28 +02:00
|
|
|
{
|
2012-12-03 11:44:01 +01:00
|
|
|
ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry();
|
2013-05-13 21:33:34 +02:00
|
|
|
ESourceCXX source(e_source_registry_ref_source(registry, uri.c_str()), TRANSFER_REF);
|
2012-09-13 17:57:28 +02:00
|
|
|
if (!source) {
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(SE_HERE, StringPrintf("EDS database with URI '%s' cannot be deleted, does not exist",
|
|
|
|
uri.c_str()));
|
2012-09-13 17:57:28 +02:00
|
|
|
}
|
|
|
|
GErrorCXX gerror;
|
|
|
|
if (!e_source_remove_sync(source, NULL, gerror)) {
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(SE_HERE, StringPrintf("deleting EDS database with URI '%s'", uri.c_str()),
|
2012-09-13 17:57:28 +02:00
|
|
|
gerror);
|
|
|
|
}
|
2013-05-24 09:42:13 +02:00
|
|
|
if (removeData == REMOVE_DATA_FORCE) {
|
|
|
|
// Don't wait for evolution-source-registry cache-reaper to
|
|
|
|
// run, instead remove files ourselves. The reaper runs only
|
|
|
|
// once per day and also only moves the data into a trash
|
|
|
|
// folder, were it would linger until finally removed after 30
|
|
|
|
// days.
|
|
|
|
//
|
|
|
|
// This is equivalent to "rm -rf $XDG_DATA_HOME/evolution/*/<uuid>".
|
|
|
|
std::string basedir = StringPrintf("%s/evolution", g_get_user_data_dir());
|
|
|
|
if (isDir(basedir)) {
|
2018-01-16 10:58:04 +01:00
|
|
|
for (const std::string &kind: ReadDir(basedir)) {
|
2013-05-24 09:42:13 +02:00
|
|
|
std::string subdir = basedir + "/" + kind;
|
|
|
|
if (isDir(subdir)) {
|
2018-01-16 10:58:04 +01:00
|
|
|
for (const std::string &source: ReadDir(subdir)) {
|
2013-05-24 09:42:13 +02:00
|
|
|
// We assume that the UUID of the database
|
|
|
|
// consists only of characters which can be
|
|
|
|
// used in the directory name, i.e., no
|
|
|
|
// special encoding of the directory name.
|
|
|
|
if (source == uri) {
|
|
|
|
rm_r(subdir + "/" + source);
|
|
|
|
// Keep searching, just in case, although
|
|
|
|
// there should only be one.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-13 17:57:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-24 10:25:20 +02:00
|
|
|
#endif // USE_EDS_CLIENT
|
|
|
|
|
|
|
|
ESource *EvolutionSyncSource::findSource(const ESourceListCXX &list, const string &id )
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
{
|
2010-02-22 16:19:12 +01:00
|
|
|
string finalID;
|
|
|
|
if (!id.empty()) {
|
|
|
|
finalID = id;
|
|
|
|
} else {
|
2012-07-24 10:25:20 +02:00
|
|
|
// Nothing selected specifically, use the one marked as default.
|
2018-01-16 10:58:04 +01:00
|
|
|
for (const Database &db: getDatabases()) {
|
2010-02-22 16:19:12 +01:00
|
|
|
if (db.m_isDefault) {
|
|
|
|
finalID = db.m_uri;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-24 10:25:20 +02:00
|
|
|
#ifdef USE_EDS_CLIENT
|
2018-01-16 10:58:04 +01:00
|
|
|
for (ESource *source: list) {
|
2012-07-24 10:25:20 +02:00
|
|
|
bool found =
|
|
|
|
!finalID.compare(e_source_get_display_name(source)) ||
|
|
|
|
!finalID.compare(e_source_get_uid(source));
|
|
|
|
if (found) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
for (GSList *g = e_source_list_peek_groups (list.get()); g; g = g->next) {
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
ESourceGroup *group = E_SOURCE_GROUP (g->data);
|
|
|
|
GSList *s;
|
|
|
|
for (s = e_source_group_peek_sources (group); s; s = s->next) {
|
|
|
|
ESource *source = E_SOURCE (s->data);
|
2011-06-17 11:53:59 +02:00
|
|
|
GStringPtr uri(e_source_get_uri(source));
|
2010-02-22 16:19:12 +01:00
|
|
|
bool found = finalID.empty() ||
|
|
|
|
!finalID.compare(e_source_peek_name(source)) ||
|
|
|
|
(uri && !finalID.compare(uri));
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
if (found) {
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-24 10:25:20 +02:00
|
|
|
#endif
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:57:56 +02:00
|
|
|
void EvolutionSyncSource::throwError(const SourceLocation &where, const string &action, GErrorCXX &gerror)
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
{
|
|
|
|
string gerrorstr;
|
|
|
|
if (gerror) {
|
|
|
|
gerrorstr += ": ";
|
|
|
|
gerrorstr += gerror->message;
|
|
|
|
} else {
|
|
|
|
gerrorstr = ": failure";
|
|
|
|
}
|
|
|
|
|
2014-04-02 14:57:56 +02:00
|
|
|
throwError(where, action + gerrorstr);
|
redesigned SyncSource base class + API
The main motivation for this change is that it allows the implementor
of a backend to choose the implementations for the different aspects
of a datasource (change tracking, item import/export, logging, ...)
independently of each other. For example, change tracking via revision
strings can now be combined with exchanging data with the Synthesis
engine via a single string (the traditional method in SyncEvolution)
and with direct access to the Synthesis field list (now possible for
the first time).
The new backend API is based on the concept of providing
implementations for certain functionality via function objects instead
of implementing certain virtual methods. The advantage is that
implementors can define their own, custom interfaces and mix and match
implementations of the different groups of functionality.
Logging (see SyncSourceLogging in a later commit) can be done by
wrapping some arbitrary other item import/export function objects
(decorator design pattern).
The class hierarchy is now this:
- SyncSourceBase: interface for common utility code, all other
classes are derived from it and thus can use that code
- SyncSource: base class which implements SyncSourceBase and
hooks a datasource into the SyncEvolution core;
its "struct Operations" holds the function objects which
can be implemented in different ways
- TestingSyncSource: combines some of the following classes
into an interface that is expected by the client-test
program; backends only have to derive from (and implement this)
if they want to use the automated testing
- TrackingSyncSource: provides the same functionality as
before (change tracking via revision strings, item import/export
as string) in a single interface; the description of the pure
virtual methods are duplicated so that developers can go through
this class and find everything they need to know to implement
it
The following classes contain the code that was previously
found in the EvolutionSyncSource base class. Implementors
can derive from them and call the init() methods to inherit
and activate the functionality:
- SyncSourceSession: binds Synthesis session callbacks to
virtual methods beginSync(), endSync()
- SyncSourceChanges: implements Synthesis item tracking callbacks
with set of LUIDs that the user of the class has to fill
- SyncSourceDelete: binds Synthesis delete callback to
virtual method
- SyncSourceRaw: read and write items in the backends format,
used for testing and backup/restore
- SyncSourceSerialize: exchanges items with Synthesis engine
using a string representation of the data; this is how
EvolutionSyncSource has traditionally worked, so much of the
same virtual methods are now in this class
- SyncSourceRevisions: utility class which does change tracking
via some kind of "revision" string which changes each time
an item is modified; this code was previously in the
TrackingSyncSource
2009-08-25 09:27:46 +02:00
|
|
|
}
|
|
|
|
#endif // HAVE_EDS
|
2009-10-02 17:23:53 +02:00
|
|
|
|
|
|
|
SE_END_CXX
|