mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Datafile: Remove empty files
If calling undo on an operation the removes many entries from the datafiles, there would be many 0 length size files remaining in the data directory. Now they will be removed if they are empty so they will not longer need to be checked when parsing the database. Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
parent
b2a8fe6f55
commit
b0efdbc9ee
1 changed files with 18 additions and 11 deletions
|
@ -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 ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue