aboutsummaryrefslogtreecommitdiff
path: root/paludis/environments/paludis/world.cc
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-09 21:35:39 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-09 21:35:39 +0000
commit8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3 (patch)
treedb429b81a81135f285ed2ff16c873d65f09a813f /paludis/environments/paludis/world.cc
parentd946b89871e6dad288440d5fd1ad29bfcd1dff1d (diff)
downloadpaludis-8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3.tar.gz
paludis-8772b7a5c74c3254a53e70a922e9e0a2bc1c09c3.tar.xz
Avoid std::ifstream and std::ofstream.
Unfortunately std::ifstream and std::ofstream are allowed to fail in unobvious ways when given a duff file. In particular, gcc won't error out when a std::ifstream is created for a directory until the first read occurs. So we write our own stream buffer classes that do error checking and throw useful exceptions on error, and use those instead.
Diffstat (limited to 'paludis/environments/paludis/world.cc')
-rw-r--r--paludis/environments/paludis/world.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/paludis/environments/paludis/world.cc b/paludis/environments/paludis/world.cc
index 94e5ee94f..f78daca14 100644
--- a/paludis/environments/paludis/world.cc
+++ b/paludis/environments/paludis/world.cc
@@ -24,11 +24,11 @@
#include <paludis/util/stringify.hh>
#include <paludis/util/log.hh>
#include <paludis/util/make_named_values.hh>
+#include <paludis/util/safe_ofstream.hh>
#include <paludis/set_file.hh>
#include <paludis/user_dep_spec.hh>
#include <paludis/dep_tag.hh>
#include <tr1/functional>
-#include <fstream>
using namespace paludis;
using namespace paludis::paludis_environment;
@@ -103,11 +103,14 @@ World::_add_string_to_world(const std::string & n) const
if (! _imp->maybe_world_file->exists())
{
- std::ofstream f(stringify(*_imp->maybe_world_file).c_str());
- if (! f)
+ try
+ {
+ SafeOFStream f(*_imp->maybe_world_file);
+ }
+ catch (const SafeOFStreamError & e)
{
Log::get_instance()->message("paludis_environment.world.cannot_create", ll_warning, lc_no_context)
- << "Cannot create world file '" << *_imp->maybe_world_file << "'";
+ << "Cannot create world file '" << *_imp->maybe_world_file << "': '" << e.message() << "' (" << e.what() << ")";
return;
}
}