mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
James LewisMoss's xml v2 patch. Backup your data! But you already
did that, right? git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3880 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f107e6090a
commit
a08c930a23
48
ChangeLog
48
ChangeLog
@ -32,6 +32,33 @@
|
||||
* src/scm/html-utilities.scm (gnc:html-build-acct-table): fix
|
||||
horizontal line width if foreign currencies are shown.
|
||||
|
||||
2001-03-31 James LewisMoss <jimdres@mindspring.com>
|
||||
|
||||
* src/test/test-xml-account.c (node_and_account_equal): fix parent
|
||||
id test. duh.
|
||||
|
||||
* src/test/test-real-data.sh (EXIT_VALUE): check for empty FILES
|
||||
return.
|
||||
|
||||
* src/test/test-xml-commodity.c (main): fix argc test.
|
||||
|
||||
* src/test/test-xml-account.c (main): fix argc test.
|
||||
|
||||
* src/test/test-xml-commodity.c (main): fix argc test
|
||||
|
||||
* src/test/test-load-xml2.c (main): call xaccLogDisable
|
||||
|
||||
* src/test/test-xml-transaction.c (main): call xaccLogDisable
|
||||
|
||||
* src/engine/io-gncxml-v2.c (gnc_book_load_from_xml_file_v2):
|
||||
comment out load debug info.
|
||||
|
||||
* src/test/test-real-data.sh (EXIT_VALUE): don't run on a
|
||||
directory.
|
||||
|
||||
* src/test/gnc-test-stuff.c (test_files_in_dir): rename vars
|
||||
file_count -> argc, files -> argv to be more accurate.
|
||||
|
||||
2001-03-31 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/scm/options.scm: add a text option type
|
||||
@ -44,6 +71,27 @@
|
||||
|
||||
* src/scm/html-document.scm: fix bug
|
||||
|
||||
2001-03-30 James LewisMoss <jimdres@mindspring.com>
|
||||
|
||||
* src/engine/io-gncxml-v2.c (gnc_book_load_from_xml_file_v2): add
|
||||
stuff from file format 1 ledger data start and end handlers to
|
||||
disable enable log, mark saved, and the rest.
|
||||
|
||||
* src/engine/gnc-book.c (gnc_book_write_to_file): clean up
|
||||
writing. Write only once.
|
||||
(gnc_book_write_to_file): extract out backup functionality.
|
||||
(gnc_book_backup_file): new func with extracted functionality.
|
||||
(gnc_book_backup_file): add more permament backup for binary
|
||||
data.
|
||||
|
||||
* src/engine/gnc-account-xml-v2.c (gnc_account_end_handler): add
|
||||
begin edit so that everyhing doesn't get recomputed till end.
|
||||
|
||||
* src/engine/io-gncxml-v2.c (gnc_book_load_from_xml_file_v2): add
|
||||
commit of all accounts at end.
|
||||
|
||||
* src/engine/gnc-book.c (gnc_book_write_to_file): use v2 write.
|
||||
|
||||
2001-03-30 Dave Peticolas <dave@krondo.com>
|
||||
|
||||
* src/scm/report/average-balance.scm: tweak default accounts
|
||||
|
@ -259,6 +259,12 @@ gnc_account_end_handler(gpointer data_for_children,
|
||||
|
||||
xmlFreeNode(tree);
|
||||
|
||||
/* Now return the account to the "edit" state. At the end of reading
|
||||
* all the transactions, we will Commit. This replaces #splits
|
||||
* rebalances with #accounts rebalances at the end. A BIG win!
|
||||
*/
|
||||
xaccAccountBeginEdit(acc);
|
||||
|
||||
return successful;
|
||||
}
|
||||
|
||||
|
@ -426,48 +426,73 @@ gnc_book_load_from_file(GNCBook *book)
|
||||
current year/month/day/hour/minute/second. */
|
||||
|
||||
static gboolean
|
||||
gnc_book_write_to_file(GNCBook *book,
|
||||
gboolean make_backup)
|
||||
gnc_book_backup_file(GNCBook *book)
|
||||
{
|
||||
const gchar *datafile = gnc_book_get_file_path(book);
|
||||
char *timestamp;
|
||||
char *backup;
|
||||
const char *datafile = gnc_book_get_file_path(book);
|
||||
|
||||
if(!gnc_book_write_to_xml_file(book, datafile)) {
|
||||
gnc_book_push_error(book, ERR_BACKEND_MISC, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!make_backup) {
|
||||
return TRUE;
|
||||
} else {
|
||||
char * timestamp;
|
||||
int filenamelen;
|
||||
char * backup;
|
||||
if(gnc_book_determine_file_type(book) == GNC_BOOK_BIN_FILE)
|
||||
{
|
||||
/* make a more permament safer backup */
|
||||
const char *back = "-binfmt.bkup";
|
||||
char *bin_bkup = g_new(char, strlen(datafile) + strlen(back) + 1);
|
||||
strcpy(bin_bkup, datafile);
|
||||
strcat(bin_bkup, back);
|
||||
link(datafile, bin_bkup);
|
||||
g_free(bin_bkup);
|
||||
}
|
||||
|
||||
/* also, write a time-stamped backup file */
|
||||
/* tag each filename with a timestamp */
|
||||
timestamp = xaccDateUtilGetStampNow ();
|
||||
|
||||
filenamelen = strlen (datafile) + strlen (timestamp) + 6;
|
||||
|
||||
backup = (char *) malloc (filenamelen);
|
||||
backup = g_new (char, strlen (datafile) + strlen (timestamp) + 6);
|
||||
strcpy (backup, datafile);
|
||||
strcat (backup, ".");
|
||||
strcat (backup, timestamp);
|
||||
strcat (backup, ".xac");
|
||||
free (timestamp);
|
||||
|
||||
if(gnc_book_write_to_xml_file(book, backup)) {
|
||||
free (backup);
|
||||
return TRUE;
|
||||
} else {
|
||||
gnc_book_push_error(book, ERR_BACKEND_MISC, NULL);
|
||||
free (backup);
|
||||
link(datafile, backup);
|
||||
g_free(backup);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnc_book_write_to_file(GNCBook *book,
|
||||
gboolean make_backup)
|
||||
{
|
||||
const gchar *datafile = gnc_book_get_file_path(book);
|
||||
char *tmp_name;
|
||||
|
||||
tmp_name = g_new(char, strlen(datafile) + 12);
|
||||
strcpy(tmp_name, datafile);
|
||||
strcat(tmp_name, ".tmp-XXXXXX");
|
||||
if(!mktemp(tmp_name))
|
||||
{
|
||||
gnc_book_push_error(book, ERR_BACKEND_MISC,
|
||||
g_strdup("unable to create temporary file name"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(make_backup)
|
||||
{
|
||||
gnc_book_backup_file(book);
|
||||
}
|
||||
|
||||
if(gnc_book_write_to_xml_file_v2(book, tmp_name))
|
||||
{
|
||||
unlink(datafile);
|
||||
link(tmp_name, datafile);
|
||||
unlink(tmp_name);
|
||||
g_free(tmp_name);
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink(tmp_name);
|
||||
g_free(tmp_name);
|
||||
gnc_book_push_error(book, ERR_BACKEND_MISC, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
/* Should never get here */
|
||||
gnc_book_push_error(book, ERR_BACKEND_MISC, NULL);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
@ -782,7 +807,7 @@ gnc_book_load (GNCBook *book)
|
||||
|
||||
LEAVE("book_id=%s", book->book_id);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
gnc_book_push_error (book, ERR_BACKEND_NO_BACKEND, NULL);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "TransLog.h"
|
||||
|
||||
#include "sixtp-dom-parsers.h"
|
||||
#include "io-gncxml-v2.h"
|
||||
@ -11,7 +12,7 @@
|
||||
#include "sixtp-parsers.h"
|
||||
#include "gnc-xml.h"
|
||||
#include "gnc-book-p.h"
|
||||
#include "gnc-pricedb.h"
|
||||
#include "gnc-pricedb-p.h"
|
||||
|
||||
#include "Group.h"
|
||||
|
||||
@ -221,15 +222,19 @@ gnc_book_load_from_xml_file_v2(
|
||||
|
||||
top_parser = sixtp_new();
|
||||
main_parser = sixtp_new();
|
||||
|
||||
|
||||
/* stop logging while we load */
|
||||
xaccLogDisable ();
|
||||
|
||||
if(!sixtp_add_some_sub_parsers(
|
||||
top_parser, TRUE,
|
||||
"gnc-v2", main_parser,
|
||||
NULL, NULL))
|
||||
{
|
||||
xaccLogEnable ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if(!sixtp_add_some_sub_parsers(
|
||||
main_parser, TRUE,
|
||||
"gnc:count-data", gnc_counter_sixtp_parser_create(),
|
||||
@ -239,21 +244,42 @@ gnc_book_load_from_xml_file_v2(
|
||||
"gnc:transaction", gnc_transaction_sixtp_parser_create(),
|
||||
NULL, NULL))
|
||||
{
|
||||
xaccLogEnable ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
if(!sixtp_parse_file(top_parser, gnc_book_get_file_path(book),
|
||||
NULL, &gd, &parse_result))
|
||||
{
|
||||
sixtp_destroy(top_parser);
|
||||
xaccLogEnable ();
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* mark the newly read group as saved, since the act of putting
|
||||
* it together will have caused it to be marked up as not-saved.
|
||||
*/
|
||||
xaccGroupMarkSaved (gnc_book_get_group(book));
|
||||
|
||||
/* also mark the pricedb as saved for the same reasons */
|
||||
gnc_pricedb_mark_clean (gnc_book_get_pricedb (book));
|
||||
|
||||
/* auto-number the accounts, if they are not already numbered */
|
||||
xaccGroupDepthAutoCode (gnc_book_get_group(book));
|
||||
|
||||
/* commit all groups, this completes the BeginEdit started when the
|
||||
* account_end_handler finished reading the account.
|
||||
*/
|
||||
xaccAccountGroupCommitEdit (gnc_book_get_group(book));
|
||||
|
||||
/* set up various state that is not normally stored in the byte stream */
|
||||
xaccRecomputeGroupBalance (gnc_book_get_group(book));
|
||||
|
||||
/* start logging again */
|
||||
xaccLogEnable ();
|
||||
|
||||
/* DEBUG */
|
||||
print_counter_data(gd.counter);
|
||||
/* print_counter_data(gd.counter); */
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@ -468,7 +494,7 @@ gnc_book_write_to_xml_file_v2(GNCBook *book, const char *filename)
|
||||
|
||||
fclose(out);
|
||||
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user