From f26955c0d286d306c674a3db0751d54dba9bb77e Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 2 Jan 2015 21:18:21 +0000 Subject: [PATCH] Fixed loot_write_minimal_list() bugs. If the output file exists but the overwrite flag is false, it's not an invalid argument, so don't use that error code. Also fixed an uncaught exception on write failure. --- src/api/api.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index a0a515c7..5c5eab7e 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -796,7 +796,7 @@ LOOT_API unsigned int loot_write_minimal_list(loot_db db, const char * const out return c_error(loot_error_invalid_args, "Output directory does not exist."); if (boost::filesystem::exists(outputFile) && !overwrite) - return c_error(loot_error_invalid_args, "Output file exists but overwrite is not set to true."); + return c_error(loot_error_file_write_fail, "Output file exists but overwrite is not set to true."); loot::Masterlist temp = db->masterlist; std::unordered_set minimalPlugins; @@ -814,11 +814,16 @@ LOOT_API unsigned int loot_write_minimal_list(loot_db db, const char * const out << YAML::EndMap; boost::filesystem::path p(outputFile); - loot::ofstream out(p); - if (out.fail()) - return c_error(loot_error_invalid_args, "Couldn't open output file"); - out << yout.c_str(); - out.close(); + try { + loot::ofstream out(p); + if (out.fail()) + return c_error(loot_error_invalid_args, "Couldn't open output file."); + out << yout.c_str(); + out.close(); + } + catch (std::exception& e) { + return c_error(loot_error_file_write_fail, e.what()); + } return loot_ok; }