aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 13:13:57 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-05 13:13:57 +0000
commit6791d0e7a1f4508d39461aad371961b2f085301e (patch)
tree19fde85780d7eb674e5fd11d04340bdf86607d10
parentaaf74164232371436e46749da85db5d7320f9cc8 (diff)
downloadpaludis-6791d0e7a1f4508d39461aad371961b2f085301e.tar.gz
paludis-6791d0e7a1f4508d39461aad371961b2f085301e.tar.xz
initial specpath support. This will break for people relying upon ROOT currently.
-rw-r--r--paludis/config_file.cc16
-rw-r--r--paludis/config_file.hh12
-rw-r--r--paludis/default_config.cc113
-rw-r--r--paludis/default_config.hh2
-rw-r--r--paludis/portage_repository.cc28
-rw-r--r--paludis/portage_repository.hh3
6 files changed, 101 insertions, 73 deletions
diff --git a/paludis/config_file.cc b/paludis/config_file.cc
index 58623ad..ea363c9 100644
--- a/paludis/config_file.cc
+++ b/paludis/config_file.cc
@@ -143,6 +143,22 @@ KeyValueConfigFile::KeyValueConfigFile(const std::string & filename) :
need_lines();
}
+KeyValueConfigFile::KeyValueConfigFile(std::istream * const s,
+ const std::map<std::string, std::string> & m) :
+ ConfigFile(s),
+ _entries(m.begin(), m.end())
+{
+ need_lines();
+}
+
+KeyValueConfigFile::KeyValueConfigFile(const std::string & filename,
+ const std::map<std::string, std::string> & m) :
+ ConfigFile(filename),
+ _entries(m.begin(), m.end())
+{
+ need_lines();
+}
+
KeyValueConfigFile::~KeyValueConfigFile()
{
}
diff --git a/paludis/config_file.hh b/paludis/config_file.hh
index a8da47f..66cda63 100644
--- a/paludis/config_file.hh
+++ b/paludis/config_file.hh
@@ -222,6 +222,18 @@ namespace paludis
KeyValueConfigFile(const std::string & filename);
/**
+ * Constructor, from a stream, with defaults.
+ */
+ KeyValueConfigFile(std::istream * const,
+ const std::map<std::string, std::string> &);
+
+ /**
+ * Constructor, from a filename, with defaults.
+ */
+ KeyValueConfigFile(const std::string & filename,
+ const std::map<std::string, std::string> &);
+
+ /**
* Destructor.
*/
~KeyValueConfigFile();
diff --git a/paludis/default_config.cc b/paludis/default_config.cc
index e8f562e..5455d3d 100644
--- a/paludis/default_config.cc
+++ b/paludis/default_config.cc
@@ -24,6 +24,7 @@
#include <paludis/util/iterator.hh>
#include <paludis/util/fs_entry.hh>
#include <paludis/util/is_file_with_extension.hh>
+#include <paludis/util/log.hh>
#include <paludis/util/stringify.hh>
#include <paludis/util/system.hh>
#include <paludis/util/tokeniser.hh>
@@ -47,20 +48,46 @@ DefaultConfig::DefaultConfig()
Tokeniser<delim_kind::AnyOfTag, delim_mode::DelimiterTag> tokeniser(" \t\n");
- /* repositories */
+ /* indirection */
+ std::string root_prefix;
+ std::string config_suffix;
+ if (! _config_suffix.empty())
+ config_suffix = "-" + _config_suffix;
+
+ FSEntry config_dir(FSEntry(getenv_or_error("HOME")) / (".paludis" + config_suffix));
+ if (! config_dir.exists())
+ config_dir = (FSEntry(SYSCONFDIR) / ("paludis" + config_suffix));
+ if (! config_dir.exists())
+ throw DefaultConfigError("Can't find configuration directory");
+
+ Log::get_instance()->message(ll_debug, "DefaultConfig initial directory is '"
+ + stringify(config_dir) + "'");
+
+ if ((config_dir / "specpath").exists())
{
- std::list<FSEntry> dirs;
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- dirs.push_back(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "repositories");
- else
+ KeyValueConfigFile specpath(config_dir / "specpath");
+ root_prefix = specpath.get("root");
+ config_suffix = specpath.get("config-suffix");
+
+ if (! root_prefix.empty() && stringify(FSEntry(root_prefix).realpath()) != "/")
{
- dirs.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("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");
+ config_dir = FSEntry(root_prefix) / SYSCONFDIR / ("paludis" + config_suffix);
+ if (! config_dir.exists())
+ throw DefaultConfigError("Can't find configuration directory under root");
}
+ }
+
+ std::map<std::string, std::string> conf_vars;
+ conf_vars.insert(std::make_pair("ROOT", root_prefix));
+
+ Log::get_instance()->message(ll_debug, "DefaultConfig real directory is '"
+ + stringify(config_dir) + "', root prefix is '" + root_prefix +
+ "', config suffix is '" + config_suffix + "'");
+
+ /* repositories */
+ {
+ std::list<FSEntry> dirs;
+ dirs.push_back(config_dir / "repositories");
std::list<FSEntry> repo_files;
for (std::list<FSEntry>::const_iterator dir(dirs.begin()), dir_end(dirs.end()) ;
@@ -78,7 +105,7 @@ DefaultConfig::DefaultConfig()
{
Context local_context("When reading repository file '" + stringify(*repo_file) + "':");
- KeyValueConfigFile k(*repo_file);
+ KeyValueConfigFile k(*repo_file, conf_vars);
std::string format(k.get("format"));
if (format.empty())
@@ -90,6 +117,7 @@ DefaultConfig::DefaultConfig()
std::map<std::string, std::string> keys(k.begin(), k.end());
keys["repo_file"] = stringify(*repo_file);
+ keys["root"] = root_prefix;
_repos.push_back(RepositoryConfigEntry(format, importance, keys));
}
@@ -102,17 +130,7 @@ DefaultConfig::DefaultConfig()
/* keywords */
{
std::list<FSEntry> files;
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- files.push_back(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "keywords.conf");
- else
- {
- files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("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");
- }
+ files.push_back(config_dir / "keywords.conf");
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
file != file_end ; ++file)
@@ -151,17 +169,7 @@ DefaultConfig::DefaultConfig()
/* user mask */
{
std::list<FSEntry> files;
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- files.push_back(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "package_mask.conf");
- else
- {
- files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("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");
- }
+ files.push_back(config_dir / "package_mask.conf");
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
file != file_end ; ++file)
@@ -184,17 +192,7 @@ DefaultConfig::DefaultConfig()
/* user unmask */
{
std::list<FSEntry> files;
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- files.push_back(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "package_unmask.conf");
- else
- {
- files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("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");
- }
+ files.push_back(config_dir / "package_unmask.conf");
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
file != file_end ; ++file)
@@ -217,17 +215,7 @@ DefaultConfig::DefaultConfig()
/* use */
{
std::list<FSEntry> files;
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- files.push_back(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "use.conf");
- else
- {
- files.push_back(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("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");
- }
+ files.push_back(config_dir / "use.conf");
for (std::list<FSEntry>::const_iterator file(files.begin()), file_end(files.end()) ;
file != file_end ; ++file)
@@ -276,6 +264,8 @@ DefaultConfig::DefaultConfig()
throw DefaultConfigError("No default keywords specified (a keywords.conf file should "
"contain an entry in the form '* keyword')");
}
+
+ _bashrc_files = stringify(config_dir / "bashrc");
}
DefaultConfig::~DefaultConfig()
@@ -310,15 +300,6 @@ DefaultConfig::set_config_suffix(const std::string & s)
std::string
DefaultConfig::bashrc_files() const
{
- if (! getenv_with_default("PALUDIS_CONFIG_DIR", "").empty())
- return stringify(FSEntry(getenv_or_error("PALUDIS_CONFIG_DIR")) / "bashrc");
- else
- return
- stringify(FSEntry(getenv_with_default("ROOT", "/") + "" SYSCONFDIR)
- / ("paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
- / "bashrc") + " " +
- stringify(FSEntry(getenv_or_error("HOME"))
- / (".paludis" + (_config_suffix.empty() ? std::string("") : "-" + _config_suffix))
- / "bashrc");
+ return _bashrc_files;
}
diff --git a/paludis/default_config.hh b/paludis/default_config.hh
index 71b9ed7..3ec867d 100644
--- a/paludis/default_config.hh
+++ b/paludis/default_config.hh
@@ -118,6 +118,8 @@ namespace paludis
static std::string _config_suffix;
static bool _config_suffix_can_be_set;
+ std::string _bashrc_files;
+
DefaultConfig();
~DefaultConfig();
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 54caf69..ce7e94e 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -109,6 +109,9 @@ namespace paludis
/// Sync URL
std::string sync;
+ /// Root location
+ FSEntry root;
+
/// Have we loaded our category names?
mutable bool has_category_names;
@@ -171,7 +174,8 @@ namespace paludis
/// Constructor.
Implementation(const Environment * const,
const PackageDatabase * const d, const FSEntry & l, const FSEntry & p,
- const FSEntry & c, const FSEntry &, const FSEntry &, const std::string &);
+ const FSEntry & c, const FSEntry &, const FSEntry &, const std::string &,
+ const FSEntry &);
/// Destructor.
~Implementation();
@@ -187,7 +191,8 @@ namespace paludis
Implementation<PortageRepository>::Implementation(const Environment * const env,
const PackageDatabase * const d,
const FSEntry & l, const FSEntry & p, const FSEntry & c,
- const FSEntry & e, const FSEntry & dd, const std::string & syn) :
+ const FSEntry & e, const FSEntry & dd, const std::string & syn,
+ const FSEntry & r) :
db(d),
env(env),
location(l),
@@ -196,6 +201,7 @@ Implementation<PortageRepository>::Implementation(const Environment * const env,
eclassdir(e),
distdir(dd),
sync(syn),
+ root(r),
has_category_names(false),
has_repo_mask(false),
has_virtuals(false),
@@ -345,10 +351,11 @@ PortageRepository::PortageRepository(
const Environment * const e, const PackageDatabase * const d,
const FSEntry & location, const FSEntry & profile,
const FSEntry & cache, const FSEntry & eclassdir,
- const FSEntry & distdir, const std::string & sync) :
+ const FSEntry & distdir, const std::string & sync,
+ const FSEntry & root) :
Repository(PortageRepository::fetch_repo_name(location)),
PrivateImplementationPattern<PortageRepository>(new Implementation<PortageRepository>(e,
- d, location, profile, cache, eclassdir, distdir, sync))
+ d, location, profile, cache, eclassdir, distdir, sync, root))
{
_info.insert(std::make_pair(std::string("location"), location));
_info.insert(std::make_pair(std::string("profile"), profile));
@@ -356,6 +363,7 @@ PortageRepository::PortageRepository(
_info.insert(std::make_pair(std::string("eclassdir"), eclassdir));
_info.insert(std::make_pair(std::string("distdir"), distdir));
_info.insert(std::make_pair(std::string("format"), std::string("portage")));
+ _info.insert(std::make_pair(std::string("root"), stringify(root)));
if (! sync.empty())
_info.insert(std::make_pair(std::string("sync"), sync));
}
@@ -921,8 +929,12 @@ PortageRepository::make_portage_repository(
if (m.end() == m.find("sync") || ((sync = m.find("sync")->second)).empty())
; // nothing
+ std::string root;
+ if (m.end() == m.find("root") || ((root = m.find("root")->second)).empty())
+ root = "/";
+
return CountedPtr<Repository>(new PortageRepository(env, db, location, profile, cache,
- eclassdir, distdir, sync));
+ eclassdir, distdir, sync, root));
}
PortageRepositoryConfigurationError::PortageRepositoryConfigurationError(
@@ -1031,6 +1043,9 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
_imp->has_profile = true;
}
+ if (! _imp->root.is_directory())
+ throw InternalError(PALUDIS_HERE, "todo: root not a directory");
+
VersionMetadata::ConstPointer metadata(0);
if (! has_version(q, v))
{
@@ -1165,6 +1180,7 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
("ECLASSDIR", stringify(_imp->eclassdir))
("PORTDIR", stringify(_imp->location) + "/")
("DISTDIR", stringify(_imp->distdir))
+ ("ROOT", stringify(_imp->root))
("PALUDIS_TMPDIR", BIGTEMPDIR "/paludis/")
("PALUDIS_CONFIG_DIR", SYSCONFDIR "/paludis/")
("PALUDIS_PROFILE_DIR", _imp->profile)
@@ -1203,7 +1219,7 @@ PortageRepository::do_sync() const
throw InternalError(PALUDIS_HERE, "todo: no protocol for sync"); /// \todo fixme
SyncerMaker::get_instance()->find_maker(_imp->sync.substr(0, p))(
- _imp->sync, _imp->location)->sync();
+ _imp->location, _imp->sync)->sync();
return true;
}
diff --git a/paludis/portage_repository.hh b/paludis/portage_repository.hh
index 828828c..2eb96a4 100644
--- a/paludis/portage_repository.hh
+++ b/paludis/portage_repository.hh
@@ -104,7 +104,8 @@ namespace paludis
const PackageDatabase * const db,
const FSEntry & location, const FSEntry & profile,
const FSEntry & cache, const FSEntry & distdir,
- const FSEntry & eclassdir, const std::string & sync);
+ const FSEntry & eclassdir, const std::string & sync,
+ const FSEntry & root);
/**
* Virtual constructor.