Datafile: Throw exception if Datafile::deleteInterval fails

This is particularly bad when called from the Database::modifyInterval
call, since the delete may fail, but then the addInterval will proceed.

Closes #319

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2020-07-19 21:18:18 -05:00 committed by lauft
parent 48baa27057
commit 7481dab8d0

View file

@ -129,16 +129,20 @@ void Datafile::deleteInterval (const Interval& interval)
assert (interval.startsWithin (_range)); assert (interval.startsWithin (_range));
if (! _lines_loaded) if (! _lines_loaded)
{
load_lines (); load_lines ();
}
auto serialized = interval.serialize (); auto serialized = interval.serialize ();
auto i = std::find (_lines.begin (), _lines.end (), serialized); auto i = std::find (_lines.begin (), _lines.end (), serialized);
if (i != _lines.end ()) if (i == _lines.end ())
{ {
throw format ("Datafile::deleteInterval failed to find '{1}'", serialized);
}
_lines.erase (i); _lines.erase (i);
_dirty = true; _dirty = true;
debug (format ("{1}: Deleted {2}", _file.name (), serialized)); debug (format ("{1}: Deleted {2}", _file.name (), serialized));
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////