diff --git a/src/Context.cpp b/src/Context.cpp index 42eb61290..a66f6fd77 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -192,9 +192,7 @@ std::string Context::dispatch () else if (cmd.command == "undelete") { out = handleUndelete (); } */ else if (cmd.command == "start") { out = handleStart (); } -/* else if (cmd.command == "stop") { out = handleStop (); } -*/ else if (cmd.command == "export") { out = handleExport (); } /* else if (cmd.command == "import") { out = handleImport (); } diff --git a/src/TDB.cpp b/src/TDB.cpp index d163d0f7d..34d20422f 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -312,8 +312,11 @@ int TDB::commit () // Write out all pending. if (fseek (mLocations[0].pending, 0, SEEK_SET) == 0) + { + ftruncate (fileno (mLocations[0].pending), 0); foreach (task, mPending) fputs (task->composeF4 ().c_str (), mLocations[0].pending); + } } return quantity; diff --git a/src/command.cpp b/src/command.cpp index 7c09304fc..401fd90a1 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -570,27 +570,44 @@ std::string handleStart () std::string handleStop () { std::stringstream out; -/* - std::vector all; - tdb.pendingT (all); - filterSequence (all, task); - foreach (t, all) + std::vector tasks; + context.tdb.lock (context.config.get ("locking", true)); + context.tdb.loadPending (tasks, context.filter); + handleRecurrence (tasks); + + // Filter sequence. + context.filter.applySequence (tasks, context.sequence); + + foreach (task, tasks) { - if (t->has ("start")) + if (task->has ("start")) { - t->removeAttribute ("start"); - tdb.modifyT (*t); + task->remove ("start"); + context.tdb.update (*task); if (context.config.get ("echo.command", true)) - out << "Stopped " << t->getId () << " '" << t->getDescription () << "'" << std::endl; + out << "Stopped " + << task->id + << " '" + << task->get ("description") + << "'" + << std::endl; } else { - out << "Task " << t->getId () << " '" << t->getDescription () << "' not started." << std::endl; + out << "Task " + << task->id + << " '" + << task->get ("description") + << "' not started." + << std::endl; } } -*/ + + context.tdb.commit (); + context.tdb.unlock (); + return out.str (); }