mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Datafile: Implemented ::commit
This commit is contained in:
parent
13e5736cd6
commit
69d80bc2bb
1 changed files with 41 additions and 0 deletions
|
@ -103,9 +103,50 @@ void Datafile::modifyInterval (const Interval& interval)
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Datafile::commit ()
|
||||
{
|
||||
// The _dirty flag indicates that the file needs to be written.
|
||||
if (_dirty)
|
||||
{
|
||||
// Special case: added but no modified means just append to the file.
|
||||
if (! _lines_modified.size () &&
|
||||
_lines_added.size ())
|
||||
{
|
||||
if (_file.open ())
|
||||
{
|
||||
_file.lock ();
|
||||
|
||||
// Write out all the added intervals.
|
||||
_file.append (std::string("")); // Seek to end of file
|
||||
|
||||
// Write out all the added lines.
|
||||
_file.append (_lines_added);
|
||||
|
||||
_lines_added.clear ();
|
||||
_file.close ();
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_file.open ())
|
||||
{
|
||||
_file.lock ();
|
||||
|
||||
// Truncate the file and rewrite.
|
||||
_file.truncate ();
|
||||
|
||||
_file.append (std::string("")); // Seek to end of file
|
||||
for (auto& line : _lines)
|
||||
_file.write_raw (line + "\n");
|
||||
|
||||
// Write out all the added lines.
|
||||
_file.append (_lines_added);
|
||||
|
||||
_lines_added.clear ();
|
||||
_file.close ();
|
||||
_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
_dirty = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue