From a219bd30cf18ff7c7c014b386e6577fc6d04df47 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Sat, 19 Jun 2021 09:20:03 -0400 Subject: [PATCH] Task: Bump annotations with duplicate entry values Since annotations are stored as a map, duplicate entry values lead to data loss (i.e. annotations overriding each other on import). Perhaps the choice of using a map internally should be reconsidered. Closes #1938. --- src/Task.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Task.cpp b/src/Task.cpp index 050fce492..d860632e7 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -766,8 +766,23 @@ void Task::parseJSON (const json::object* root_obj) if (! what) throw format ("Annotation is missing a description: {1}", root_obj->dump ()); - std::string name = "annotation_" + Datetime (when->_data).toEpochString (); - annos.insert (std::make_pair (name, json::decode (what->_data))); + // Extract 64-bit annotation entry value + // Time travelers from 2038, we have your back. + long long ann_timestamp = (long long) (Datetime (when->_data).toEpoch ()); + + std::stringstream name; + name << "annotation_" << ann_timestamp; + + // Increment the entry timestamp in case of a conflict. Same + // behaviour as CmdAnnotate. + while (annos.find(name.str ()) != annos.end ()) + { + name.str (""); // Clear + ann_timestamp++; + name << "annotation_" << ann_timestamp; + } + + annos.insert (std::make_pair (name.str (), json::decode (what->_data))); } setAnnotations (annos);