command line import/export: failed for non-peer configs

Besides the issue with reading the "type" (MBC #3157),
operations like "--print-items @some-context addressbook"
also failed because the TrackingSyncSource would try to write
updated id/rev pairs into a DevNullConfigNode, set because
there is no tracking node in @some-context.

DevNullConfigNode does not allow writing. This patch uses
a set of config nodes where the tracking node is volatile and
allows writing.

The additional benefit also for peer configs is that the SyncSource
can no longer overwrite the change tracking for that peer
accidentally because it never gets access to that node.
This commit is contained in:
Patrick Ohly 2010-06-16 13:51:50 +02:00
parent 6ff8f4ff0c
commit 3c3532c280
3 changed files with 30 additions and 1 deletions

View file

@ -730,7 +730,7 @@ bool Cmdline::run() {
context.reset(createSyncClient());
context->setOutput(&m_out);
string sourceName = *m_sources.begin();
SyncSourceNodes sourceNodes = context->getSyncSourceNodes(sourceName);
SyncSourceNodes sourceNodes = context->getSyncSourceNodesNoTracking(sourceName);
SyncSourceParams params(sourceName, sourceNodes);
cxxptr<SyncSource> source(SyncSource::createSource(params, true));

View file

@ -957,6 +957,19 @@ ConstSyncSourceNodes SyncConfig::getSyncSourceNodes(const string &name,
return const_cast<SyncConfig *>(this)->getSyncSourceNodes(name, changeId);
}
SyncSourceNodes SyncConfig::getSyncSourceNodesNoTracking(const string &name)
{
SyncSourceNodes nodes = getSyncSourceNodes(name);
boost::shared_ptr<ConfigNode> dummy(new VolatileConfigNode());
return SyncSourceNodes(nodes.m_havePeerNode,
nodes.m_sharedNode,
nodes.m_peerNode,
nodes.m_hiddenPeerNode,
dummy,
nodes.m_serverNode,
nodes.m_cacheDir);
}
static ConfigProperty syncPropSyncURL("syncURL",
"Identifies how to contact the peer,\n"
"best explained with some examples:\n"

View file

@ -1110,6 +1110,20 @@ class SyncConfig {
ConstSyncSourceNodes getSyncSourceNodes(const string &name,
const string &trackName = "") const;
/**
* Creates config nodes for a certain node. The nodes are not
* yet created in the backend if they do not yet exist.
* In contrast to the normal set of nodes, the tracking node
* is empty and discards all changes. This is useful when
* trying to initialize a SyncSource without a peer (normally
* has a tracking node which rejects writes with an exception)
* or with a peer without interfering with normal change tracking
* (normally SyncSource might overwrite change tracking).
*
* @param name the name of the sync source
*/
SyncSourceNodes getSyncSourceNodesNoTracking(const string &name);
/**
* initialize all properties with their default value
*/
@ -1483,6 +1497,8 @@ class SyncSourceNodes {
const boost::shared_ptr<ConfigNode> &serverNode,
const string &cacheDir);
friend class SyncConfig;
/** true if the peer-specific config node exists */
bool exists() const { return m_peerNode->exists(); }