Enhancement - undo

- Added logging of both new tasks, and modified tasks.
- Added size of undo.data file to the statistics report.
This commit is contained in:
Paul Beckingham 2009-06-28 14:16:44 -04:00
parent c29682b91f
commit 5d8c28f72f
3 changed files with 40 additions and 22 deletions

View file

@ -361,32 +361,42 @@ int TDB::commit ()
// The alternative is to potentially rewrite both files.
else if (mNew.size () || mModified.size ())
{
foreach (task, mPending)
// allPending is a copy of mPending, with all modifications included, and
// new tasks appended.
std::vector <Task> allPending;
allPending = mPending;
foreach (task, allPending)
foreach (mtask, mModified)
if (task->id == mtask->id)
*task = *mtask;
mModified.clear ();
foreach (task, mNew)
mPending.push_back (*task);
mNew.clear ();
allPending.push_back (*task);
// Write out all pending.
if (fseek (mLocations[0].pending, 0, SEEK_SET) == 0)
{
ftruncate (fileno (mLocations[0].pending), 0);
foreach (task, mPending)
foreach (task, allPending)
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
}
/*
// Update the undo log.
fseek (mLocations[0].undo, 0, SEEK_END);
foreach (task, mPending)
writeUndo (*task, mLocations[0].undo);
*/
if (fseek (mLocations[0].undo, 0, SEEK_END) == 0)
{
foreach (task, mPending)
foreach (mtask, mModified)
if (task->id == mtask->id)
writeUndo (*task, *mtask, mLocations[0].undo);
foreach (task, mNew)
writeUndo (*task, mLocations[0].undo);
}
mPending = allPending;
mModified.clear ();
mNew.clear ();
}
return quantity;
@ -512,19 +522,22 @@ void TDB::writeUndo (const Task& after, FILE* file)
{
Timer t ("TDB::writeUndo");
// TODO Locate "before" task (match on uuid).
fprintf (file,
"time %u\nnew %s\n---\n",
"time %u\nnew %s---\n",
(unsigned int) time (NULL),
after.composeF4 ().c_str ());
/*
fprintf (file,
"time %u\nold %s\nnew %s\n---\n",
(unsigned int) time (NULL),
before.composeF4 ().c_str (),
after.composeF4 ().c_str ());
*/
}
////////////////////////////////////////////////////////////////////////////////
void TDB::writeUndo (const Task& before, const Task& after, FILE* file)
{
Timer t ("TDB::writeUndo");
fprintf (file,
"time %u\nold %snew %s---\n",
(unsigned int) time (NULL),
before.composeF4 ().c_str (),
after.composeF4 ().c_str ());
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -65,6 +65,7 @@ public:
private:
FILE* openAndLock (const std::string&);
void writeUndo (const Task&, FILE*);
void writeUndo (const Task&, const Task&, FILE*);
private:
std::vector <Location> mLocations;

View file

@ -1617,6 +1617,10 @@ std::string handleReportStats ()
if (!stat (file.c_str (), &s))
dataSize += s.st_size;
file = location + "/undo.data";
if (!stat (file.c_str (), &s))
dataSize += s.st_size;
// TODO Include transaction log?
// Get all the tasks.