aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-09-04 22:31:17 +0100
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2011-09-04 22:31:17 +0100
commitd775e85b9cbe3b384f9838628413eb2a60a8fa7e (patch)
tree62ba02282f5718decf858c323cc92ccaf75037e8
parent8331ad9a4b6a00eede51c15b1782cc6f14d2e4d0 (diff)
downloadpaludis-d775e85b9cbe3b384f9838628413eb2a60a8fa7e.tar.gz
paludis-d775e85b9cbe3b384f9838628413eb2a60a8fa7e.tar.xz
Refactor
-rw-r--r--paludis/repositories/e/e_installed_repository_id.cc11
-rw-r--r--paludis/repositories/e/e_installed_repository_id.hh3
-rw-r--r--paludis/repositories/e/e_key.cc113
-rw-r--r--paludis/repositories/e/e_key.hh18
-rw-r--r--paludis/repositories/e/exndbam_id.cc69
-rw-r--r--paludis/repositories/e/exndbam_id.hh4
-rw-r--r--paludis/repositories/e/vdb_id.cc72
-rw-r--r--paludis/repositories/e/vdb_id.hh4
8 files changed, 82 insertions, 212 deletions
diff --git a/paludis/repositories/e/e_installed_repository_id.cc b/paludis/repositories/e/e_installed_repository_id.cc
index a3a03b6..a40981b 100644
--- a/paludis/repositories/e/e_installed_repository_id.cc
+++ b/paludis/repositories/e/e_installed_repository_id.cc
@@ -89,7 +89,6 @@ namespace
std::shared_ptr<const MetadataSpecTreeKey<SimpleURISpecTree> > homepage;
std::shared_ptr<const MetadataValueKey<std::string> > short_description;
std::shared_ptr<const MetadataValueKey<std::string> > long_description;
- std::shared_ptr<const MetadataValueKey<std::shared_ptr<const Contents> > > contents;
std::shared_ptr<const MetadataTimeKey> installed_time;
std::shared_ptr<const MetadataCollectionKey<Set<std::string> > > from_repositories;
std::shared_ptr<const MetadataSpecTreeKey<SimpleURISpecTree> > upstream_changelog;
@@ -508,9 +507,6 @@ EInstalledRepositoryID::need_keys_added() const
add_metadata_key(_imp->keys->homepage);
}
- _imp->keys->contents = make_contents_key();
- add_metadata_key(_imp->keys->contents);
-
_imp->keys->installed_time = std::make_shared<EMTimeKey>("INSTALLED_TIME", "Installed time",
_imp->dir / contents_filename(), mkt_normal);
add_metadata_key(_imp->keys->installed_time);
@@ -860,13 +856,6 @@ EInstalledRepositoryID::long_description_key() const
return _imp->keys->long_description;
}
-const std::shared_ptr<const Contents>
-EInstalledRepositoryID::contents() const
-{
- need_keys_added();
- return _imp->keys->contents->parse_value();
-}
-
const std::shared_ptr<const MetadataTimeKey>
EInstalledRepositoryID::installed_time_key() const
{
diff --git a/paludis/repositories/e/e_installed_repository_id.hh b/paludis/repositories/e/e_installed_repository_id.hh
index 58000fc..3547148 100644
--- a/paludis/repositories/e/e_installed_repository_id.hh
+++ b/paludis/repositories/e/e_installed_repository_id.hh
@@ -99,7 +99,6 @@ namespace paludis
virtual std::string fs_location_raw_name() const = 0;
virtual std::string fs_location_human_name() const = 0;
virtual std::string contents_filename() const = 0;
- virtual std::shared_ptr<MetadataValueKey<std::shared_ptr<const Contents> > > make_contents_key() const = 0;
virtual const std::shared_ptr<const ChoiceValue> make_choice_value(
const std::shared_ptr<const Choice> &, const UnprefixedChoiceName &, const Tribool,
@@ -111,8 +110,6 @@ namespace paludis
virtual void can_drop_in_memory_cache() const;
virtual void set_scm_revision(const std::string &) const PALUDIS_ATTRIBUTE((noreturn));
-
- virtual const std::shared_ptr<const Contents> contents() const;
};
}
}
diff --git a/paludis/repositories/e/e_key.cc b/paludis/repositories/e/e_key.cc
index 6ae1e2b..51bf0e3 100644
--- a/paludis/repositories/e/e_key.cc
+++ b/paludis/repositories/e/e_key.cc
@@ -22,7 +22,6 @@
#include <paludis/repositories/e/dep_parser.hh>
#include <paludis/repositories/e/parse_uri_label.hh>
#include <paludis/repositories/e/eapi.hh>
-#include <paludis/repositories/e/vdb_contents_tokeniser.hh>
#include <paludis/repositories/e/e_repository.hh>
#include <paludis/repositories/e/myoption.hh>
#include <paludis/repositories/e/spec_tree_pretty_printer.hh>
@@ -30,7 +29,6 @@
#include <paludis/util/pretty_print.hh>
#include <paludis/util/pimp-impl.hh>
#include <paludis/util/stringify.hh>
-#include <paludis/util/tokeniser.hh>
#include <paludis/util/log.hh>
#include <paludis/util/join.hh>
#include <paludis/util/create_iterator-impl.hh>
@@ -54,8 +52,6 @@
#include <algorithm>
#include <functional>
-#include <list>
-#include <vector>
using namespace paludis;
using namespace paludis::erepository;
@@ -635,115 +631,6 @@ ERequiredUseKey::type() const
return _imp->type;
}
-namespace paludis
-{
- template <>
- struct Imp<EContentsKey>
- {
- const FSPath filename;
-
- const std::string raw_name;
- const std::string human_name;
- const MetadataKeyType type;
-
- Imp(const FSPath & v, const std::string & r, const std::string & h, const MetadataKeyType & t) :
- filename(v),
- raw_name(r),
- human_name(h),
- type(t)
- {
- }
- };
-}
-
-EContentsKey::EContentsKey(const std::string & r, const std::string & h, const FSPath & v, const MetadataKeyType t) :
- _imp(v, r, h, t)
-{
-}
-
-EContentsKey::~EContentsKey()
-{
-}
-
-const std::shared_ptr<const Contents>
-EContentsKey::parse_value() const
-{
- Context context("When creating contents from '" + stringify(_imp->filename) + "':");
-
- auto value(std::make_shared<Contents>());
-
- FSPath f(_imp->filename);
- if (! f.stat().is_regular_file_or_symlink_to_regular_file())
- {
- Log::get_instance()->message("e.contents.not_a_file", ll_warning, lc_context) << "Could not read CONTENTS file '" <<
- _imp->filename << "'";
- return value;
- }
-
- SafeIFStream ff(f);
-
- std::string line;
- unsigned line_number(0);
- while (std::getline(ff, line))
- {
- ++line_number;
-
- std::vector<std::string> tokens;
- if (! VDBContentsTokeniser::tokenise(line, std::back_inserter(tokens)))
- {
- Log::get_instance()->message("e.contents.broken", ll_warning, lc_context) << "CONTENTS has broken line '" <<
- line_number << "', skipping";
- continue;
- }
-
- if ("obj" == tokens.at(0))
- {
- std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsFileEntry>(FSPath(tokens.at(1))));
- e->add_metadata_key(std::make_shared<LiteralMetadataTimeKey>("mtime", "mtime", mkt_normal,
- Timestamp(destringify<time_t>(tokens.at(3)), 0)));
- e->add_metadata_key(std::make_shared<LiteralMetadataValueKey<std::string>>("md5", "md5", mkt_normal, tokens.at(2)));
- value->add(e);
- }
- else if ("dir" == tokens.at(0))
- {
- std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsDirEntry>(FSPath(tokens.at(1))));
- value->add(e);
- }
- else if ("sym" == tokens.at(0))
- {
- std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsSymEntry>(FSPath(tokens.at(1)), tokens.at(2)));
- e->add_metadata_key(std::make_shared<LiteralMetadataTimeKey>("mtime", "mtime", mkt_normal,
- Timestamp(destringify<time_t>(tokens.at(3)), 0)));
- value->add(e);
- }
- else if ("misc" == tokens.at(0) || "fif" == tokens.at(0) || "dev" == tokens.at(0))
- value->add(std::shared_ptr<ContentsEntry>(std::make_shared<ContentsOtherEntry>(FSPath(tokens.at(1)))));
- else
- Log::get_instance()->message("e.contents.unknown", ll_warning, lc_context) << "CONTENTS has unsupported entry type '" <<
- tokens.at(0) << "', skipping";
- }
-
- return value;
-}
-
-const std::string
-EContentsKey::raw_name() const
-{
- return _imp->raw_name;
-}
-
-const std::string
-EContentsKey::human_name() const
-{
- return _imp->human_name;
-}
-
-MetadataKeyType
-EContentsKey::type() const
-{
- return _imp->type;
-}
-
namespace
{
Timestamp get_mtime(const FSPath & v)
diff --git a/paludis/repositories/e/e_key.hh b/paludis/repositories/e/e_key.hh
index aa9bf7d..3e1022f 100644
--- a/paludis/repositories/e/e_key.hh
+++ b/paludis/repositories/e/e_key.hh
@@ -223,24 +223,6 @@ namespace paludis
const PrettyPrintOptions &) const PALUDIS_ATTRIBUTE((warn_unused_result));
};
- class EContentsKey :
- public MetadataValueKey<std::shared_ptr<const Contents> >
- {
- private:
- Pimp<EContentsKey> _imp;
-
- public:
- EContentsKey(const std::string &, const std::string &, const FSPath &, const MetadataKeyType);
- ~EContentsKey();
-
- const std::shared_ptr<const Contents> parse_value() const
- PALUDIS_ATTRIBUTE((warn_unused_result));
-
- virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
- virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result));
- virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result));
- };
-
class EMTimeKey :
public MetadataTimeKey
{
diff --git a/paludis/repositories/e/exndbam_id.cc b/paludis/repositories/e/exndbam_id.cc
index 21c530b..ab2b651 100644
--- a/paludis/repositories/e/exndbam_id.cc
+++ b/paludis/repositories/e/exndbam_id.cc
@@ -29,63 +29,6 @@
using namespace paludis;
using namespace paludis::erepository;
-namespace
-{
- class ExndbamContentsKey :
- public MetadataValueKey<std::shared_ptr<const Contents> >
- {
- private:
- const PackageID * const _id;
- const NDBAM * const _db;
- mutable Mutex _mutex;
- mutable std::shared_ptr<Contents> _v;
-
- public:
- ExndbamContentsKey(const PackageID * const i, const NDBAM * const d) :
- _id(i),
- _db(d)
- {
- }
-
- const std::shared_ptr<const Contents> parse_value() const
- {
- Lock l(_mutex);
- if (_v)
- return _v;
-
- using namespace std::placeholders;
- _v = std::make_shared<Contents>();
- _db->parse_contents(*_id,
- std::bind(&Contents::add, _v.get(), std::placeholders::_1),
- std::bind(&Contents::add, _v.get(), std::placeholders::_1),
- std::bind(&Contents::add, _v.get(), std::placeholders::_1)
- );
- return _v;
- }
-
- virtual const std::string raw_name() const PALUDIS_ATTRIBUTE((warn_unused_result))
- {
- return "contents";
- }
-
- virtual const std::string human_name() const PALUDIS_ATTRIBUTE((warn_unused_result))
- {
- return "Contents";
- }
-
- virtual MetadataKeyType type() const PALUDIS_ATTRIBUTE((warn_unused_result))
- {
- return mkt_internal;
- }
-
- virtual void invalidate() const
- {
- Lock l(_mutex);
- _v.reset();
- }
- };
-}
-
ExndbamID::ExndbamID(const QualifiedPackageName & q, const VersionSpec & v,
const Environment * const e,
const RepositoryName & r,
@@ -113,9 +56,15 @@ ExndbamID::contents_filename() const
return "contents";
}
-std::shared_ptr<MetadataValueKey<std::shared_ptr<const Contents> > >
-ExndbamID::make_contents_key() const
+const std::shared_ptr<const Contents>
+ExndbamID::contents() const
{
- return std::make_shared<ExndbamContentsKey>(this, _ndbam);
+ auto v(std::make_shared<Contents>());
+ _ndbam->parse_contents(*this,
+ std::bind(&Contents::add, v.get(), std::placeholders::_1),
+ std::bind(&Contents::add, v.get(), std::placeholders::_1),
+ std::bind(&Contents::add, v.get(), std::placeholders::_1)
+ );
+ return v;
}
diff --git a/paludis/repositories/e/exndbam_id.hh b/paludis/repositories/e/exndbam_id.hh
index 945c78a..f8cd076 100644
--- a/paludis/repositories/e/exndbam_id.hh
+++ b/paludis/repositories/e/exndbam_id.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2008, 2010 Ciaran McCreesh
+ * Copyright (c) 2008, 2010, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -43,7 +43,7 @@ namespace paludis
virtual std::string fs_location_raw_name() const;
virtual std::string fs_location_human_name() const;
virtual std::string contents_filename() const;
- virtual std::shared_ptr<MetadataValueKey<std::shared_ptr<const Contents> > > make_contents_key() const;
+ virtual const std::shared_ptr<const Contents> contents() const;
};
}
}
diff --git a/paludis/repositories/e/vdb_id.cc b/paludis/repositories/e/vdb_id.cc
index 79eb554..23efddb 100644
--- a/paludis/repositories/e/vdb_id.cc
+++ b/paludis/repositories/e/vdb_id.cc
@@ -19,7 +19,18 @@
#include <paludis/repositories/e/vdb_id.hh>
#include <paludis/repositories/e/e_key.hh>
+#include <paludis/repositories/e/vdb_contents_tokeniser.hh>
#include <paludis/util/fs_path.hh>
+#include <paludis/util/fs_stat.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/safe_ifstream.hh>
+#include <paludis/util/destringify.hh>
+#include <paludis/util/timestamp.hh>
+#include <paludis/contents.hh>
+#include <paludis/literal_metadata_key.hh>
+
+#include <vector>
using namespace paludis;
using namespace paludis::erepository;
@@ -50,9 +61,64 @@ VDBID::contents_filename() const
return "CONTENTS";
}
-std::shared_ptr<MetadataValueKey<std::shared_ptr<const Contents> > >
-VDBID::make_contents_key() const
+const std::shared_ptr<const Contents>
+VDBID::contents() const
{
- return std::make_shared<EContentsKey>("CONTENTS", "Contents", fs_location_key()->parse_value() / "CONTENTS", mkt_internal);
+ FSPath contents_location(fs_location_key()->parse_value() / "CONTENTS");
+ Context context("When creating contents from '" + stringify(contents_location) + "':");
+
+ auto value(std::make_shared<Contents>());
+
+ if (! contents_location.stat().is_regular_file_or_symlink_to_regular_file())
+ {
+ Log::get_instance()->message("e.contents.not_a_file", ll_warning, lc_context) << "Could not read CONTENTS file '" <<
+ contents_location << "'";
+ return value;
+ }
+
+ SafeIFStream ff(contents_location);
+
+ std::string line;
+ unsigned line_number(0);
+ while (std::getline(ff, line))
+ {
+ ++line_number;
+
+ std::vector<std::string> tokens;
+ if (! VDBContentsTokeniser::tokenise(line, std::back_inserter(tokens)))
+ {
+ Log::get_instance()->message("e.contents.broken", ll_warning, lc_context) << "CONTENTS has broken line '" <<
+ line_number << "', skipping";
+ continue;
+ }
+
+ if ("obj" == tokens.at(0))
+ {
+ std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsFileEntry>(FSPath(tokens.at(1))));
+ e->add_metadata_key(std::make_shared<LiteralMetadataTimeKey>("mtime", "mtime", mkt_normal,
+ Timestamp(destringify<time_t>(tokens.at(3)), 0)));
+ e->add_metadata_key(std::make_shared<LiteralMetadataValueKey<std::string>>("md5", "md5", mkt_normal, tokens.at(2)));
+ value->add(e);
+ }
+ else if ("dir" == tokens.at(0))
+ {
+ std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsDirEntry>(FSPath(tokens.at(1))));
+ value->add(e);
+ }
+ else if ("sym" == tokens.at(0))
+ {
+ std::shared_ptr<ContentsEntry> e(std::make_shared<ContentsSymEntry>(FSPath(tokens.at(1)), tokens.at(2)));
+ e->add_metadata_key(std::make_shared<LiteralMetadataTimeKey>("mtime", "mtime", mkt_normal,
+ Timestamp(destringify<time_t>(tokens.at(3)), 0)));
+ value->add(e);
+ }
+ else if ("misc" == tokens.at(0) || "fif" == tokens.at(0) || "dev" == tokens.at(0))
+ value->add(std::shared_ptr<ContentsEntry>(std::make_shared<ContentsOtherEntry>(FSPath(tokens.at(1)))));
+ else
+ Log::get_instance()->message("e.contents.unknown", ll_warning, lc_context) << "CONTENTS has unsupported entry type '" <<
+ tokens.at(0) << "', skipping";
+ }
+
+ return value;
}
diff --git a/paludis/repositories/e/vdb_id.hh b/paludis/repositories/e/vdb_id.hh
index 9032a6c..e2c191b 100644
--- a/paludis/repositories/e/vdb_id.hh
+++ b/paludis/repositories/e/vdb_id.hh
@@ -1,7 +1,7 @@
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
- * Copyright (c) 2007, 2008, 2010 Ciaran McCreesh
+ * Copyright (c) 2007, 2008, 2010, 2011 Ciaran McCreesh
*
* This file is part of the Paludis package manager. Paludis is free software;
* you can redistribute it and/or modify it under the terms of the GNU General
@@ -38,7 +38,7 @@ namespace paludis
virtual std::string fs_location_raw_name() const;
virtual std::string fs_location_human_name() const;
virtual std::string contents_filename() const;
- virtual std::shared_ptr<MetadataValueKey<std::shared_ptr<const Contents> > > make_contents_key() const;
+ virtual const std::shared_ptr<const Contents> contents() const;
};
}
}