mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-20 22:33:08 +02:00
Sync
- Corrected handling of backlog.data after a synch, using TF2::clear_tasks.
This commit is contained in:
parent
c5ff24358c
commit
98d9a367f3
3 changed files with 16 additions and 4 deletions
|
@ -188,6 +188,13 @@ void TF2::add_line (const std::string& line)
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void TF2::clear_tasks ()
|
||||||
|
{
|
||||||
|
_tasks.clear ();
|
||||||
|
_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TF2::clear_lines ()
|
void TF2::clear_lines ()
|
||||||
{
|
{
|
||||||
|
@ -243,7 +250,7 @@ void TF2::commit ()
|
||||||
// Truncate the file and rewrite.
|
// Truncate the file and rewrite.
|
||||||
_file.truncate ();
|
_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 <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
for (task = _tasks.begin ();
|
for (task = _tasks.begin ();
|
||||||
task != _tasks.end ();
|
task != _tasks.end ();
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
void add_task (const Task&);
|
void add_task (const Task&);
|
||||||
bool modify_task (const Task&);
|
bool modify_task (const Task&);
|
||||||
void add_line (const std::string&);
|
void add_line (const std::string&);
|
||||||
|
void clear_tasks ();
|
||||||
void clear_lines ();
|
void clear_lines ();
|
||||||
void commit ();
|
void commit ();
|
||||||
|
|
||||||
|
|
|
@ -98,9 +98,9 @@ int CmdSync::execute (std::string& output)
|
||||||
payload = response.getPayload ();
|
payload = response.getPayload ();
|
||||||
std::vector <std::string> lines;
|
std::vector <std::string> lines;
|
||||||
split (lines, payload, '\n');
|
split (lines, payload, '\n');
|
||||||
std::cout << "# received " << lines.size () << " lines of data\n";
|
|
||||||
|
|
||||||
// Load all tasks.
|
// Load all tasks.
|
||||||
|
// TODO This is not necessary if only a synch key was received.
|
||||||
std::vector <Task> all = context.tdb2.all_tasks ();
|
std::vector <Task> all = context.tdb2.all_tasks ();
|
||||||
|
|
||||||
std::string synch_key = "";
|
std::string synch_key = "";
|
||||||
|
@ -116,11 +116,13 @@ int CmdSync::execute (std::string& output)
|
||||||
<< "\n";
|
<< "\n";
|
||||||
context.tdb2.modify (from_server);
|
context.tdb2.modify (from_server);
|
||||||
}
|
}
|
||||||
else
|
else if (*line != "")
|
||||||
{
|
{
|
||||||
synch_key = *line;
|
synch_key = *line;
|
||||||
context.debug ("Synch key " + synch_key);
|
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
|
// 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 != "")
|
if (synch_key != "")
|
||||||
{
|
{
|
||||||
// Truncate backlog.data, save new 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");
|
context.tdb2.backlog.add_line (synch_key + "\n");
|
||||||
|
|
||||||
// Commit all changes.
|
// Commit all changes.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue