mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
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:
parent
48baa27057
commit
7481dab8d0
1 changed files with 8 additions and 4 deletions
|
@ -129,17 +129,21 @@ 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));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Datafile::commit ()
|
void Datafile::commit ()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue