aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-19 00:07:28 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-11-19 00:07:28 +0000
commitddf65604053759e2988195f8cb650cca7d596a79 (patch)
tree01c03567a345fe2a873bc87775473aa9dfc43c71
parenta7c0e279090afdb14dbc80510bd68a406bbbe5ab (diff)
downloadpaludis-ddf65604053759e2988195f8cb650cca7d596a79.tar.gz
paludis-ddf65604053759e2988195f8cb650cca7d596a79.tar.xz
Allow write_cache= for Portage format repositories
-rw-r--r--paludis/repositories/portage/ebuild_entries.cc32
-rw-r--r--paludis/repositories/portage/ebuild_flat_metadata_cache.cc56
-rw-r--r--paludis/repositories/portage/ebuild_flat_metadata_cache.hh4
-rw-r--r--paludis/repositories/portage/portage_repository.cc1
4 files changed, 85 insertions, 8 deletions
diff --git a/paludis/repositories/portage/ebuild_entries.cc b/paludis/repositories/portage/ebuild_entries.cc
index d1c77c9..fa1eab4 100644
--- a/paludis/repositories/portage/ebuild_entries.cc
+++ b/paludis/repositories/portage/ebuild_entries.cc
@@ -87,24 +87,41 @@ VersionMetadata::Pointer
EbuildEntries::generate_version_metadata(const QualifiedPackageName & q,
const VersionSpec & v) const
{
+ Context context("When generating version metadata for '" + stringify(q) + "-" + stringify(v) + "':");
+
VersionMetadata::Pointer result(new VersionMetadata::Ebuild(PortageDepParser::parse_depend));
FSEntry ebuild_file(_imp->params.location / stringify(q.category) /
stringify(q.package) / (stringify(q.package) + "-" + stringify(v) + ".ebuild"));
+ FSEntry cache_file(_imp->params.cache);
+ cache_file /= stringify(q.category);
+ cache_file /= stringify(q.package) + "-" + stringify(v);
+
+ FSEntry write_cache_file(_imp->params.write_cache);
+ write_cache_file /= stringify(q.category);
+ write_cache_file /= stringify(q.package) + "-" + stringify(v);
+
bool ok(false);
if (_imp->params.cache.basename() != "empty")
{
- FSEntry cache_file(_imp->params.cache);
- cache_file /= stringify(q.category);
- cache_file /= stringify(q.package) + "-" + stringify(v);
EbuildFlatMetadataCache metadata_cache(cache_file, ebuild_file, _imp->master_mtime,
- _imp->eclass_mtimes);
+ _imp->eclass_mtimes, false);
if (metadata_cache.load(result))
ok = true;
}
+ if ((! ok) && _imp->params.write_cache.basename() != "empty")
+ {
+ EbuildFlatMetadataCache write_metadata_cache(write_cache_file, ebuild_file, _imp->master_mtime,
+ _imp->eclass_mtimes, true);
+ if (write_metadata_cache.load(result))
+ ok = true;
+ else if (write_cache_file.exists())
+ write_cache_file.unlink();
+ }
+
if (! ok)
{
if (_imp->params.cache.basename() != "empty")
@@ -132,6 +149,13 @@ EbuildEntries::generate_version_metadata(const QualifiedPackageName & q,
if (0 == ((result = cmd.metadata())))
throw InternalError(PALUDIS_HERE, "cmd.metadata() is zero pointer???");
+
+ if (_imp->params.write_cache.basename() != "empty")
+ {
+ EbuildFlatMetadataCache metadata_cache(write_cache_file, ebuild_file, _imp->master_mtime,
+ _imp->eclass_mtimes, false);
+ metadata_cache.save(result);
+ }
}
return result;
diff --git a/paludis/repositories/portage/ebuild_flat_metadata_cache.cc b/paludis/repositories/portage/ebuild_flat_metadata_cache.cc
index b09c9ca..050a926 100644
--- a/paludis/repositories/portage/ebuild_flat_metadata_cache.cc
+++ b/paludis/repositories/portage/ebuild_flat_metadata_cache.cc
@@ -20,23 +20,28 @@
#include "ebuild_flat_metadata_cache.hh"
#include <paludis/util/log.hh>
#include <paludis/util/tokeniser.hh>
+#include <paludis/util/join.hh>
#include <fstream>
#include <set>
+#include <list>
using namespace paludis;
EbuildFlatMetadataCache::EbuildFlatMetadataCache(const FSEntry & f,
- const FSEntry & e, time_t t, EclassMtimes::ConstPointer m) :
+ const FSEntry & e, time_t t, EclassMtimes::ConstPointer m, bool s) :
_filename(f),
_ebuild(e),
_master_mtime(t),
- _eclass_mtimes(m)
+ _eclass_mtimes(m),
+ _silent(s)
{
}
bool
EbuildFlatMetadataCache::load(VersionMetadata::Pointer result)
{
+ Context context("When loading version metadata to '" + stringify(_filename) + "':");
+
std::ifstream cache(stringify(_filename).c_str());
std::string line;
@@ -88,9 +93,54 @@ EbuildFlatMetadataCache::load(VersionMetadata::Pointer result)
}
else
{
- Log::get_instance()->message(ll_warning, lc_no_context,
+ Log::get_instance()->message(_silent ? ll_debug : ll_warning, lc_no_context,
"Couldn't use the cache file at '" + stringify(_filename) + "'");
return false;
}
}
+namespace
+{
+ template <typename T_>
+ std::string normalise(const T_ & s)
+ {
+ std::list<std::string> tokens;
+ WhitespaceTokeniser::get_instance()->tokenise(stringify(s), std::back_inserter(tokens));
+ return join(tokens.begin(), tokens.end(), " ");
+ }
+}
+
+void
+EbuildFlatMetadataCache::save(VersionMetadata::ConstPointer v)
+{
+ Context context("When saving version metadata to '" + stringify(_filename) + "':");
+
+ _filename.dirname().mkdir();
+ std::ofstream cache(stringify(_filename).c_str());
+
+ if (cache)
+ {
+ cache << normalise(v->deps.build_depend_string) << std::endl;
+ cache << normalise(v->deps.run_depend_string) << std::endl;
+ cache << normalise(v->slot) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->src_uri) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->restrict_string) << std::endl;
+ cache << normalise(v->homepage) << std::endl;
+ cache << normalise(v->license_string) << std::endl;
+ cache << normalise(v->description) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->keywords) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->inherited) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->iuse) << std::endl;
+ cache << std::endl;
+ cache << normalise(v->deps.post_depend_string) << std::endl;
+ cache << normalise(v->get_ebuild_interface()->provide_string) << std::endl;
+ cache << normalise(v->eapi) << std::endl;
+ }
+ else
+ {
+ Log::get_instance()->message(ll_warning, lc_no_context,
+ "Couldn't write cache file to '" + stringify(_filename) + "'");
+ }
+
+}
+
diff --git a/paludis/repositories/portage/ebuild_flat_metadata_cache.hh b/paludis/repositories/portage/ebuild_flat_metadata_cache.hh
index b5107a7..a89733c 100644
--- a/paludis/repositories/portage/ebuild_flat_metadata_cache.hh
+++ b/paludis/repositories/portage/ebuild_flat_metadata_cache.hh
@@ -33,11 +33,13 @@ namespace paludis
const FSEntry & _ebuild;
time_t _master_mtime;
EclassMtimes::ConstPointer _eclass_mtimes;
+ bool _silent;
public:
EbuildFlatMetadataCache(const FSEntry &, const FSEntry &,
- time_t, EclassMtimes::ConstPointer);
+ time_t, EclassMtimes::ConstPointer, bool silent);
bool load(VersionMetadata::Pointer);
+ void save(VersionMetadata::ConstPointer);
};
}
diff --git a/paludis/repositories/portage/portage_repository.cc b/paludis/repositories/portage/portage_repository.cc
index a4db56f..ff438d4 100644
--- a/paludis/repositories/portage/portage_repository.cc
+++ b/paludis/repositories/portage/portage_repository.cc
@@ -254,6 +254,7 @@ PortageRepository::PortageRepository(const PortageRepositoryParams & p) :
config_info->add_kv("eclassdirs", join(_imp->params.eclassdirs->begin(),
_imp->params.eclassdirs->end(), " "));
config_info->add_kv("cache", stringify(_imp->params.cache));
+ config_info->add_kv("write_cache", stringify(_imp->params.write_cache));
config_info->add_kv("distdir", stringify(_imp->params.distdir));
config_info->add_kv("pkgdir", stringify(_imp->params.pkgdir));
config_info->add_kv("securitydir", stringify(_imp->params.securitydir));