diff options
author | John Wiegley <johnw@newartisans.com> | 2004-09-23 02:37:42 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-09-23 02:37:42 -0400 |
commit | 4e6157b74a8fb55eb4e6ab786858dfb055839f55 (patch) | |
tree | b4040bd771302c4df1bd139bea78a6ef9ed149d0 /main.cc | |
parent | 12c0c08f1ea8cda276f390c6929a7b59b86448ed (diff) | |
download | fork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.tar.gz fork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.tar.bz2 fork-ledger-4e6157b74a8fb55eb4e6ab786858dfb055839f55.zip |
added some error checking
Diffstat (limited to 'main.cc')
-rw-r--r-- | main.cc | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -247,8 +247,13 @@ int parse_and_report(int argc, char * argv[], char * envp[]) TIMER_START(report_gen); std::ostream * out = &std::cout; - if (! config.output_file.empty()) - out = new std::ofstream(config.output_file.c_str()); + if (! config.output_file.empty()) { + if (access(config.output_file.c_str(), W_OK) == -1) + throw error(std::string("Cannot write output to file '" + + config.output_file + "'")); + else + out = new std::ofstream(config.output_file.c_str()); + } // Compile the format strings @@ -328,9 +333,15 @@ int parse_and_report(int argc, char * argv[], char * envp[]) TIMER_START(write_cache); - if (config.use_cache && config.cache_dirty && ! config.cache_file.empty()) { - std::ofstream stream(config.cache_file.c_str()); - write_binary_journal(stream, journal.get(), &journal->sources); + if (config.use_cache && config.cache_dirty && + ! config.cache_file.empty()) { + if (access(config.cache_file.c_str(), W_OK) == -1) { + std::cerr << "Warning: Cannot update cache file '" + << config.cache_file << "'" << std::endl; + } else { + std::ofstream stream(config.cache_file.c_str()); + write_binary_journal(stream, journal.get(), &journal->sources); + } } TIMER_STOP(write_cache); |