Skip to content

Commit

Permalink
Bug #378638 - log replay creates two transactions from a single logge…
Browse files Browse the repository at this point in the history
…d transaction

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@19243 57a11ea4-9604-0410-9ed3-97b8803252fd
  • Loading branch information
gjanssens committed Jun 8, 2010
1 parent 78308b2 commit fbeec39
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions src/import-export/log-replay/gnc-log-replay.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ static void process_trans_record( FILE *log_file)
{
char read_buf[2048];
char *read_retval;
char * trans_ro = NULL;
const char * record_end_str = "===== END";
int first_record = TRUE;
int record_ended = FALSE;
Expand Down Expand Up @@ -395,7 +396,11 @@ static void process_trans_record( FILE *log_file)
if ((trans = xaccTransLookup (&(record.trans_guid), book)) != NULL
&& first_record == TRUE)
{
xaccTransBeginEdit(trans);
if (xaccTransGetReadOnly(trans))
{
PWARN("Destroying a read only transaction.");
xaccTransClearReadOnly(trans);
}
xaccTransDestroy(trans);
}
else if (first_record == TRUE)
Expand All @@ -406,20 +411,25 @@ static void process_trans_record( FILE *log_file)
case LOG_COMMIT:
DEBUG("process_trans_record(): Playing back LOG_COMMIT");
if (record.trans_guid_present == TRUE
&& (trans = xaccTransLookupDirect (record.trans_guid, book)) != NULL
&& first_record == TRUE)
{
DEBUG("process_trans_record(): Transaction to be edited was found");/*Destroy the current transaction, we will create a new one to replace it*/
xaccTransBeginEdit(trans);
xaccTransDestroy(trans);
xaccTransCommitEdit(trans);
}
trans = xaccTransLookupDirect (record.trans_guid, book);
if (trans != NULL)
{
DEBUG("process_trans_record(): Transaction to be edited was found");
trans_ro = g_strdup(xaccTransGetReadOnly(trans));
if (trans_ro)
{
PWARN("Replaying a read only transaction.");
xaccTransClearReadOnly(trans);
}
}
else
{
DEBUG("process_trans_record(): Creating a new transaction");
trans = xaccMallocTransaction (book);
}

if (record.trans_guid_present == TRUE
&& first_record == TRUE)
{
DEBUG("process_trans_record(): Creating the new transaction");
trans = xaccMallocTransaction (book);
xaccTransBeginEdit(trans);
xaccTransSetGUID (trans, &(record.trans_guid));
/*Fill the transaction info*/
Expand All @@ -446,14 +456,28 @@ static void process_trans_record( FILE *log_file)
}
if (record.split_guid_present == TRUE) /*Fill the split info*/
{
split = xaccMallocSplit(book);
gboolean is_new_split;

split = xaccSplitLookupDirect (record.split_guid, book);
if (split != NULL)
{
DEBUG("process_trans_record(): Split to be edited was found");
is_new_split = FALSE;
}
else
{
DEBUG("process_trans_record(): Creating a new split");
split = xaccMallocSplit(book);
is_new_split = TRUE;
}
xaccSplitSetGUID (split, &(record.split_guid));
if (record.acc_guid_present)
{
acct = xaccAccountLookupDirect(record.acc_guid, book);
xaccAccountInsertSplit(acct, split);
}
xaccTransAppendSplit(trans, split);
if (is_new_split)
xaccTransAppendSplit(trans, split);

if (record.split_memo_present)
{
Expand Down Expand Up @@ -498,6 +522,8 @@ static void process_trans_record( FILE *log_file)
{
xaccTransScrubCurrencyFromSplits(trans);
xaccTransCommitEdit(trans);
xaccTransSetReadOnly(trans, trans_ro);
g_free(trans_ro);
}
}
}
Expand Down Expand Up @@ -525,6 +551,9 @@ void gnc_file_log_replay (void)
qof_log_set_level(GNC_MOD_IMPORT, QOF_LOG_DEBUG);
ENTER(" ");

/* Don't log the log replay. This would only result in redundant logs */
xaccLogDisable();

default_dir = gnc_get_default_directory(GCONF_SECTION);

filter = gtk_file_filter_new();
Expand Down Expand Up @@ -607,6 +636,9 @@ void gnc_file_log_replay (void)
}
g_free(selected_filename);
}
/* Start logging again */
xaccLogEnable();

LEAVE("");
}

Expand Down

0 comments on commit fbeec39

Please sign in to comment.