diff --git a/src/Datafile.cpp b/src/Datafile.cpp index cfe79cd9..7d896873 100644 --- a/src/Datafile.cpp +++ b/src/Datafile.cpp @@ -148,23 +148,30 @@ void Datafile::commit () if (_dirty) { AtomicFile file (_file); - if (file.open ()) + if (_lines.size () > 0) { - // Sort the intervals by ascending start time. - std::sort (_lines.begin (), _lines.end ()); - - // Write out all the lines. - file.truncate (); - for (auto& line : _lines) + if (file.open ()) { - file.write_raw (line + '\n'); - } + // Sort the intervals by ascending start time. + std::sort (_lines.begin (), _lines.end ()); - _dirty = false; + // Write out all the lines. + file.truncate (); + for (auto& line : _lines) + { + file.write_raw (line + '\n'); + } + + _dirty = false; + } + else + { + throw format ("Could not write to data file {1}", _file._data); + } } else { - throw format ("Could not write to data file {1}", _file._data); + file.remove (); } } }