diff --git a/src/Datafile.cpp b/src/Datafile.cpp index f8cfd9b2..461d3358 100644 --- a/src/Datafile.cpp +++ b/src/Datafile.cpp @@ -107,8 +107,17 @@ void Datafile::addInterval (const Interval& interval) //////////////////////////////////////////////////////////////////////////////// void Datafile::modifyInterval (const Interval& interval) { - _lines_modified.push_back (interval.serialize ()); - _dirty = true; + for (auto& i : _intervals) + { + if (i.start () == interval.start () && + i.tags () == interval.tags ()) + { + i = interval; + _dirty = true; + _lines_modified = true; + break; + } + } } //////////////////////////////////////////////////////////////////////////////// @@ -118,8 +127,8 @@ void Datafile::commit () if (_dirty) { // Special case: added but no modified means just append to the file. - if (! _lines_modified.size () && - _lines_added.size ()) + if (_lines_added.size () && + ! _lines_modified) { if (_file.open ()) { @@ -147,9 +156,10 @@ void Datafile::commit () // Truncate the file and rewrite. _file.truncate (); + // Rewrite all the intervals, because at least one was modified. _file.append (std::string("")); // Seek to end of file - for (auto& line : _lines) - _file.write_raw (line + "\n"); + for (auto& interval : _intervals) + _file.write_raw (interval.serialize () + "\n"); // Write out all the added lines. for (auto& line : _lines_added) diff --git a/src/Datafile.h b/src/Datafile.h index d1e3586b..31f4e5a4 100644 --- a/src/Datafile.h +++ b/src/Datafile.h @@ -63,7 +63,7 @@ private: // Lines read from file, not parsed. std::vector _lines {}; std::vector _lines_added {}; - std::vector _lines_modified {}; + bool _lines_modified {false}; bool _lines_loaded {false}; // Intervals parsed from lines.