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

View File

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