aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-17 15:37:48 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-04-17 15:37:48 +0000
commit95305ce1c02130aaf8128a56030d34316e3c1cc8 (patch)
tree66ae96b0b3b46679e76b66f757046db148819502
parentb415c11547f91e907aaff18f1a039113cb1cb7e3 (diff)
downloadpaludis-95305ce1c02130aaf8128a56030d34316e3c1cc8.tar.gz
paludis-95305ce1c02130aaf8128a56030d34316e3c1cc8.tar.xz
Remove automatic cast from FSEntry to std::string, since all it does is lead to silly bugs going undetected at compile time. Change code that relies upon this automatic cast. Provide overloaded constructors for ConfigFile and descendents that take an FSEntry rather than a std::string.
-rw-r--r--paludis/config_file.cc51
-rw-r--r--paludis/config_file.hh33
-rw-r--r--paludis/config_file_TEST.cc6
-rw-r--r--paludis/portage_repository.cc18
-rw-r--r--paludis/util/fs_entry.cc7
-rw-r--r--paludis/util/fs_entry.hh7
-rw-r--r--paludis/util/fs_entry_TEST.cc12
-rw-r--r--paludis/vdb_repository.cc6
8 files changed, 111 insertions, 29 deletions
diff --git a/paludis/config_file.cc b/paludis/config_file.cc
index b667f48..47a04d0 100644
--- a/paludis/config_file.cc
+++ b/paludis/config_file.cc
@@ -51,6 +51,19 @@ catch (...)
throw;
}
+ConfigFile::ConfigFile(const FSEntry & filename) try :
+ _stream(_make_stream(stringify(filename))),
+ _has_lines(false),
+ _filename(stringify(filename)),
+ _destroy_stream(true)
+{
+}
+catch (...)
+{
+ _destroy_stream = false;
+ throw;
+}
+
ConfigFile::~ConfigFile()
{
if (_stream && _destroy_stream)
@@ -135,6 +148,12 @@ LineConfigFile::LineConfigFile(const std::string & filename) :
need_lines();
}
+LineConfigFile::LineConfigFile(const FSEntry & filename) :
+ ConfigFile(filename)
+{
+ need_lines();
+}
+
void
LineConfigFile::accept_line(const std::string & s) const
{
@@ -160,6 +179,12 @@ KeyValueConfigFile::KeyValueConfigFile(const std::string & filename) :
need_lines();
}
+KeyValueConfigFile::KeyValueConfigFile(const FSEntry & filename) :
+ ConfigFile(filename)
+{
+ need_lines();
+}
+
KeyValueConfigFile::KeyValueConfigFile(std::istream * const s,
const std::map<std::string, std::string> & m) :
ConfigFile(s),
@@ -176,6 +201,14 @@ KeyValueConfigFile::KeyValueConfigFile(const std::string & filename,
need_lines();
}
+KeyValueConfigFile::KeyValueConfigFile(const FSEntry & filename,
+ const std::map<std::string, std::string> & m) :
+ ConfigFile(filename),
+ _entries(m.begin(), m.end())
+{
+ need_lines();
+}
+
KeyValueConfigFile::~KeyValueConfigFile()
{
}
@@ -293,6 +326,14 @@ AdvisoryFile::AdvisoryFile(const std::string & filename) :
sanitise();
}
+AdvisoryFile::AdvisoryFile(const FSEntry & filename) :
+ ConfigFile(filename),
+ _end_of_header(false)
+{
+ need_lines();
+ sanitise();
+}
+
AdvisoryFile::AdvisoryFile(std::istream * const s,
const std::map<std::string, std::string> & m) :
ConfigFile(s),
@@ -314,6 +355,16 @@ AdvisoryFile::AdvisoryFile(const std::string & filename,
sanitise();
}
+AdvisoryFile::AdvisoryFile(const FSEntry & filename,
+ const std::map<std::string, std::string> & m) :
+ ConfigFile(filename),
+ _entries(m.begin(), m.end()),
+ _end_of_header(false)
+{
+ need_lines();
+ sanitise();
+}
+
AdvisoryFile::~AdvisoryFile()
{
}
diff --git a/paludis/config_file.hh b/paludis/config_file.hh
index 463c0e5..cba5f51 100644
--- a/paludis/config_file.hh
+++ b/paludis/config_file.hh
@@ -24,6 +24,7 @@
#include <list>
#include <map>
#include <paludis/util/exception.hh>
+#include <paludis/util/fs_entry.hh>
#include <paludis/util/instantiation_policy.hh>
#include <string>
@@ -108,6 +109,11 @@ namespace paludis
ConfigFile(const std::string & filename);
/**
+ * Constructor, from a file.
+ */
+ ConfigFile(const FSEntry & filename);
+
+ /**
* Our filename, or blank if unknown.
*/
std::string filename() const
@@ -148,6 +154,11 @@ namespace paludis
LineConfigFile(const std::string & filename);
/**
+ * Constructor, from a filename.
+ */
+ LineConfigFile(const FSEntry & filename);
+
+ /**
* Iterator over our lines.
*/
typedef std::list<std::string>::const_iterator Iterator;
@@ -222,6 +233,11 @@ namespace paludis
KeyValueConfigFile(const std::string & filename);
/**
+ * Constructor, from a filename.
+ */
+ KeyValueConfigFile(const FSEntry & filename);
+
+ /**
* Constructor, from a stream, with defaults.
*/
KeyValueConfigFile(std::istream * const,
@@ -234,6 +250,12 @@ namespace paludis
const std::map<std::string, std::string> &);
/**
+ * Constructor, from a filename, with defaults.
+ */
+ KeyValueConfigFile(const FSEntry & filename,
+ const std::map<std::string, std::string> &);
+
+ /**
* Destructor.
*/
~KeyValueConfigFile();
@@ -319,6 +341,11 @@ namespace paludis
AdvisoryFile(const std::string & filename);
/**
+ * Constructor, from a filename.
+ */
+ AdvisoryFile(const FSEntry & filename);
+
+ /**
* Constructor, from a stream, with defaults.
*/
AdvisoryFile(std::istream * const,
@@ -331,6 +358,12 @@ namespace paludis
const std::map<std::string, std::string> &);
/**
+ * Constructor, from a filename, with defaults.
+ */
+ AdvisoryFile(const FSEntry & filename,
+ const std::map<std::string, std::string> &);
+
+ /**
* Destructor.
*/
~AdvisoryFile();
diff --git a/paludis/config_file_TEST.cc b/paludis/config_file_TEST.cc
index 81bc8d4..a2782dd 100644
--- a/paludis/config_file_TEST.cc
+++ b/paludis/config_file_TEST.cc
@@ -52,6 +52,12 @@ class TestFile : protected ConfigFile
need_lines();
}
+ TestFile(const FSEntry & filename) :
+ ConfigFile(filename)
+ {
+ need_lines();
+ }
+
mutable std::vector<std::string> lines;
protected:
diff --git a/paludis/portage_repository.cc b/paludis/portage_repository.cc
index 542dc78..70f1caa 100644
--- a/paludis/portage_repository.cc
+++ b/paludis/portage_repository.cc
@@ -382,14 +382,14 @@ Implementation<PortageRepository>::invalidate() const
}
PortageRepository::PortageRepository(const PortageRepositoryParams & p) :
- Repository(PortageRepository::fetch_repo_name(p.get<prpk_location>())),
+ Repository(PortageRepository::fetch_repo_name(stringify(p.get<prpk_location>()))),
PrivateImplementationPattern<PortageRepository>(new Implementation<PortageRepository>(p))
{
- _info.insert(std::make_pair(std::string("location"), _imp->location));
- _info.insert(std::make_pair(std::string("profile"), _imp->profile));
- _info.insert(std::make_pair(std::string("cache"), _imp->cache));
- _info.insert(std::make_pair(std::string("eclassdir"), _imp->eclassdir));
- _info.insert(std::make_pair(std::string("distdir"), _imp->distdir));
+ _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
+ _info.insert(std::make_pair(std::string("profile"), stringify(_imp->profile)));
+ _info.insert(std::make_pair(std::string("cache"), stringify(_imp->cache)));
+ _info.insert(std::make_pair(std::string("eclassdir"), stringify(_imp->eclassdir)));
+ _info.insert(std::make_pair(std::string("distdir"), stringify(_imp->distdir)));
_info.insert(std::make_pair(std::string("format"), std::string("portage")));
_info.insert(std::make_pair(std::string("root"), stringify(_imp->root)));
if (! _imp->sync.empty())
@@ -696,7 +696,7 @@ PortageRepository::do_version_metadata(
VirtualsMap::iterator vi(_imp->virtuals_map.end());
if (cache_file.is_regular_file())
{
- std::ifstream cache(std::string(cache_file).c_str());
+ std::ifstream cache(stringify(cache_file).c_str());
std::string line;
if (cache)
@@ -1269,7 +1269,7 @@ PortageRepository::do_install(const QualifiedPackageName & q, const VersionSpec
("ROOT", stringify(_imp->root) + "/")
("PALUDIS_TMPDIR", BIGTEMPDIR "/paludis/")
("PALUDIS_CONFIG_DIR", SYSCONFDIR "/paludis/")
- ("PALUDIS_PROFILE_DIR", _imp->profile)
+ ("PALUDIS_PROFILE_DIR", stringify(_imp->profile))
("PALUDIS_BASHRC_FILES", _imp->env->bashrc_files())
("PALUDIS_COMMAND", _imp->env->paludis_command())
("KV", kernel_version())
@@ -1391,7 +1391,7 @@ PortageRepository::do_sync() const
SyncOptions opts(_imp->sync_exclude);
SyncerMaker::get_instance()->find_maker(_imp->sync.substr(0, std::min(p, q)))(
- _imp->location, _imp->sync.substr(q < p ? q + 1 : 0))->sync(opts);
+ stringify(_imp->location), _imp->sync.substr(q < p ? q + 1 : 0))->sync(opts);
return true;
}
diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc
index 18b8a13..b101479 100644
--- a/paludis/util/fs_entry.cc
+++ b/paludis/util/fs_entry.cc
@@ -76,11 +76,6 @@ FSEntry::operator= (const FSEntry & other)
return *this;
}
-FSEntry::operator std::string() const
-{
- return _path;
-}
-
FSEntry
FSEntry::operator/ (const FSEntry & rhs) const
{
@@ -301,7 +296,7 @@ FSEntry::cwd()
std::ostream &
paludis::operator<< (std::ostream & s, const FSEntry & f)
{
- s << std::string(f);
+ s << f._path;
return s;
}
diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh
index 7b54152..9a421c0 100644
--- a/paludis/util/fs_entry.hh
+++ b/paludis/util/fs_entry.hh
@@ -81,6 +81,8 @@ namespace paludis
comparison_mode::FullComparisonTag,
comparison_method::CompareByMemberTag<std::string> >
{
+ friend std::ostream & operator<< (std::ostream & s, const FSEntry & f);
+
private:
std::string _path;
@@ -147,11 +149,6 @@ namespace paludis
}
/**
- * Fetch a string representation of our path.
- */
- operator std::string() const;
-
- /**
* Does a filesystem entry exist at our location?
*/
bool exists() const;
diff --git a/paludis/util/fs_entry_TEST.cc b/paludis/util/fs_entry_TEST.cc
index a942739..d4971b5 100644
--- a/paludis/util/fs_entry_TEST.cc
+++ b/paludis/util/fs_entry_TEST.cc
@@ -100,7 +100,7 @@ namespace test_cases
FSEntry r(f.realpath());
TEST_CHECK(r.is_regular_file());
std::string g("fs_entry_TEST_dir/dir_a/file_in_a");
- TEST_CHECK_EQUAL(std::string(r).substr(std::string(r).length() - g.length()), g);
+ TEST_CHECK_EQUAL(stringify(r).substr(stringify(r).length() - g.length()), g);
}
} test_fs_entry_realpath;
@@ -199,15 +199,15 @@ namespace test_cases
FSEntry e("..");
TEST_CHECK(a.basename() == "bar");
- TEST_CHECK(std::string(a.dirname()) == "/foo");
+ TEST_CHECK(stringify(a.dirname()) == "/foo");
TEST_CHECK(b.basename() == "cow");
- TEST_CHECK(std::string(b.dirname()) == "/moo/went/the");
+ TEST_CHECK(stringify(b.dirname()) == "/moo/went/the");
TEST_CHECK(c.basename() == "/");
- TEST_CHECK(std::string(c.dirname()) == "/");
+ TEST_CHECK(stringify(c.dirname()) == "/");
TEST_CHECK(d.basename() == ".");
- TEST_CHECK(std::string(d.dirname()) == ".");
+ TEST_CHECK(stringify(d.dirname()) == ".");
TEST_CHECK(e.basename() == "..");
- TEST_CHECK(std::string(e.dirname()) == "..");
+ TEST_CHECK(stringify(e.dirname()) == "..");
}
} test_fs_entry_dir_base_name;
}
diff --git a/paludis/vdb_repository.cc b/paludis/vdb_repository.cc
index 8253a5d..785b06d 100644
--- a/paludis/vdb_repository.cc
+++ b/paludis/vdb_repository.cc
@@ -291,10 +291,10 @@ VDBRepository::VDBRepository(const VDBRepositoryParams & p) :
Repository(RepositoryName("installed")),
PrivateImplementationPattern<VDBRepository>(new Implementation<VDBRepository>(p))
{
- _info.insert(std::make_pair(std::string("location"), _imp->location));
- _info.insert(std::make_pair(std::string("root"), _imp->root));
+ _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
+ _info.insert(std::make_pair(std::string("root"), stringify(_imp->root)));
_info.insert(std::make_pair(std::string("format"), std::string("vdb")));
- _info.insert(std::make_pair(std::string("world"), _imp->world_file));
+ _info.insert(std::make_pair(std::string("world"), stringify(_imp->world_file)));
}
VDBRepository::~VDBRepository()