aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-30 21:35:41 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2007-03-30 21:35:41 +0000
commit7353f5b4b430e916170d74da003fa8169c125556 (patch)
treed3ec21baecd8c3d294d2f2c359bd2728f037f2a2
parentf7ea662e169332c43e2b45370773ae4d13953610 (diff)
downloadpaludis-7353f5b4b430e916170d74da003fa8169c125556.tar.gz
paludis-7353f5b4b430e916170d74da003fa8169c125556.tar.xz
Better fallback code
-rw-r--r--paludis/environments/environment_maker.cc24
-rw-r--r--paludis/environments/environment_maker.hh6
-rw-r--r--paludis/environments/paludis/Makefile.am1
-rw-r--r--paludis/environments/paludis/paludis_config.cc7
-rw-r--r--paludis/environments/paludis/paludis_config.hh9
5 files changed, 45 insertions, 2 deletions
diff --git a/paludis/environments/environment_maker.cc b/paludis/environments/environment_maker.cc
index 302e4a9..f936baa 100644
--- a/paludis/environments/environment_maker.cc
+++ b/paludis/environments/environment_maker.cc
@@ -24,6 +24,7 @@
#include <paludis/util/system.hh>
#include <paludis/about.hh>
#include <list>
+#include <set>
#include <dlfcn.h>
#include <stdint.h>
@@ -141,7 +142,28 @@ EnvironmentMaker::make_from_spec(const std::string & s) const
if (key.empty())
key = "paludis";
- return (*find_maker(key))(suffix);
+ try
+ {
+ return (*find_maker(key))(suffix);
+ }
+ catch (const FallBackToAnotherMakerError &)
+ {
+ if (s.empty())
+ {
+ std::set<std::string> keys;
+ copy_keys(std::inserter(keys, keys.begin()));
+ if (keys.end() != keys.find("portage"))
+ return make_from_spec("portage");
+ else
+ throw;
+ }
+ else
+ throw;
+ }
+}
+
+FallBackToAnotherMakerError::FallBackToAnotherMakerError()
+{
}
extern "C"
diff --git a/paludis/environments/environment_maker.hh b/paludis/environments/environment_maker.hh
index 371dfec..33d539f 100644
--- a/paludis/environments/environment_maker.hh
+++ b/paludis/environments/environment_maker.hh
@@ -80,6 +80,12 @@ namespace paludis
const char * what() const throw ();
};
+ class FallBackToAnotherMakerError
+ {
+ protected:
+ FallBackToAnotherMakerError();
+ };
+
/**
* Virtual constructor for environments.
*
diff --git a/paludis/environments/paludis/Makefile.am b/paludis/environments/paludis/Makefile.am
index 8654bd6..edcc3f3 100644
--- a/paludis/environments/paludis/Makefile.am
+++ b/paludis/environments/paludis/Makefile.am
@@ -21,6 +21,7 @@ libpaludispaludisenvironment_la_LDFLAGS = -version-info @VERSION_LIB_CURRENT@:@V
if ! MONOLITHIC
libpaludispaludisenvironment_la_LIBADD = \
+ $(top_builddir)/paludis/environments/libpaludisenvironments.la \
$(top_builddir)/paludis/repositories/libpaludisrepositories.la \
$(top_builddir)/paludis/util/libpaludisutil.la \
$(top_builddir)/paludis/libpaludis.la
diff --git a/paludis/environments/paludis/paludis_config.cc b/paludis/environments/paludis/paludis_config.cc
index 03c12b9..8ee9f0b 100644
--- a/paludis/environments/paludis/paludis_config.cc
+++ b/paludis/environments/paludis/paludis_config.cc
@@ -288,6 +288,11 @@ PaludisConfigError::PaludisConfigError(const std::string & msg) throw () :
{
}
+PaludisConfigNoDirectoryError::PaludisConfigNoDirectoryError(const std::string & msg) throw () :
+ PaludisConfigError("Paludis configuration error: " + msg)
+{
+}
+
PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & suffix) :
PrivateImplementationPattern<PaludisConfig>(new Implementation<PaludisConfig>(e))
{
@@ -312,7 +317,7 @@ PaludisConfig::PaludisConfig(PaludisEnvironment * const e, const std::string & s
}
if (! local_config_dir.exists())
- throw PaludisConfigError("Can't find configuration directory (tried '"
+ throw PaludisConfigNoDirectoryError("Can't find configuration directory (tried '"
+ stringify(old_config_dir) + "', '" + stringify(local_config_dir) + "')");
Log::get_instance()->message(ll_debug, lc_no_context, "PaludisConfig initial directory is '"
diff --git a/paludis/environments/paludis/paludis_config.hh b/paludis/environments/paludis/paludis_config.hh
index 14c4918..a086d6c 100644
--- a/paludis/environments/paludis/paludis_config.hh
+++ b/paludis/environments/paludis/paludis_config.hh
@@ -26,6 +26,7 @@
#include <paludis/util/exception.hh>
#include <paludis/util/instantiation_policy.hh>
#include <paludis/util/sr.hh>
+#include <paludis/environments/environment_maker.hh>
#include <string>
@@ -65,6 +66,14 @@ namespace paludis
PaludisConfigError(const std::string & msg) throw ();
};
+ class PALUDIS_VISIBLE PaludisConfigNoDirectoryError :
+ public PaludisConfigError,
+ public FallBackToAnotherMakerError
+ {
+ public:
+ PaludisConfigNoDirectoryError(const std::string & msg) throw ();
+ };
+
#include <paludis/environments/paludis/use_config_entry-sr.hh>
#include <paludis/environments/paludis/repository_config_entry-sr.hh>