Use AtomicFile for data, tags, undo, and config files

Now changes accross all of these files either happen all together or not
at all.

Related to issue #155
This commit is contained in:
Shaun Ruffell 2020-02-16 12:52:12 -06:00 committed by lauft
parent 8e99c07d85
commit 4b3a907cbb
7 changed files with 47 additions and 36 deletions

View file

@ -24,7 +24,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#include <FS.h>
#include <AtomicFile.h>
#include <format.h>
#include <Journal.h>
#include <TransactionsFactory.h>
@ -54,19 +54,9 @@ void Journal::endTransaction ()
throw "Call to end non-existent transaction";
}
File undo (_location);
AtomicFile::append (_location, _currentTransaction->toString ());
if (undo.open ())
{
undo.append (_currentTransaction->toString());
undo.close ();
_currentTransaction.reset ();
}
else
{
throw format ("Unable to write the undo transaction to {1}", undo._data);
}
_currentTransaction.reset ();
}
////////////////////////////////////////////////////////////////////////////////
@ -102,7 +92,7 @@ void Journal::recordUndoAction (
////////////////////////////////////////////////////////////////////////////////
Transaction Journal::popLastTransaction ()
{
File undo (_location);
AtomicFile undo (_location);
std::vector <std::string> read_lines;
undo.read (read_lines);
@ -125,8 +115,8 @@ Transaction Journal::popLastTransaction ()
Transaction last = transactions.back ();
transactions.pop_back ();
File::remove (undo._data);
undo.open ();
undo.truncate ();
for (auto& transaction : transactions)
{