aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-11 21:35:07 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-11 21:35:07 +0000
commit512b20f073a1bee3adf778106a512d2bfe4316ad (patch)
tree198b5832521e02c9713ef3b86fcf70223c392641
parentf94f31abf9d2e6937f69c1812fe0cb471eea9634 (diff)
downloadpaludis-512b20f073a1bee3adf778106a512d2bfe4316ad.tar.gz
paludis-512b20f073a1bee3adf778106a512d2bfe4316ad.tar.xz
Add a NothingRepository that supports sync= but does not contain any packages
-rw-r--r--doc/doc_main.doxygen5
-rw-r--r--paludis/files.m41
-rw-r--r--paludis/nothing_repository.cc255
-rw-r--r--paludis/nothing_repository.hh167
4 files changed, 428 insertions, 0 deletions
diff --git a/doc/doc_main.doxygen b/doc/doc_main.doxygen
index e224c2c..f2fbc6c 100644
--- a/doc/doc_main.doxygen
+++ b/doc/doc_main.doxygen
@@ -127,6 +127,11 @@
* \ingroup grprepository
*/
+/** \defgroup grpnothingrepository Nothing repository
+ *
+ * \ingroup grprepository
+ */
+
/** \defgroup grpvdbrepository VDB repository
*
* \ingroup grprepository
diff --git a/paludis/files.m4 b/paludis/files.m4
index 883def2..539aafa 100644
--- a/paludis/files.m4
+++ b/paludis/files.m4
@@ -26,6 +26,7 @@ add(`hashed_containers', `hh', `cc', `test')
add(`mask_reasons', `hh', `cc')
add(`match_package', `hh', `cc')
add(`name', `hh', `cc', `test')
+add(`nothing_repository', `hh', `cc')
add(`package_database', `hh', `cc', `test')
add(`package_database_entry', `hh')
add(`paludis', `hh', `cc')
diff --git a/paludis/nothing_repository.cc b/paludis/nothing_repository.cc
new file mode 100644
index 0000000..78e33bd
--- /dev/null
+++ b/paludis/nothing_repository.cc
@@ -0,0 +1,255 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "config.h"
+
+#include <paludis/nothing_repository.hh>
+#include <paludis/portage_dep_parser.hh>
+#include <paludis/syncer.hh>
+#include <paludis/util/dir_iterator.hh>
+#include <paludis/util/log.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/tokeniser.hh>
+
+/** \file
+ * Implementation of NothingRepository.
+ *
+ * \ingroup grpnothingrepository
+ */
+
+using namespace paludis;
+
+namespace paludis
+{
+ /**
+ * Implementation data for a NothingRepository.
+ *
+ * \ingroup grpnothingrepository
+ */
+ template <>
+ struct Implementation<NothingRepository> :
+ InternalCounted<Implementation<NothingRepository> >
+ {
+ /// Our name
+ std::string name;
+
+ /// Our location
+ FSEntry location;
+
+ /// Sync URL
+ std::string sync;
+
+ /// Sync exclude file
+ std::string sync_exclude;
+
+ /// (Empty) provides map.
+ const std::map<QualifiedPackageName, QualifiedPackageName> provide_map;
+
+ /// Constructor.
+ Implementation(const NothingRepositoryParams &);
+
+ /// Destructor.
+ ~Implementation();
+ };
+}
+
+Implementation<NothingRepository>::Implementation(const NothingRepositoryParams & p) :
+ name(p.get<nrpk_name>()),
+ location(p.get<nrpk_location>()),
+ sync(p.get<nrpk_sync>()),
+ sync_exclude(p.get<nrpk_sync_exclude>())
+{
+}
+
+Implementation<NothingRepository>::~Implementation()
+{
+}
+
+NothingRepository::NothingRepository(const NothingRepositoryParams & p) try :
+ Repository(RepositoryName(p.get<nrpk_name>()),
+ RepositoryCapabilities::create((
+ param<repo_mask>(static_cast<MaskInterface *>(0)),
+ param<repo_installable>(static_cast<InstallableInterface *>(0)),
+ param<repo_installed>(static_cast<InstalledInterface *>(0)),
+ param<repo_news>(static_cast<NewsInterface *>(0)),
+ param<repo_sets>(static_cast<SetsInterface *>(0)),
+ param<repo_syncable>(this),
+ param<repo_uninstallable>(static_cast<UninstallableInterface *>(0)),
+ param<repo_use>(static_cast<UseInterface *>(0)),
+ param<repo_world>(static_cast<WorldInterface *>(0))
+ ))),
+ PrivateImplementationPattern<NothingRepository>(new Implementation<NothingRepository>(p))
+{
+ if (! _imp->sync.empty())
+ _info.insert(std::make_pair(std::string("sync"), _imp->sync));
+ if (! _imp->sync_exclude.empty())
+ _info.insert(std::make_pair(std::string("sync_exclude"), _imp->sync_exclude));
+ _info.insert(std::make_pair(std::string("location"), stringify(_imp->location)));
+}
+catch (const NameError & e)
+{
+ Context context("When making Nothing repository '" + p.get<nrpk_name>() + "':");
+ throw NothingRepositoryConfigurationError("Caught NameError: " + e.message());
+}
+
+NothingRepository::~NothingRepository()
+{
+}
+
+bool
+NothingRepository::do_has_category_named(const CategoryNamePart &) const
+{
+ return false;
+}
+
+bool
+NothingRepository::do_has_package_named(const QualifiedPackageName &) const
+{
+ return false;
+}
+
+CategoryNamePartCollection::ConstPointer
+NothingRepository::do_category_names() const
+{
+ CategoryNamePartCollection::Pointer result(new CategoryNamePartCollection);
+ return result;
+}
+
+QualifiedPackageNameCollection::ConstPointer
+NothingRepository::do_package_names(const CategoryNamePart &) const
+{
+ QualifiedPackageNameCollection::Pointer result(new QualifiedPackageNameCollection);
+ return result;
+}
+
+VersionSpecCollection::ConstPointer
+NothingRepository::do_version_specs(const QualifiedPackageName &) const
+{
+ return VersionSpecCollection::Pointer(new VersionSpecCollection);
+}
+
+bool
+NothingRepository::do_has_version(const QualifiedPackageName &,
+ const VersionSpec &) const
+{
+ return false;
+}
+
+VersionMetadata::ConstPointer
+NothingRepository::do_version_metadata(
+ const QualifiedPackageName & q, const VersionSpec & v) const
+{
+ Log::get_instance()->message(ll_warning, "has_version failed for request for '" +
+ stringify(q) + "-" + stringify(v) + "' in repository '" +
+ stringify(name()) + "'");
+ return VersionMetadata::ConstPointer(new VersionMetadata::Ebuild(
+ PortageDepParser::parse_depend));
+}
+
+CountedPtr<Repository>
+NothingRepository::make_nothing_repository(
+ const Environment * const,
+ const PackageDatabase * const,
+ const std::map<std::string, std::string> & m)
+{
+ std::string repo_file(m.end() == m.find("repo_file") ? std::string("?") :
+ m.find("repo_file")->second);
+
+ Context context("When making Nothing repository from repo_file '" + repo_file + "':");
+
+ std::string location;
+ if (m.end() == m.find("location") || ((location = m.find("location")->second)).empty())
+ throw NothingRepositoryConfigurationError("Key 'location' not specified or empty");
+
+ std::string sync;
+ if (m.end() == m.find("sync") || ((sync = m.find("sync")->second)).empty())
+ ; // nothing
+
+ std::string name;
+ if (m.end() == m.find("name") || ((name = m.find("name")->second)).empty())
+ throw NothingRepositoryConfigurationError("Key 'name' not specified or empty in '"
+ + repo_file + "'");
+
+ std::string sync_exclude;
+ if (m.end() == m.find("sync_exclude") || ((sync_exclude = m.find("sync_exclude")->second)).empty())
+ ; // nothing
+
+ return CountedPtr<Repository>(new NothingRepository(NothingRepositoryParams::create((
+ param<nrpk_name>(name),
+ param<nrpk_location>(location),
+ param<nrpk_sync>(sync),
+ param<nrpk_sync_exclude>(sync_exclude)))));
+}
+
+NothingRepositoryConfigurationError::NothingRepositoryConfigurationError(
+ const std::string & msg) throw () :
+ ConfigurationError("Nothing repository configuration error: " + msg)
+{
+}
+
+bool
+NothingRepository::do_is_licence(const std::string &) const
+{
+ return false;
+}
+
+bool
+NothingRepository::do_is_mirror(const std::string &) const
+{
+ return false;
+}
+
+bool
+NothingRepository::do_sync() const
+{
+ Context context("When syncing repository '" + stringify(name()) + "':");
+
+ if (_imp->sync.empty())
+ return false;
+
+ std::string::size_type p(_imp->sync.find("://")), q(_imp->sync.find(":"));
+ if (std::string::npos == p)
+ throw NoSuchSyncerError(_imp->sync);
+
+ SyncOptions opts(_imp->sync_exclude);
+
+ SyncerMaker::get_instance()->find_maker(_imp->sync.substr(0, std::min(p, q)))(
+ stringify(_imp->location), _imp->sync.substr(q < p ? q + 1 : 0))->sync(opts);
+
+ return true;
+}
+
+void
+NothingRepository::invalidate() const
+{
+}
+
+Repository::ProvideMapIterator
+NothingRepository::begin_provide_map() const
+{
+ return _imp->provide_map.begin();
+}
+
+Repository::ProvideMapIterator
+NothingRepository::end_provide_map() const
+{
+ return _imp->provide_map.end();
+}
+
diff --git a/paludis/nothing_repository.hh b/paludis/nothing_repository.hh
new file mode 100644
index 0000000..b31fa74
--- /dev/null
+++ b/paludis/nothing_repository.hh
@@ -0,0 +1,167 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2006 Ciaran McCreesh <ciaran.mccreesh@blueyonder.co.uk>
+ *
+ * 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
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef PALUDIS_GUARD_PALUDIS_NOTHING_REPOSITORY_HH
+#define PALUDIS_GUARD_PALUDIS_NOTHING_REPOSITORY_HH 1
+
+#include <paludis/repository.hh>
+#include <paludis/util/private_implementation_pattern.hh>
+#include <paludis/util/smart_record.hh>
+
+/**
+ * Declarations for the NothingRepository class.
+ *
+ * \ingroup grpnothingrepository
+ */
+
+namespace paludis
+{
+ class PackageDatabase;
+ class FSEntry;
+
+ /**
+ * Keys for NothingRepositoryParams.
+ *
+ * \see NothingRepositoryParams
+ * \ingroup grpnothingrepository
+ */
+ enum NothingRepositoryParamsKeys
+ {
+ nrpk_name,
+ nrpk_location,
+ nrpk_sync,
+ nrpk_sync_exclude,
+ last_nrpk
+ };
+
+ /**
+ * Tag for NothingRepositoryParams.
+ *
+ * \see NothingRepositoryParams
+ * \ingroup grpnothingrepository
+ */
+ struct NothingRepositoryParamsTag :
+ SmartRecordTag<comparison_mode::NoComparisonTag, void>,
+ SmartRecordKeys<NothingRepositoryParamsKeys, last_nrpk>,
+ SmartRecordKey<nrpk_location, const FSEntry>,
+ SmartRecordKey<nrpk_name, const std::string>,
+ SmartRecordKey<nrpk_sync, const std::string>,
+ SmartRecordKey<nrpk_sync_exclude, const std::string>
+ {
+ };
+
+ /**
+ * Constructor parameters for NothingRepository.
+ *
+ * \see NothingRepository
+ * \ingroup grpnothingrepository
+ */
+ typedef MakeSmartRecord<NothingRepositoryParamsTag>::Type NothingRepositoryParams;
+
+ /**
+ * A NothingRepository is a Repository that has no content, but can be
+ * synced along with other repositories.
+ *
+ * \ingroup grpnothingrepository
+ */
+ class NothingRepository :
+ public Repository,
+ public Repository::SyncableInterface,
+ private PrivateImplementationPattern<NothingRepository>
+ {
+ protected:
+ virtual bool do_has_category_named(const CategoryNamePart &) const;
+
+ virtual bool do_has_package_named(const QualifiedPackageName &) const;
+
+ virtual CategoryNamePartCollection::ConstPointer do_category_names() const;
+
+ virtual QualifiedPackageNameCollection::ConstPointer do_package_names(
+ const CategoryNamePart &) const;
+
+ virtual VersionSpecCollection::ConstPointer do_version_specs(
+ const QualifiedPackageName &) const;
+
+ virtual bool do_has_version(const QualifiedPackageName &, const VersionSpec &) const;
+
+ virtual VersionMetadata::ConstPointer do_version_metadata(
+ const QualifiedPackageName &,
+ const VersionSpec &) const;
+
+ virtual bool do_is_licence(const std::string &) const;
+
+ virtual bool do_is_mirror(const std::string &) const;
+
+ virtual bool do_sync() const;
+
+ public:
+ /**
+ * Constructor.
+ */
+ NothingRepository(const NothingRepositoryParams &);
+
+ /**
+ * Virtual constructor.
+ */
+ static CountedPtr<Repository> make_nothing_repository(
+ const Environment * const env,
+ const PackageDatabase * const db,
+ const std::map<std::string, std::string> &);
+
+ /**
+ * Destructor.
+ */
+ ~NothingRepository();
+
+ virtual void invalidate() const;
+
+ virtual ProvideMapIterator begin_provide_map() const;
+
+ virtual ProvideMapIterator end_provide_map() const;
+
+ typedef CountedPtr<NothingRepository, count_policy::InternalCountTag> Pointer;
+ typedef CountedPtr<const NothingRepository, count_policy::InternalCountTag> ConstPointer;
+ };
+
+ /**
+ * Thrown if invalid parameters are provided for
+ * NothingRepository::make_nothing_repository.
+ *
+ * \ingroup grpexceptions
+ * \ingroup grpnothingrepository
+ */
+ class NothingRepositoryConfigurationError : public ConfigurationError
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ NothingRepositoryConfigurationError(const std::string & msg) throw ();
+ };
+
+ /**
+ * Register NothingRepository.
+ */
+ static const RepositoryMaker::RegisterMaker register_nothing_repository(
+ "nothing", &NothingRepository::make_nothing_repository);
+
+}
+
+
+#endif