/* vim: set sw=4 sts=4 et foldmethod=syntax : *//* * Copyright (c) 2005, 2006, 2007, 2008, 2009 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 * 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"fake_installed_repository.hh"#include<paludis/util/fs_entry.hh>#include<paludis/util/sequence.hh>#include<paludis/util/set.hh>#include<paludis/util/make_shared_ptr.hh>#include<paludis/util/make_named_values.hh>#include<paludis/util/wrapped_forward_iterator.hh>#include<paludis/package_id.hh>#include<paludis/metadata_key.hh>#include<paludis/environment.hh>#include<paludis/dep_spec_flattener.hh>#include<paludis/dep_spec.hh>#include<paludis/action.hh>#include<paludis/literal_metadata_key.hh>usingnamespacepaludis;namespacepaludis{template<>structImplementation<FakeInstalledRepository>{std::tr1::shared_ptr<constMetadataValueKey<std::string>>format_key;std::tr1::shared_ptr<constMetadataValueKey<FSEntry>>installed_root_key;constboolsupports_uninstall;Implementation(constbools):format_key(newLiteralMetadataValueKey<std::string>("format","format",mkt_significant,"installed_fake")),installed_root_key(newLiteralMetadataValueKey<FSEntry>("installed_root","installed_root",mkt_normal,FSEntry("/"))),supports_uninstall(s){}};}FakeInstalledRepository::FakeInstalledRepository(constEnvironment*conste,constRepositoryName&our_name,constboolsupports_uninstall):FakeRepositoryBase(e,our_name,make_named_values<RepositoryCapabilities>(value_for<n::destination_interface>(this),value_for<n::e_interface>(static_cast<RepositoryEInterface*>(0)),value_for<n::environment_variable_interface>(static_cast<RepositoryEnvironmentVariableInterface*>(0)),value_for<n::hook_interface>(static_cast<RepositoryHookInterface*>(0)),value_for<n::make_virtuals_interface>(static_cast<RepositoryMakeVirtualsInterface*>(0)),value_for<n::manifest_interface>(static_cast<RepositoryManifestInterface*>(0)),value_for<n::mirrors_interface>(static_cast<RepositoryMirrorsInterface*>(0)),value_for<n::provides_interface>(this),value_for<n::qa_interface>(static_cast<RepositoryQAInterface*>(0)),value_for<n::sets_interface>(this),value_for<n::syncable_interface>(static_cast<RepositorySyncableInterface*>(0)),value_for<n::virtuals_interface>(static_cast<RepositoryVirtualsInterface*>(0)))),PrivateImplementationPattern<FakeInstalledRepository>(newImplementation<FakeInstalledRepository>(supports_uninstall)),_imp(PrivateImplementationPattern<FakeInstalledRepository>::_imp){add_metadata_key(_imp->format_key);add_metadata_key(_imp->installed_root_key);}FakeInstalledRepository::~FakeInstalledRepository(){}boolFakeInstalledRepository::is_suitable_destination_for(constPackageID&)const{returntrue;}std::tr1::shared_ptr<constFakeInstalledRepository::ProvidesSequence>FakeInstalledRepository::provided_packages()const{std::tr1::shared_ptr<ProvidesSequence>result(newProvidesSequence);std::tr1::shared_ptr<constCategoryNamePartSet>cats(category_names());for(CategoryNamePartSet::ConstIteratorc(cats->begin()),c_end(cats->end());c!=c_end;++c){std::tr1::shared_ptr<constQualifiedPackageNameSet>pkgs(package_names(*c));for(QualifiedPackageNameSet::ConstIteratorp(pkgs->begin()),p_end(pkgs->end());p!=p_end;++p){std::tr1::shared_ptr<constPackageIDSequence>vers(package_ids(*p));for(PackageIDSequence::ConstIteratorv(vers->begin()),v_end(vers->end());v!=v_end;++v){if(!(*v)->provide_key())continue;DepSpecFlattener<ProvideSpecTree,PackageDepSpec>f(environment());(*v)->provide_key()->value()->root()->accept(f);for(DepSpecFlattener<ProvideSpecTree,PackageDepSpec>::ConstIteratorq(f.begin()),q_end(f.end());q!=q_end;++q)result->push_back(make_named_values<RepositoryProvidesEntry>(value_for<n::provided_by>(*v),value_for<n::virtual_name>(QualifiedPackageName((*q)->text()))));}}}returnresult;}boolFakeInstalledRepository::is_default_destination()const{returnenvironment()->root()==installed_root_key()->value();}boolFakeInstalledRepository::want_pre_post_phases()const{returntrue;}voidFakeInstalledRepository::merge(constMergeParams&){}namespace{structSupportsActionQuery{constboolsupports_uninstall;SupportsActionQuery(constbools):supports_uninstall(s){}boolvisit(constSupportsActionTest<InstalledAction>&)const{returntrue;}boolvisit(constSupportsActionTest<InstallAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<ConfigAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<PretendAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<FetchAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<PretendFetchAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<InfoAction>&)const{returnfalse;}boolvisit(constSupportsActionTest<UninstallAction>&)const{returnsupports_uninstall;}};}boolFakeInstalledRepository::some_ids_might_support_action(constSupportsActionTestBase&a)const{SupportsActionQueryq(_imp->supports_uninstall);returna.accept_returning<bool>(q);}conststd::tr1::shared_ptr<constMetadataValueKey<std::string>>FakeInstalledRepository::format_key()const{return_imp->format_key;}conststd::tr1::shared_ptr<constMetadataValueKey<FSEntry>>FakeInstalledRepository::location_key()const{returnstd::tr1::shared_ptr<constMetadataValueKey<FSEntry>>();}conststd::tr1::shared_ptr<constMetadataValueKey<FSEntry>>FakeInstalledRepository::installed_root_key()const{return_imp->installed_root_key;}RepositoryNameFakeInstalledRepository::repository_factory_name(constEnvironment*const,conststd::tr1::function<std::string(conststd::string&)>&f){returnRepositoryName(f("name"));}std::tr1::shared_ptr<Repository>FakeInstalledRepository::repository_factory_create(Environment*constenv,conststd::tr1::function<std::string(conststd::string&)>&f){Contextcontext("When creating FakeInstalledRepository:");RepositoryNamename(f("name"));returnmake_shared_ptr(newFakeInstalledRepository(env,name));}std::tr1::shared_ptr<constRepositoryNameSet>FakeInstalledRepository::repository_factory_dependencies(constEnvironment*const,conststd::tr1::function<std::string(conststd::string&)>&){returnmake_shared_ptr(newRepositoryNameSet);}