From 6faf6bb678a9982b77cf6d1360279995851f4ed5 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 16 Aug 2014 14:20:00 -0400 Subject: [PATCH] TDB2 - Now updates the task ID of any new task, therefore avoiding off-by-one errors that occur when code calls TDB2::next_id. --- src/TDB2.cpp | 19 ++++++++----------- src/TDB2.h | 2 +- src/commands/CmdAdd.cpp | 2 +- src/commands/CmdDuplicate.cpp | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index e0eaf83eb..f42a90c8d 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -135,26 +135,23 @@ bool TF2::get (const std::string& uuid, Task& task) } //////////////////////////////////////////////////////////////////////////////// -void TF2::add_task (const Task& task) +void TF2::add_task (Task& task) { - Task hookTask (task); - context.hooks.onAdd (hookTask); + context.hooks.onAdd (task); + _tasks.push_back (task); // For subsequent queries + _added_tasks.push_back (task); // For commit/synch - _tasks.push_back (hookTask); // For subsequent queries - _added_tasks.push_back (hookTask); // For commit/synch - - int id = task.id; Task::status status = task.getStatus (); - if (id == 0 && + if (task.id == 0 && (status == Task::pending || status == Task::recurring || status == Task::waiting)) { - id = context.tdb2.next_id (); + task.id = context.tdb2.next_id (); } - _I2U[id] = task.get ("uuid"); - _U2I[task.get ("uuid")] = id; + _I2U[task.id] = task.get ("uuid"); + _U2I[task.get ("uuid")] = task.id; _dirty = true; } diff --git a/src/TDB2.h b/src/TDB2.h index ff8138d3e..3071fab72 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -50,7 +50,7 @@ public: bool get (int, Task&); bool get (const std::string&, Task&); - void add_task (const Task&); + void add_task (Task&); bool modify_task (const Task&); void add_line (const std::string&); void clear_tasks (); diff --git a/src/commands/CmdAdd.cpp b/src/commands/CmdAdd.cpp index a087edf66..7cd7afd5f 100644 --- a/src/commands/CmdAdd.cpp +++ b/src/commands/CmdAdd.cpp @@ -55,7 +55,7 @@ int CmdAdd::execute (std::string& output) context.tdb2.add (task); if (context.verbose ("new-id")) - output += format (STRING_CMD_ADD_FEEDBACK, context.tdb2.next_id ()) + "\n"; + output += format (STRING_CMD_ADD_FEEDBACK, task.id) + "\n"; else if (context.verbose ("new-uuid")) output += format (STRING_CMD_ADD_FEEDBACK, task.get ("uuid")) + "\n"; diff --git a/src/commands/CmdDuplicate.cpp b/src/commands/CmdDuplicate.cpp index 99c844a76..b79ea82f1 100644 --- a/src/commands/CmdDuplicate.cpp +++ b/src/commands/CmdDuplicate.cpp @@ -110,7 +110,7 @@ int CmdDuplicate::execute (std::string& output) feedback_affected (STRING_CMD_DUPLICATE_TASK, *task); if (context.verbose ("new-id")) - std::cout << format (STRING_CMD_ADD_FEEDBACK, context.tdb2.next_id ()) + "\n"; + std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.id) + "\n"; else if (context.verbose ("new-uuid")) std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.get ("uuid")) + "\n";