summaryrefslogtreecommitdiff
path: root/binary.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2005-02-01 02:36:51 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 02:40:52 -0400
commitd1d63be306aaef4a31e90b2f39402cf562e405c0 (patch)
tree7d85c99333074409861132191fc96fc6642bbe11 /binary.cc
parentdf44635260f08564e3ac61ad595fb87b73338c89 (diff)
downloadfork-ledger-d1d63be306aaef4a31e90b2f39402cf562e405c0.tar.gz
fork-ledger-d1d63be306aaef4a31e90b2f39402cf562e405c0.tar.bz2
fork-ledger-d1d63be306aaef4a31e90b2f39402cf562e405c0.zip
Updated binary cache version, for good measure.
(read_binary_journal): Read in the price_db, in order to throw away the cache if it has changed. (write_binary_journal): Removed unused "files" parameter. Changed logic for writing out files list. Also, write out the prices database that was used. (py_write_binary_journal): Removed "files" argument.
Diffstat (limited to 'binary.cc')
-rw-r--r--binary.cc25
1 files changed, 17 insertions, 8 deletions
diff --git a/binary.cc b/binary.cc
index 601c779e..112ad43c 100644
--- a/binary.cc
+++ b/binary.cc
@@ -11,7 +11,7 @@
namespace ledger {
static unsigned long binary_magic_number = 0xFFEED765;
-static unsigned long format_version = 0x00020029;
+static unsigned long format_version = 0x00020031;
static account_t ** accounts;
static account_t ** accounts_next;
@@ -359,6 +359,12 @@ unsigned int read_binary_journal(std::istream& in,
journal->sources.push_back(path);
}
+
+ // Make sure that the cache uses the same price database,
+ // otherwise it means that LEDGER_PRICE_DB has been changed, and
+ // we should ignore this cache file.
+ if (read_binary_string(in) != journal->price_db)
+ return 0;
}
// Read all of the data in at once, so that we're just dealing with
@@ -634,8 +640,7 @@ void write_binary_account(std::ostream& out, account_t * account)
write_binary_account(out, (*i).second);
}
-void write_binary_journal(std::ostream& out, journal_t * journal,
- strings_list * files)
+void write_binary_journal(std::ostream& out, journal_t * journal)
{
account_index =
commodity_index = 0;
@@ -646,18 +651,22 @@ void write_binary_journal(std::ostream& out, journal_t * journal,
// Write out the files that participated in this journal, so that
// they can be checked for changes on reading.
- if (! files) {
+ if (journal->sources.size() == 0) {
write_binary_number<unsigned short>(out, 0);
} else {
- write_binary_number<unsigned short>(out, files->size());
- for (strings_list::const_iterator i = files->begin();
- i != files->end();
+ write_binary_number<unsigned short>(out, journal->sources.size());
+ for (strings_list::const_iterator i = journal->sources.begin();
+ i != journal->sources.end();
i++) {
write_binary_string(out, *i);
struct stat info;
stat((*i).c_str(), &info);
write_binary_number(out, std::time_t(info.st_mtime));
}
+
+ // Write out the price database that relates to this data file, so
+ // that if it ever changes the cache can be invalidated.
+ write_binary_string(out, journal->price_db);
}
std::ostream::pos_type data_val = out.tellp();
@@ -757,7 +766,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(binary_parse_overloads,
void py_write_binary_journal(const std::string& path, journal_t * journal)
{
std::ofstream out(path.c_str());
- write_binary_journal(out, journal, &journal->sources);
+ write_binary_journal(out, journal);
}
void export_binary() {