From 4e6157b74a8fb55eb4e6ab786858dfb055839f55 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 23 Sep 2004 02:37:42 -0400 Subject: added some error checking --- main.cc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'main.cc') diff --git a/main.cc b/main.cc index 10e57f2a..27ebc021 100644 --- a/main.cc +++ b/main.cc @@ -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); -- cgit v1.2.3