From 501953a6dabaf9f3fd9757b8481ec6e032e985b2 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 21 Aug 2011 22:37:02 -0400 Subject: [PATCH] TDB2 - Verifies that a UUID is not already found in the data. This prevents erroneous double-import. Or triple... --- src/TDB2.cpp | 15 +++++++++++++++ src/TDB2.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/src/TDB2.cpp b/src/TDB2.cpp index 48a418705..c76dc3ff6 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -385,6 +385,11 @@ void TDB2::add (const Task& task) { // std::cout << "# TDB2::add\n"; + // If the tasks are loaded, then verify that this uuid is not already in + // the file. + if (!verifyUniqueUUID (task.get ("uuid"))) + throw format ("Cannot add task because the uuid '{1}' is not unique.", task.get ("uuid")); + std::string status = task.get ("status"); if (status == "completed" || status == "deleted") @@ -485,6 +490,16 @@ int TDB2::next_id () return _id++; } +//////////////////////////////////////////////////////////////////////////////// +bool TDB2::verifyUniqueUUID (const std::string& uuid) +{ + if (pending.id (uuid) != 0 || + completed.id (uuid) != 0) + return false; + + return true; +} + //////////////////////////////////////////////////////////////////////////////// // // File RW State Tasks + - ~ lines + - Bytes diff --git a/src/TDB2.h b/src/TDB2.h index 967ca6f43..7d642da57 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -99,6 +99,9 @@ public: void dump (); void dump_file (ViewText&, const std::string&, TF2&); +private: + bool verifyUniqueUUID (const std::string&); + public: TF2 pending; TF2 completed;