PIM: allow configuration of session dirs (part of FDO #55921)

Useful for moving the session directories to a temporary file system.
They are essentially just useful for debugging when used as part of
PIM Manager.

- "logdir" - a directory in which directories are created with
             debug information about sync session
- "maxsessions" - number of sessions that are allowed to exist
                  after a sync (>= 0): 0 is special and means unlimited,
                  1 for just the latest, etc.;
                  old sessions are pruned heuristically (for example,
                  keep sessions where something changed instead of
                  some where nothing changed), so there is no hard
                  guarantee that the last n sessions are present.
This commit is contained in:
Patrick Ohly 2012-12-04 17:11:21 +01:00
parent 8f9669ec97
commit 07b82c9c64
3 changed files with 89 additions and 2 deletions

View file

@ -31,6 +31,7 @@
#include <syncevo/IniConfigNode.h>
#include <syncevo/BoostHelper.h>
#include <boost/lexical_cast.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/tokenizer.hpp>
#include <deque>
@ -866,6 +867,8 @@ static const char * const PEER_IP_TRANSPORT = "IP";
static const char * const PEER_DEF_TRANSPORT = PEER_BLUETOOTH_TRANSPORT;
static const char * const PEER_KEY_ADDRESS = "address";
static const char * const PEER_KEY_DATABASE = "database";
static const char * const PEER_KEY_LOGDIR = "logdir";
static const char * const PEER_KEY_MAXSESSIONS = "maxsessions";
static std::string GetEssential(const StringMap &properties, const char *key,
bool allowEmpty = false)
@ -890,10 +893,21 @@ void Manager::doSetPeer(const boost::shared_ptr<Session> &session,
std::string transport = GetWithDef(properties, PEER_KEY_TRANSPORT, PEER_DEF_TRANSPORT);
std::string address = GetEssential(properties, PEER_KEY_ADDRESS);
std::string database = GetWithDef(properties, PEER_KEY_DATABASE);
std::string logdir = GetWithDef(properties, PEER_KEY_LOGDIR);
std::string maxsessions = GetWithDef(properties, PEER_KEY_MAXSESSIONS);
unsigned maxLogDirs = 0;
if (!maxsessions.empty()) {
// https://svn.boost.org/trac/boost/ticket/5494
if (boost::starts_with(maxsessions, "-")) {
SE_THROW(StringPrintf("negative 'maxsessions' not allowed: %s", maxsessions.c_str()));
}
maxLogDirs = boost::lexical_cast<unsigned>(maxsessions);
}
std::string localDatabaseName = MANAGER_PREFIX + uid;
std::string context = StringPrintf("@%s%s", MANAGER_PREFIX, uid.c_str());
SE_LOG_DEBUG(NULL, NULL, "%s: creating config for protocol %s",
uid.c_str(),
protocol.c_str());
@ -923,6 +937,12 @@ void Manager::doSetPeer(const boost::shared_ptr<Session> &session,
config->setPeerIsClient(true);
config->setDumpData(false);
config->setPrintChanges(false);
if (!logdir.empty()) {
config->setLogDir(logdir);
}
if (!maxsessions.empty()) {
config->setMaxLogDirs(maxLogDirs);
}
boost::shared_ptr<PersistentSyncSourceConfig> source(config->getSyncSourceConfig(MANAGER_LOCAL_SOURCE));
source->setBackend("evolution-contacts");
source->setDatabaseID(localDatabaseName);
@ -954,6 +974,12 @@ void Manager::doSetPeer(const boost::shared_ptr<Session> &session,
config->setPreventSlowSync(false);
config->setDumpData(false);
config->setPrintChanges(false);
if (!logdir.empty()) {
config->setLogDir(logdir);
}
if (!maxsessions.empty()) {
config->setMaxLogDirs(maxLogDirs);
}
source = config->getSyncSourceConfig(MANAGER_REMOTE_SOURCE);
if (protocol == PEER_PBAP_PROTOCOL) {
// PBAP

View file

@ -57,6 +57,15 @@ string-to-string dict, with the following keys:
format (for transport=Bluetooth)
- "database" - empty or unset for the internal address book
(protocol=PBAP), the URI (protocol=SyncML)
- "logdir" - a directory in which directories are created with
debug information about sync session
- "maxsessions" - number of sessions that are allowed to exist
after a sync (>= 0): 0 is special and means unlimited,
1 for just the latest, etc.;
old sessions are pruned heuristically (for example,
keep sessions where something changed instead of
some where nothing changed), so there is no hard
guarantee that the last n sessions are present.
Address books
-------------

View file

@ -539,7 +539,7 @@ XDG root.
self.configurePhone(phone, uid, contacts)
self.syncPhone(phone, uid)
def listall(dirs, exclude):
def listall(dirs, exclude=[]):
result = {}
def append(dirname, entry):
fullname = os.path.join(dirname, entry)
@ -608,10 +608,62 @@ END:VCARD'''
# Also exclude modified database files.
self.assertEqual(files, listsyncevo(exclude=exclude))
self.exportCache(uid, export)
self.compareDBs(contacts, export)
# Keep one session directory in a non-default location.
logdir = xdg_root + '/pim-logdir'
peers[uid]['logdir'] = logdir
peers[uid]['maxsessions'] = '1'
self.manager.SetPeer(uid,
peers[uid],
timeout=self.timeout)
files = listsyncevo(exclude=exclude)
self.manager.SyncPeer(uid,
timeout=self.timeout)
exclude.append(logdir + '(/$)')
self.assertEqual(files, listsyncevo(exclude=exclude))
self.assertEqual(2, len(os.listdir(logdir)))
# At most one!
self.manager.SyncPeer(uid,
timeout=self.timeout)
exclude.append(logdir + '(/$)')
self.assertEqual(files, listsyncevo(exclude=exclude))
self.assertEqual(2, len(os.listdir(logdir)))
# And now prune none.
peers[uid]['maxsessions'] = '0'
self.manager.SetPeer(uid,
peers[uid],
timeout=self.timeout)
files = listsyncevo(exclude=exclude)
self.manager.SyncPeer(uid,
timeout=self.timeout)
exclude.append(logdir + '(/$)')
self.assertEqual(files, listsyncevo(exclude=exclude))
self.assertEqual(4, len(os.listdir(logdir)))
# Test invalid maxsession values.
with self.assertRaisesRegexp(dbus.DBusException,
"negative 'maxsessions' not allowed: -1"):
self.manager.SetPeer(uid,
{'protocol': 'PBAP',
'address': 'foo',
'maxsessions': '-1'},
timeout=self.timeout)
self.assertEqual(files, listsyncevo(exclude=exclude))
with self.assertRaisesRegexp(dbus.DBusException,
'bad lexical cast: source type value could not be interpreted as target'):
self.manager.SetPeer(uid,
{'protocol': 'PBAP',
'address': 'foo',
'maxsessions': '1000000000000000000000000000000000000000000000'},
timeout=self.timeout)
self.assertEqual(files, listsyncevo(exclude=exclude))
@timeout(100)
@property("ENV", "SYNCEVOLUTION_SYNC_DELAY=200")
@property("snapshot", "simple-sort")