Enhancement

- Importing the same YAML twice now generates an error.
This commit is contained in:
Paul Beckingham
2010-09-02 21:32:33 -04:00
parent b32d731010
commit 1cc67e9895
6 changed files with 42 additions and 8 deletions

View File

@@ -463,17 +463,25 @@ const std::vector <Task>& TDB::getAllModified ()
// Note: mLocations[0] is where all tasks are written.
void TDB::add (const Task& task)
{
std::string unique;
Task t (task);
if (task.get ("uuid") == "")
{
std::string unique = ::uuid ();
t.set ("uuid", unique);
}
unique = ::uuid ();
else
t.set ("uuid", task.get ("uuid"));
unique = task.get ("uuid");
t.set ("uuid", unique);
// If the tasks are loaded, then verify that this uuid is not already in
// the file.
if (uuidAlreadyUsed (unique, mNew) ||
uuidAlreadyUsed (unique, mModified) ||
uuidAlreadyUsed (unique, mPending) ||
uuidAlreadyUsed (unique, mCompleted))
throw std::string ("Cannot add task because the uuid '") + unique + "' is not unique.";
mNew.push_back (t);
mI2U[task.id] = t.get ("uuid");
mI2U[task.id] = unique;
mU2I[task.get ("uuid")] = t.id;
}
@@ -1610,3 +1618,16 @@ void TDB::writeUndo (const Task& before, const Task& after, FILE* file)
}
////////////////////////////////////////////////////////////////////////////////
bool TDB::uuidAlreadyUsed (
const std::string& uuid,
const std::vector <Task>& all)
{
std::vector <Task>::const_iterator it;
for (it = all.begin (); it != all.end (); ++it)
if (it->get ("uuid") == uuid)
return true;
return false;
}
////////////////////////////////////////////////////////////////////////////////