aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 07:58:56 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 07:58:56 +0000
commit67b08436d6ab0bdec10f259a691d8de5e1a75d44 (patch)
tree3f071cf808af50511c59ed72ef753fd27f99b257
parent998ded909087493cc1ad80801ec8409193b8d581 (diff)
downloadpaludis-67b08436d6ab0bdec10f259a691d8de5e1a75d44.tar.gz
paludis-67b08436d6ab0bdec10f259a691d8de5e1a75d44.tar.xz
config-suffix support
-rw-r--r--paludis/default_config.cc63
-rw-r--r--paludis/default_config.hh9
-rw-r--r--src/command_line.cc1
-rw-r--r--src/command_line.hh3
-rw-r--r--src/paludis.cc2
5 files changed, 68 insertions, 10 deletions
diff --git a/paludis/default_config.cc b/paludis/default_config.cc
index ae3da3c..f2cf9c8 100644
--- a/paludis/default_config.cc
+++ b/paludis/default_config.cc
@@ -41,6 +41,8 @@ DefaultConfigError::DefaultConfigError(const std::string & msg) throw () :
DefaultConfig::DefaultConfig()
{
+ _config_suffix_can_be_set = false;
+
Context context("When loading default configuration:");
Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
@@ -53,8 +55,11 @@ DefaultConfig::DefaultConfig()
else
{
dirs.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / "paludis" / "repositories");
- dirs.push_back(FSEntry(getenv_or_error("HOME")) / ".paludis" / "repositories");
+ / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "repositories");
+ dirs.push_back(FSEntry(getenv_or_error("HOME"))
+ / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "repositories");
}
std::list<FSEntry> repo_files;
@@ -102,8 +107,11 @@ DefaultConfig::DefaultConfig()
else
{
files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / "paludis" / "keywords.conf");
- files.push_back(FSEntry(getenv_or_error("HOME")) / ".paludis" / "keywords.conf");
+ / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "keywords.conf");
+ files.push_back(FSEntry(getenv_or_error("HOME"))
+ / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "keywords.conf");
}
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
@@ -148,8 +156,11 @@ DefaultConfig::DefaultConfig()
else
{
files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / "paludis" / "package_mask.conf");
- files.push_back(FSEntry(getenv_or_error("HOME")) / ".paludis" / "package_mask.conf");
+ / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "package_mask.conf");
+ files.push_back(FSEntry(getenv_or_error("HOME"))
+ / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "package_mask.conf");
}
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
@@ -178,8 +189,11 @@ DefaultConfig::DefaultConfig()
else
{
files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / "paludis" / "package_unmask.conf");
- files.push_back(FSEntry(getenv_or_error("HOME")) / ".paludis" / "package_unmask.conf");
+ / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "package_unmask.conf");
+ files.push_back(FSEntry(getenv_or_error("HOME"))
+ / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "package_unmask.conf");
}
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
@@ -208,8 +222,11 @@ DefaultConfig::DefaultConfig()
else
{
files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / "paludis" / "use.conf");
- files.push_back(FSEntry(getenv_or_error("HOME")) / ".paludis" / "use.conf");
+ / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "use.conf");
+ files.push_back(FSEntry(getenv_or_error("HOME"))
+ / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
+ / "use.conf");
}
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
@@ -264,3 +281,29 @@ DefaultConfig::DefaultConfig()
DefaultConfig::~DefaultConfig()
{
}
+
+std::string DefaultConfig::_config_suffix;
+bool DefaultConfig::_config_suffix_can_be_set(true);
+
+void
+DefaultConfig::set_config_suffix(const std::string & s)
+{
+ if (! _config_suffix_can_be_set)
+ throw InternalError(PALUDIS_HERE, "DefaultConfig::set_config_suffix called after "
+ "DefaultConfig has been instantiated.");
+
+ static const std::string allowed_chars(
+ "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "0123456789-_+:");
+
+ if (std::string::npos != s.find_first_not_of(allowed_chars))
+ throw DefaultConfigError("Invalid config suffix '" + s + "'");
+
+ if (! s.empty())
+ if ('-' == s.at(0) || '-' == s.at(s.length() - 1))
+ throw DefaultConfigError("Invalid config suffix '" + s + "'");
+
+ _config_suffix = s;
+}
+
diff --git a/paludis/default_config.hh b/paludis/default_config.hh
index 4f82539..2772745 100644
--- a/paludis/default_config.hh
+++ b/paludis/default_config.hh
@@ -115,6 +115,9 @@ namespace paludis
friend class InstantiationPolicy<DefaultConfig, instantiation_method::SingletonAsNeededTag>;
private:
+ static std::string _config_suffix;
+ static bool _config_suffix_can_be_set;
+
DefaultConfig();
~DefaultConfig();
@@ -142,6 +145,12 @@ namespace paludis
public:
/**
+ * Set config suffix. Must be called before we do anything, or not
+ * at all.
+ */
+ static void set_config_suffix(const std::string &);
+
+ /**
* An iterator for our repositories.
*/
typedef std::list<RepositoryConfigEntry>::const_iterator RepositoryIterator;
diff --git a/src/command_line.cc b/src/command_line.cc
index e038700..5dbff82 100644
--- a/src/command_line.cc
+++ b/src/command_line.cc
@@ -43,6 +43,7 @@ CommandLine::CommandLine() :
"qa"),
a_no_colour(&general_args, "no-colour", 'c', "Do not use colour"),
a_no_color(&a_no_colour, "no-color"),
+ a_config_suffix(&general_args, "config-suffix", '\0', "Config directory suffix"),
query_args(this, "Query options"),
a_show_slot(&query_args, "show-slot", 'S', "Show SLOTs"),
diff --git a/src/command_line.hh b/src/command_line.hh
index 7640ef9..f91cfc3 100644
--- a/src/command_line.hh
+++ b/src/command_line.hh
@@ -97,6 +97,9 @@ class CommandLine :
/// --no-color
paludis::args::AliasArg a_no_color;
+ /// --config-suffix
+ paludis::args::StringArg a_config_suffix;
+
///}
/// \name Query arguments
diff --git a/src/paludis.cc b/src/paludis.cc
index 4e4b6ae..bfe4853 100644
--- a/src/paludis.cc
+++ b/src/paludis.cc
@@ -70,6 +70,8 @@ main(int argc, char *argv[])
else
throw DoHelp("bad value for --log-level");
+ if (CommandLine::get_instance()->a_config_suffix.specified())
+ p::DefaultConfig::set_config_suffix(CommandLine::get_instance()->a_config_suffix.argument());
if (1 != (CommandLine::get_instance()->a_query.specified() +
CommandLine::get_instance()->a_version.specified() +