LogDir: use a-z instead of number to make session dirs unique (MB #9759)

Using numbers 1..9..10.. as suffix had the problem that sorting
puts -10 in front of -2. Because we use hh-mm as base name, this
limited us to 9 sessions per minute, which is easily reached
when doing local testing.

By switching to -a to -z as suffix, we get 27 sessions per minute
before moving on to less nice characters (possible, but might
make file names unusuable eventually). That should be enough.
In local tests I got as far as -q.

With this change, the LogDir expire tests can be merged back
into one function.

An additional benefit is that the suffix is visually different
from the base name, which makes it a bit easier to identify
yyyy-mm-dd-hh-mm manually.
This commit is contained in:
Patrick Ohly 2010-02-26 10:08:02 +01:00
parent ed8a673fbc
commit 48ac9d79ac

View file

@ -363,10 +363,10 @@ public:
}
int sequence;
if (off != dateTime.npos) {
sequence = atoi(dateTime.substr(off + 1).c_str());
sequence = dateTime[off + 1] - 'a';
dateTime.resize(off);
} else {
sequence = 0;
sequence = -1;
}
pair <SeqMap_t::iterator, bool> entry = dateTimes2Seq.insert(make_pair(dateTime, sequence));
if (sequence > entry.first->second) {
@ -379,7 +379,7 @@ public:
path << base.str();
SeqMap_t::iterator it = dateTimes2Seq.find(path.str());
if (it != dateTimes2Seq.end()) {
path << "-" << it->second + 1;
path << "-" << (char)('a' + it->second + 1);
}
m_path = m_logdir + "/";
m_path += m_prefix;
@ -3731,7 +3731,6 @@ private:
CPPUNIT_TEST(testSessionChanges);
CPPUNIT_TEST(testMultipleSessions);
CPPUNIT_TEST(testExpire);
CPPUNIT_TEST(testExpire2);
CPPUNIT_TEST_SUITE_END();
/**
@ -3976,20 +3975,6 @@ private:
sessions = listSessions();
CPPUNIT_ASSERT_EQUAL((size_t)1, sessions.size());
CPPUNIT_ASSERT_EQUAL(dirs[0], sessions[0]);
}
void testExpire2() {
ScopedEnvChange config("XDG_CONFIG_HOME", "LogDirTest/config");
ScopedEnvChange cache("XDG_CACHE_HOME", "LogDirTest/cache");
string dirs[5];
Sessions_t sessions;
// Have to restart with clean log dir because our sequence counter
// runs over after 10 sessions. Continue where testExpire() stopped.
dirs[0] = session(false, STATUS_OK,
"ical20", ".two", ".one",
"vcard30", ".two", ".one",
(char *)0);
// when doing multiple failed syncs without dumps, keep the sessions
// which have database dumps