diff --git a/src/TDB2.cpp b/src/TDB2.cpp index ad1d1c0e7..d7dc0a194 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -188,6 +188,13 @@ void TF2::add_line (const std::string& line) _dirty = true; } +//////////////////////////////////////////////////////////////////////////////// +void TF2::clear_tasks () +{ + _tasks.clear (); + _dirty = true; +} + //////////////////////////////////////////////////////////////////////////////// void TF2::clear_lines () { @@ -243,7 +250,7 @@ void TF2::commit () // Truncate the file and rewrite. _file.truncate (); - // only write out _tasks, because any deltas have already been applied. + // Only write out _tasks, because any deltas have already been applied. std::vector ::iterator task; for (task = _tasks.begin (); task != _tasks.end (); diff --git a/src/TDB2.h b/src/TDB2.h index aaefcbba6..22b01c610 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -55,6 +55,7 @@ public: void add_task (const Task&); bool modify_task (const Task&); void add_line (const std::string&); + void clear_tasks (); void clear_lines (); void commit (); diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index 5db7d2377..da9e4471c 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -98,9 +98,9 @@ int CmdSync::execute (std::string& output) payload = response.getPayload (); std::vector lines; split (lines, payload, '\n'); - std::cout << "# received " << lines.size () << " lines of data\n"; // Load all tasks. + // TODO This is not necessary if only a synch key was received. std::vector all = context.tdb2.all_tasks (); std::string synch_key = ""; @@ -116,11 +116,13 @@ int CmdSync::execute (std::string& output) << "\n"; context.tdb2.modify (from_server); } - else + else if (*line != "") { synch_key = *line; context.debug ("Synch key " + synch_key); } + + // Otherwise line is blank, so ignore it. } // Only update everything if there is a new synch_key. No synch_key means @@ -128,7 +130,9 @@ int CmdSync::execute (std::string& output) if (synch_key != "") { // Truncate backlog.data, save new synch_key. - context.tdb2.backlog.clear (); + context.tdb2.backlog._file.truncate (); + context.tdb2.backlog.clear_tasks (); + context.tdb2.backlog.clear_lines (); context.tdb2.backlog.add_line (synch_key + "\n"); // Commit all changes.