From: Duncan Mac-Vicar P Date: Wed, 6 Jun 2007 14:41:23 +0000 (+0000) Subject: zypper port starts. zypp2 to zypp X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~653 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e9ef94d21eebae701d05a88d17cddfff36de31e3;p=platform%2Fupstream%2Flibzypp.git zypper port starts. zypp2 to zypp --- diff --git a/zypp2/RepoInfo.cc b/zypp2/RepoInfo.cc deleted file mode 100644 index a26bbb8..0000000 --- a/zypp2/RepoInfo.cc +++ /dev/null @@ -1,189 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/RepoInfo.cc - * -*/ -#include -#include "zypp/base/Logger.h" - -#include "zypp2/RepoInfo.h" - -using namespace std; -using namespace boost; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoInfo::Impl - // - /** RepoInfo implementation. */ - struct RepoInfo::Impl - { - - Impl() - : enabled (indeterminate), - autorefresh(indeterminate), - type(repo::RepoType::NONE_e) - {} - - ~Impl() - { - //MIL << std::endl; - } - public: - boost::tribool enabled; - boost::tribool autorefresh; - repo::RepoType type; - Url mirrorlist_url; - std::set urls; - std::string alias; - std::string name; - - public: - - private: - friend Impl * rwcowClone( const Impl * rhs ); - /** clone for RWCOW_pointer */ - Impl * clone() const - { return new Impl( *this ); } - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoInfo::Impl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj ) - { - return str << "RepoInfo::Impl"; - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoInfo - // - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : RepoInfo::RepoInfo - // METHOD TYPE : Ctor - // - RepoInfo::RepoInfo() - : _pimpl( new Impl() ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : RepoInfo::~RepoInfo - // METHOD TYPE : Dtor - // - RepoInfo::~RepoInfo() - { - //MIL << std::endl; - } - - - - RepoInfo & RepoInfo::setEnabled( boost::tribool enabled ) - { - _pimpl->enabled = enabled; - return *this; - } - - RepoInfo & RepoInfo::setAutorefresh( boost::tribool autorefresh ) - { - _pimpl->autorefresh = autorefresh; - return *this; - } - - RepoInfo & RepoInfo::setMirrorListUrl( const Url &url ) - { - _pimpl->mirrorlist_url = url; - return *this; - } - - RepoInfo & RepoInfo::addBaseUrl( const Url &url ) - { - _pimpl->urls.insert(url); - return *this; - } - - RepoInfo & RepoInfo::setAlias( const std::string &alias ) - { - _pimpl->alias = alias; - return *this; - } - - RepoInfo & RepoInfo::setType( const repo::RepoType &t ) - { - _pimpl->type = t; - return *this; - } - - RepoInfo & RepoInfo::setName( const std::string &name ) - { - _pimpl->name = name; - return *this; - } - - tribool RepoInfo::enabled() const - { return _pimpl->enabled; } - - tribool RepoInfo::autorefresh() const - { return _pimpl->autorefresh; } - - std::string RepoInfo::alias() const - { return _pimpl->alias; } - - std::string RepoInfo::name() const - { return _pimpl->name; } - - repo::RepoType RepoInfo::type() const - { return _pimpl->type; } - - Url RepoInfo::mirrorListUrl() const - { return _pimpl->mirrorlist_url; } - - std::set RepoInfo::urls() const - { return _pimpl->urls; } - - RepoInfo::urls_const_iterator RepoInfo::urlsBegin() const - { return _pimpl->urls.begin(); } - - RepoInfo::urls_const_iterator RepoInfo::urlsEnd() const - { return _pimpl->urls.end(); } - - std::ostream & RepoInfo::dumpOn( std::ostream & str ) const - { - str << "--------------------------------------" << std::endl; - str << "- alias : " << alias() << std::endl; - std::set url_set(urls()); - for ( std::set::const_iterator it = url_set.begin(); - it != url_set.end(); - ++it ) - { - str << "- url : " << *it << std::endl; - } - - str << "- type : " << type() << std::endl; - str << "- enabled : " << enabled() << std::endl; - str << "- autorefresh : " << autorefresh() << std::endl; - //str << "- path : " << path() << std::endl; - return str; - } - - std::ostream & operator<<( std::ostream & str, const RepoInfo & obj ) - { - return obj.dumpOn(str); - } - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// diff --git a/zypp2/RepoInfo.h b/zypp2/RepoInfo.h deleted file mode 100644 index b1a7b27..0000000 --- a/zypp2/RepoInfo.h +++ /dev/null @@ -1,199 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp2/RepoInfo.h - * -*/ -#ifndef ZYPP2_REPOSITORYINFO_H -#define ZYPP2_REPOSITORYINFO_H - -#include -#include -#include -#include "zypp/base/PtrTypes.h" - -#include -#include "zypp/Pathname.h" -#include "zypp/Url.h" -#include "zypp2/repo/RepoType.h" - - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoInfo - // - /** - * \short What is known about a repository - * - * The class RepoInfo represents everything that - * is known about a software repository. - * - * It can be used to store information about known - * sources. - * - * This class tries to be compatible with the - * concept of a .repo file used by YUM and - * also available in the openSUSE build service. - * - * Example file - * - * \code - * [ruby] - * name=Ruby repository (openSUSE_10.2) - * type=rpm-md - * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/ - * gpgcheck=1 - * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc - * enabled=1 - * \endcode - * - * \note A Repository info is a hint about how - * to create a repository. - */ - class RepoInfo - { - friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj ); - - public: - RepoInfo(); - ~RepoInfo(); - //RepoInfo( const Url & url, const Pathname & path, const std::string & alias = "", boost::tribool autorefresh = boost::indeterminate ); - - /** - * unique identifier for this source. If not specified - * It should be generated from the base url. - * - * Normally, in a .repo file the section name is used - * ( [somerepo] ) - */ - std::string alias() const; - - /** - * The base Url is the Url of the repository that generates - * the authoritative metadata this repository provides. - * - * For example for the url http://updates.novell.com/10.2 - * the base url is http://updates.novell.com/10.2. - * For the url http://host.com/mirror/update.novell.com/10.2 - * the base url is http://updates.novell.com/10.2 - * - * This can't be empty in order the repository to be valid - * unless the download of the mirror list succeeds and it - * contains a valid url. - */ - std::set urls() const; - - /** - * Url of a file which contains a list of Urls - * If empty, the base url will be used. - */ - Url mirrorListUrl() const; - - typedef std::set::const_iterator urls_const_iterator; - - /** - * iterator that points at begin of repository urls - */ - urls_const_iterator urlsBegin() const; - - /** - * iterator that points at end of repository urls - */ - urls_const_iterator urlsEnd() const; - - /** - * If enabled is false, then this repository must be ignored as if does - * not exists, except when checking for duplicate alias. - */ - boost::tribool enabled() const; - - /** - * If true, the repostory must be refreshed before creating resolvables - * from it - */ - boost::tribool autorefresh() const; - - /** - * Type of repository, - * - */ - repo::RepoType type() const; - - /** - * \short Repository short label - * - * Short label or description of the repository, to be used on - * the user interface. - * ie: "SUSE Linux 10.2 updates" - */ - std::string name() const; - - /** - * Add a base url. \see baseUrl - * \param url The base url for the repository. - */ - RepoInfo & addBaseUrl( const Url &url ); - - /** - * Set mirror list url. \see mirrorListUrl - * \param url The base url for the list - */ - RepoInfo & setMirrorListUrl( const Url &url ); - - /** - * enable or disable the repository \see enabled - * \param enabled - */ - RepoInfo & setEnabled( boost::tribool enabled ); - - /** - * enable or disable autorefresh \see autorefresh - * \param enabled - */ - RepoInfo & setAutorefresh( boost::tribool autorefresh ); - - /** - * set the repository alias \see alias - * \param alias - */ - RepoInfo & setAlias( const std::string &alias ); - - /** - * set the repository type \see type - * \param t - */ - RepoInfo & setType( const repo::RepoType &t ); - - /** - * set the repository name \see name - * \param name - */ - RepoInfo & setName( const std::string &name ); - - std::ostream & dumpOn( std::ostream & str ) const; - - class Impl; - private: - /** Pointer to implementation */ - RWCOW_pointer _pimpl; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoInfo Stream output */ - std::ostream & operator<<( std::ostream & str, const RepoInfo & obj ); - - typedef std::list RepoInfoList; - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// -#endif // ZYPP2_REPOSITORYINFO_H diff --git a/zypp2/RepoManager.cc b/zypp2/RepoManager.cc deleted file mode 100644 index f797e37..0000000 --- a/zypp2/RepoManager.cc +++ /dev/null @@ -1,402 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/RepoManager.cc - * -*/ - -#include -#include -#include -#include "zypp/base/InputStream.h" -#include "zypp/base/Logger.h" -#include "zypp/base/Function.h" -#include "zypp/PathInfo.h" -#include "zypp/TmpPath.h" - -#include "zypp2/repo/RepoException.h" -#include "zypp2/RepoManager.h" - -#include "zypp2/cache/CacheStore.h" -#include "zypp2/repo/cached/RepoImpl.h" -#include "zypp/MediaSetAccess.h" - -#include "zypp2/parser/RepoFileReader.h" -#include "zypp/source/yum/YUMDownloader.h" -#include "zypp/parser/yum/RepoParser.h" - -#include "zypp/source/susetags/SUSETagsDownloader.h" -#include "zypp2/parser/susetags/RepoParser.h" - -using namespace std; -using namespace zypp; -using namespace zypp::repo; -using namespace zypp::filesystem; - -using zypp::source::yum::YUMDownloader; -using zypp::source::susetags::SUSETagsDownloader; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoManagerOptions - // - /////////////////////////////////////////////////////////////////// - - RepoManagerOptions::RepoManagerOptions() - { - ZConfig globalConfig; - repoCachePath = globalConfig.defaultRepoCachePath(); - repoRawCachePath = globalConfig.defaultRepoRawCachePath(); - knownReposPath = globalConfig.defaultKnownReposPath(); - } - - /** - * \short Simple callback to collect the results - */ - struct RepoCollector - { - RepoCollector() - { - MIL << endl; - } - - ~RepoCollector() - { - MIL << endl; - } - - bool collect( const RepoInfo &repo ) - { - //MIL << "here in collector: " << repo.alias() << endl; - repos.push_back(repo); - //MIL << "added: " << repo.alias() << endl; - return true; - } - - RepoInfoList repos; - }; - - //////////////////////////////////////////////////////////////////////////// - - /** - * \short List of RepoInfo's from a directory - * - * Goes trough every file in a directory and adds all - * RepoInfo's contained in that file. - * - * \param file pathname of the file to read. - */ - static std::list repositories_in_path( const Pathname &dir ) - { - MIL << " " << dir << endl; - RepoCollector collector; - std::list repos; - list entries; - if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 ) - ZYPP_THROW(Exception("failed to read directory")); - - for ( list::const_iterator it = entries.begin(); it != entries.end(); ++it ) - { - Pathname file = *it; - parser::RepoFileReader parser( file, bind( &RepoCollector::collect, &collector, _1 ) ); - - //std::copy( collector.repos.begin(), collector.repos.end(), std::back_inserter(repos)); - //MIL << "ok" << endl; - } - return collector.repos; - } - - //////////////////////////////////////////////////////////////////////////// - - static void assert_alias( const RepoInfo &info ) - { - if (info.alias().empty()) - ZYPP_THROW(RepoNoAliasException()); - } - - //////////////////////////////////////////////////////////////////////////// - - static void assert_urls( const RepoInfo &info ) - { - if (info.urls().empty()) - ZYPP_THROW(RepoNoUrlException()); - } - - //////////////////////////////////////////////////////////////////////////// - - /** - * \short Calculates the raw cache path for a repository - */ - static Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info ) - { - assert_alias(info); - return opt.repoRawCachePath + info.alias(); - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoManager::Impl - // - /////////////////////////////////////////////////////////////////// - - /** - * \short RepoManager implementation. - */ - struct RepoManager::Impl - { - Impl( const RepoManagerOptions &opt ) - : options(opt) - { - - } - - Impl() - { - - } - - RepoManagerOptions options; - - public: - /** Offer default Impl. */ - static shared_ptr nullimpl() - { - static shared_ptr _nullimpl( new Impl ); - return _nullimpl; - } - - private: - friend Impl * rwcowClone( const Impl * rhs ); - /** clone for RWCOW_pointer */ - Impl * clone() const - { return new Impl( *this ); } - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoManager::Impl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const RepoManager::Impl & obj ) - { - return str << "RepoManager::Impl"; - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoManager - // - /////////////////////////////////////////////////////////////////// - - RepoManager::RepoManager( const RepoManagerOptions &opt ) - : _pimpl( new Impl(opt) ) - {} - - //////////////////////////////////////////////////////////////////////////// - - RepoManager::~RepoManager() - {} - - //////////////////////////////////////////////////////////////////////////// - - std::list RepoManager::knownRepositories() const - { - MIL << endl; - return repositories_in_path("/etc/zypp/repos.d"); - MIL << endl; - } - - //////////////////////////////////////////////////////////////////////////// - - void RepoManager::refreshMetadata( const RepoInfo &info ) - { - assert_alias(info); - assert_urls(info); - - // try urls one by one - for ( RepoInfo::urls_const_iterator it = info.urlsBegin(); it != info.urlsEnd(); ++it ) - { - Url url(*it); - filesystem::TmpDir tmpdir; - - repo::RepoType repokind = info.type(); - - // if the type is unknown, try probing. - switch ( repokind.toEnum() ) - { - case RepoType::NONE_e: - // unknown, probe it - repokind = probe(*it); - break; - default: - break; - } - - switch ( repokind.toEnum() ) - { - case RepoType::RPMMD_e : - { - YUMDownloader downloader( url, "/" ); - downloader.download(tmpdir.path()); - // no error - } - break; - case RepoType::YAST2_e : - { - SUSETagsDownloader downloader( url, "/" ); - downloader.download(tmpdir.path()); - // no error - } - break; - default: - ZYPP_THROW(RepoUnknownTypeException()); - } - - // ok we have the metadata, now exchange - // the contents - Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info); - TmpDir oldmetadata; - filesystem::assert_dir(rawpath); - filesystem::rename( rawpath, oldmetadata.path() ); - // move the just downloaded there - filesystem::rename( tmpdir.path(), rawpath ); - - // we are done. - } - } - - //////////////////////////////////////////////////////////////////////////// - - void RepoManager::cleanMetadata( const RepoInfo &info ) - { - filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_pimpl->options, info)); - } - - //////////////////////////////////////////////////////////////////////////// - - void RepoManager::buildCache( const RepoInfo &info ) - { - assert_alias(info); - Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info); - - cache::CacheStore store(_pimpl->options.repoCachePath); - - if ( store.isCached( info.alias() ) ) - { - MIL << info.alias() << " is already cached, cleaning..." << endl; - data::RecordId id = store.lookupRepository(info.alias()); - store.cleanRepository(id); - } - - data::RecordId id = store.lookupOrAppendRepository(info.alias()); - - // do we have type? - repo::RepoType repokind = info.type(); - - // if the type is unknown, try probing. - switch ( repokind.toEnum() ) - { - case RepoType::NONE_e: - // unknown, probe the local metadata - repokind = probe(Url(rawpath.asString())); - break; - default: - break; - } - - switch ( repokind.toEnum() ) - { - case RepoType::RPMMD_e : - { - parser::yum::RepoParser parser(id, store); - parser.parse(rawpath); - // no error - } - break; - case RepoType::YAST2_e : - { - parser::susetags::RepoParser parser(id, store); - parser.parse(rawpath); - // no error - } - break; - default: - ZYPP_THROW(RepoUnknownTypeException()); - } - - MIL << "Commit cache.." << endl; - store.commit(); - } - - //////////////////////////////////////////////////////////////////////////// - - repo::RepoType RepoManager::probe( const Url &url ) - { - MediaSetAccess access(url); - if ( access.doesFileExist("/repodata/repomd.xml") ) - return repo::RepoType::RPMMD; - if ( access.doesFileExist("/content") ) - return repo::RepoType::YAST2; - - return repo::RepoType("UNKNOWN"); - } - - //////////////////////////////////////////////////////////////////////////// - - void RepoManager::cleanCache( const RepoInfo &info ) - { - cache::CacheStore store(_pimpl->options.repoCachePath); - - data::RecordId id = store.lookupRepository(info.alias()); - store.cleanRepository(id); - store.commit(); - } - - //////////////////////////////////////////////////////////////////////////// - - bool RepoManager::isCached( const RepoInfo &info ) const - { - cache::CacheStore store(_pimpl->options.repoCachePath); - return store.isCached(info.alias()); - } - - Repository RepoManager::createFromCache( const RepoInfo &info ) - { - cache::CacheStore store(_pimpl->options.repoCachePath); - - if ( ! store.isCached( info.alias() ) ) - ZYPP_THROW(RepoNotCachedException()); - - MIL << "Repository " << info.alias() << " is cached" << endl; - - data::RecordId id = store.lookupRepository(info.alias()); - repo::cached::RepoImpl::Ptr repoimpl = - new repo::cached::RepoImpl( info, _pimpl->options.repoCachePath, id ); - // read the resolvables from cache - repoimpl->createResolvables(); - return Repository(repoimpl); - } - - //////////////////////////////////////////////////////////////////////////// - - void RepoManager::addRepository( const RepoInfo &info ) - { - - } - - //////////////////////////////////////////////////////////////////////////// - - std::ostream & operator<<( std::ostream & str, const RepoManager & obj ) - { - return str << *obj._pimpl; - } - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// diff --git a/zypp2/RepoManager.h b/zypp2/RepoManager.h deleted file mode 100644 index 3a5eef7..0000000 --- a/zypp2/RepoManager.h +++ /dev/null @@ -1,177 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/RepoManager.h - * -*/ -#ifndef ZYPP_REPOMANAGER_H -#define ZYPP_REPOMANAGER_H - -#include -#include - -#include "zypp/base/PtrTypes.h" -//#include "zypp/base/ReferenceCounted.h" -//#include "zypp/base/NonCopyable.h" -#include "zypp/Pathname.h" -#include "zypp/ZConfig.h" -#include "zypp2/Repository.h" -#include "zypp2/RepoInfo.h" -#include "zypp2/repo/RepoException.h" -#include "zypp2/repo/RepoType.h" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /** - * Repo manager settings. - * Settings default to ZYpp global settings. - */ - struct RepoManagerOptions - { - RepoManagerOptions(); - - Pathname repoCachePath; - Pathname repoRawCachePath; - Pathname knownReposPath; - }; - - /** - * \short creates and provides information about known sources. - * - */ - class RepoManager - { - friend std::ostream & operator<<( std::ostream & str, const RepoManager & obj ); - - public: - /** Implementation */ - class Impl; - - public: - RepoManager( const RepoManagerOptions &options = RepoManagerOptions() ); - /** Dtor */ - ~RepoManager(); - - /** - * \short List known repositories. - * - * The known repositories are read from - * \ref RepoManagerOptions::knownReposPath passed on the Ctor. - * Which defaults to ZYpp global settings. - * - */ - std::list knownRepositories() const; - - /** - * \short Refresh local cache - * - * Will try to download the metadata - * - * In case of falure the metadata remains - * as it was before. - * - * \throws RepoNoUrlException if no urls are available. - * \throws RepoNoAliasException if can't figure an alias - * \throws RepoUnknownTypeException if the metadata is unknown - * \throws Exception on unknown error. - */ - void refreshMetadata( const RepoInfo &info ); - - /** - * \short Clean local metadata - * - * Empty local metadata. - * - * \throws RepoNoAlias if can't figure an alias - * \throws Exception on unknown error. - */ - void cleanMetadata( const RepoInfo &info ); - - /** - * \short Refresh local cache - * - * Will try to build the cache from - * local metadata. - * - * If the cache exists it will be overwriten. - * - * \note the local metadata must be valid. - * - * \throws RepoNoAlias if can't figure an alias to look in cache - * \throws Exception on unknown error. - */ - void buildCache( const RepoInfo &info ); - - /** - * \short clean local cache - * - * Clean the cached version of the metadata - * - * \note the local metadata must be valid. - * - * \throws RepoNoAlias if can't figure an alias to look in cache - * \throws Exception on unknown error. - */ - void cleanCache( const RepoInfo &info ); - - /** - * \short Wether a repository exists in cache - * - * \param RepoInfo to be checked. - */ - bool isCached( const RepoInfo &info ) const; - - /** - * \short Create a repository object from the cache data - * - * \throw RepoNotCachedException When the source is not cached. - */ - Repository createFromCache( const RepoInfo &info ); - - /** - * \short Probe repo metadata type. - * - * \todo FIXME Should this be private? - */ - repo::RepoType probe( const Url &url ); - - - /** - * \short Adds a repository to the list of known repositories. - * - * - * - * \throws RepoAlreadyExistsException If the repo clash some - * unique attribute like alias - */ - void addRepository( const RepoInfo &info ); - - /** - * Adds a .repo file directly, which can contain - * one or more repositories. - */ - //void addRepositories( const Url &url ); - - - public: - - private: - /** Pointer to implementation */ - RWCOW_pointer _pimpl; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoManager Stream output */ - std::ostream & operator<<( std::ostream & str, const RepoManager & obj ); - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// -#endif // ZYPP2_REPOMANAGER_H diff --git a/zypp2/RepoStatus.cc b/zypp2/RepoStatus.cc deleted file mode 100644 index d9b0e25..0000000 --- a/zypp2/RepoStatus.cc +++ /dev/null @@ -1,110 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp2/RepoStatus.cc - * -*/ -#include -//#include "zypp/base/Logger.h" -#include "zypp2/RepoStatus.h" - - -using namespace std; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoStatus::Impl - // - /** RepoStatus implementation. */ - struct RepoStatus::Impl - { - - public: - - string checksum; - Date timestamp; - - /** Offer default Impl. */ - static shared_ptr nullimpl() - { - static shared_ptr _nullimpl( new Impl ); - return _nullimpl; - } - - private: - friend Impl * rwcowClone( const Impl * rhs ); - /** clone for RWCOW_pointer */ - Impl * clone() const - { return new Impl( *this ); } - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoStatus::Impl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const RepoStatus::Impl & obj ) - { - return str << "RepoStatus::Impl"; - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoStatus - // - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : RepoStatus::RepoStatus - // METHOD TYPE : Ctor - // - RepoStatus::RepoStatus() - : _pimpl( Impl::nullimpl() ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : RepoStatus::~RepoStatus - // METHOD TYPE : Dtor - // - RepoStatus::~RepoStatus() - {} - - RepoStatus & RepoStatus::setChecksum( const string &checksum ) - { - _pimpl->checksum = checksum; - return *this; - } - - RepoStatus & RepoStatus::setTimestamp( const Date ×tamp ) - { - _pimpl->timestamp = timestamp; - return *this; - } - - string RepoStatus::checksum() const - { return _pimpl->checksum; } - - Date RepoStatus::timestamp() const - { return _pimpl->timestamp; } - - /****************************************************************** - ** - ** FUNCTION NAME : operator<< - ** FUNCTION TYPE : std::ostream & - */ - std::ostream & operator<<( std::ostream & str, const RepoStatus & obj ) - { - return str << *obj._pimpl; - } - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// diff --git a/zypp2/RepoStatus.h b/zypp2/RepoStatus.h deleted file mode 100644 index eb92a36..0000000 --- a/zypp2/RepoStatus.h +++ /dev/null @@ -1,93 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/RepoStatus.h - * -*/ -#ifndef ZYPP2_REPOSTATUS_H -#define ZYPP2_REPOSTATUS_H - -#include -#include "zypp/base/PtrTypes.h" -#include "zypp/CheckSum.h" -#include "zypp/Date.h" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : RepoStatus - // - /** - * \short Local facts about a repository - * This class represents the status of a - * repository on the system. - * - * Anything that is not provided on the metadata - * files, like the timestamp of the downloaded - * metadata, and its checksum. - */ - class RepoStatus - { - friend std::ostream & operator<<( std::ostream & str, const RepoStatus & obj ); - - public: - - /** - * Checksum of the repository. - * Usually the checksum of the index, but any - * checksum that changes when the repository changes - * in any way is sufficient. - */ - std::string checksum() const; - - /** - * timestamp of the repository. If the repository - * changes, it has to be updated as well with the - * new timestamp. - */ - Date timestamp() const; - - /** - * set the repository checksum \see checksum - * \param checksum - */ - RepoStatus & setChecksum( const std::string &checksum ); - - /** - * set the repository timestamp \see timestamp - * \param timestamp - */ - RepoStatus & setTimestamp( const Date ×tamp ); - - /** Implementation */ - class Impl; - - public: - /** Default ctor */ - RepoStatus(); - /** Dtor */ - ~RepoStatus(); - - public: - - private: - /** Pointer to implementation */ - RWCOW_pointer _pimpl; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates RepoStatus Stream output */ - std::ostream & operator<<( std::ostream & str, const RepoStatus & obj ); - - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// -#endif // ZYPP2_REPOSTATUS_H diff --git a/zypp2/Repository.cc b/zypp2/Repository.cc deleted file mode 100644 index dc477e4..0000000 --- a/zypp2/Repository.cc +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include - -#include "zypp2/Repository.h" -#include "zypp2/repo/RepositoryImpl.h" - -using namespace std; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - - const Repository Repository::noRepository; - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : Repository::Repository - // METHOD TYPE : Ctor - // - Repository::Repository() - : _pimpl( Impl::nullimpl() ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : Repository::Repository - // METHOD TYPE : Ctor - // - Repository::Repository( const Impl_Ptr & impl_r ) - : _pimpl( impl_r ) - { - assert( impl_r ); - } - - /////////////////////////////////////////////////////////////////// - // - // Forward to RepositoryImpl: - // - /////////////////////////////////////////////////////////////////// - - Repository::NumericId Repository::numericId() const - { return _pimpl->numericId(); } - - const ResStore & Repository::resolvables() - { - return _pimpl->resolvables(); - } - -} - diff --git a/zypp2/Repository.h b/zypp2/Repository.h deleted file mode 100644 index c9b1a13..0000000 --- a/zypp2/Repository.h +++ /dev/null @@ -1,81 +0,0 @@ - -#ifndef ZYPP_REPOSITORY_H -#define ZYPP_REPOSITORY_H - -#include -#include - -#include "zypp/base/PtrTypes.h" -#include "zypp/base/SafeBool.h" -#include "zypp/ResStore.h" - -namespace zypp -{ - namespace repo - { - DEFINE_PTR_TYPE(RepositoryImpl); - class RepositoryImpl; - } - - class Repository : protected base::SafeBool /* private, but gcc refuses */ - { - public: - friend std::ostream & operator<<( std::ostream & str, const Repository & obj ); - friend bool operator==( const Repository & lhs, const Repository & rhs ); - friend bool operator<( const Repository & lhs, const Repository & rhs ); - - public: - typedef repo::RepositoryImpl Impl; - typedef repo::RepositoryImpl_Ptr Impl_Ptr; - - public: - - /** Default ctor: noRepository. - * Real Repositorys are to be created via RepositoryFactory. - */ - Repository(); - - /** A dummy Repository (Id \c 0) providing nothing, doing nothing. - * \todo provide a _constRef - */ - static const Repository noRepository; - - /** Validate Repository in a boolean context. - * \c FALSE iff == noRepository. - */ - using base::SafeBool::operator bool_type; - - public: - typedef unsigned long NumericId; - - /** Runtime unique numeric Repository Id. */ - NumericId numericId() const; - - const ResStore & resolvables(); - - private: - friend base::SafeBool::operator bool_type() const; - /** \ref SafeBool test. */ - bool boolTest() const - { return _pimpl != noRepository._pimpl; } - - private: - /** Factory */ - friend class RepoManager; - friend class repo::RepositoryImpl; - - private: - /** Factory ctor */ - explicit - Repository( const Impl_Ptr & impl_r ); - - private: - /** Pointer to implementation */ - Impl_Ptr _pimpl; - }; - -} - -#endif - - diff --git a/zypp2/RepositoryFactory.cc b/zypp2/RepositoryFactory.cc deleted file mode 100644 index a6d3cb7..0000000 --- a/zypp2/RepositoryFactory.cc +++ /dev/null @@ -1,23 +0,0 @@ - -#include "zypp2/RepositoryFactory.h" - -namespace zypp { - -RepositoryFactory::RepositoryFactory() -{ -} - -RepositoryFactory::~RepositoryFactory() -{ - -} - - -Repository RepositoryFactory::createFrom( const RepoInfo & context ) -{ - -} - -} // ns zypp - - diff --git a/zypp2/RepositoryFactory.h b/zypp2/RepositoryFactory.h deleted file mode 100644 index c73f560..0000000 --- a/zypp2/RepositoryFactory.h +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef ZYPP_REPOSITORY_FACTORY_H -#define ZYPP_REPOSITORY_FACTORY_H - -#include "zypp2/Repository.h" -#include "zypp2/RepoInfo.h" - -namespace zypp -{ - class RepositoryFactory - { - friend std::ostream & operator<<( std::ostream & str, const RepositoryFactory & obj ); - - public: - /** Default ctor */ - RepositoryFactory(); - /** Dtor */ - ~RepositoryFactory(); - - public: - /** Construct source. - * \throw EXCEPTION on fail - */ - Repository createFrom( const RepoInfo & context ); - }; -} - -#endif - - diff --git a/zypp2/cache/CacheException.cc b/zypp2/cache/CacheException.cc deleted file mode 100644 index d7504f2..0000000 --- a/zypp2/cache/CacheException.cc +++ /dev/null @@ -1,66 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp/repo/CacheException.cc - * -*/ -#include -//#include "zypp/base/Logger.h" -#include "zypp2/cache/CacheException.h" - -using std::endl; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace cache - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheException::CacheException - // METHOD TYPE : Ctor - // - CacheException::CacheException() - : Exception( "Cache exception" ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheException::CacheException - // METHOD TYPE : Ctor - // - CacheException::CacheException( const std::string & msg_r ) - : Exception( msg_r ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheException::~CacheException - // METHOD TYPE : Dtor - // - CacheException::~CacheException() throw() - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheException::dumpOn - // METHOD TYPE : std::ostream & - // - std::ostream & CacheException::dumpOn( std::ostream & str ) const - { - return Exception::dumpOn( str ); - } - - ///////////////////////////////////////////////////////////////// - } // namespace repo - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// diff --git a/zypp2/cache/CacheException.h b/zypp2/cache/CacheException.h deleted file mode 100644 index 8a44183..0000000 --- a/zypp2/cache/CacheException.h +++ /dev/null @@ -1,57 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ - -#ifndef ZYPP_REPO_REPOEXCEPTION_H -#define ZYPP_REPO_REPOEXCEPTION_H - -#include -#include - -#include "zypp/base/Exception.h" -#include "zypp/base/UserRequestException.h" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace cache - { ///////////////////////////////////////////////////////////////// - - /** - * \short Exception for cache errors - */ - class CacheException : public Exception - { - public: - /** Default ctor */ - CacheException(); - /** Ctor */ - CacheException( const std::string & msg_r ); - /** Dtor */ - virtual ~CacheException() throw(); - protected: - virtual std::ostream & dumpOn( std::ostream & str ) const; - }; - /////////////////////////////////////////////////////////////////// - - /** - * The record you supplied can't be found - */ - class CacheRecordNotFoundException : public CacheException - { - - }; - - ///////////////////////////////////////////////////////////////// - } // namespace cache - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// -#endif // ZYPP_PARSER_TAGFILE_PARSEEXCEPTION_H diff --git a/zypp2/cache/CacheFSCK.cc b/zypp2/cache/CacheFSCK.cc deleted file mode 100644 index 2383526..0000000 --- a/zypp2/cache/CacheFSCK.cc +++ /dev/null @@ -1,125 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp2/cache/CacheFSCK.cc - * -*/ -#include -#include "zypp/base/Logger.h" -#include "zypp/base/Exception.h" -#include "zypp2/cache/CacheFSCK.h" -#include "zypp2/cache/sqlite3x/sqlite3x.hpp" - -using namespace zypp; -using namespace zypp::cache; -using namespace std; -using namespace sqlite3x; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace cache - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : CacheFSCK::Impl - // - /** CacheFSCK implementation. */ - struct CacheFSCK::Impl - { - - public: - - Impl( const Pathname &dbdir ) - : _dbdir(dbdir) - { - - } - - void start() - { - try - { - sqlite3_connection con((_dbdir + "zypp.db").asString().c_str()); - //con.executenonquery("BEGIN;"); - - sqlite3_command cmd( con, "PRAGMA integrity_check;"); - sqlite3_reader reader = cmd.executereader(); - while(reader.read()) - { - cout << reader.getstring(0) << endl; - } - } - catch( const std::exception &e ) - { - ZYPP_RETHROW(Exception(e.what())); - } - } - - private: - friend Impl * rwcowClone( const Impl * rhs ); - /** clone for RWCOW_pointer */ - Impl * clone() const - { return new Impl( *this ); } - - Pathname _dbdir; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates CacheFSCK::Impl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const CacheFSCK::Impl & obj ) - { - return str << "CacheFSCK::Impl"; - } - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : CacheFSCK - // - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheFSCK::CacheFSCK - // METHOD TYPE : Ctor - // - CacheFSCK::CacheFSCK( const Pathname &dbdir ) - : _pimpl( new Impl(dbdir) ) - {} - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CacheFSCK::~CacheFSCK - // METHOD TYPE : Dtor - // - CacheFSCK::~CacheFSCK() - {} - - void CacheFSCK::start() - { - _pimpl->start(); - } - - /****************************************************************** - ** - ** FUNCTION NAME : operator<< - ** FUNCTION TYPE : std::ostream & - */ - std::ostream & operator<<( std::ostream & str, const CacheFSCK & obj ) - { - return str << *obj._pimpl; - } - - ///////////////////////////////////////////////////////////////// - } // namespace cache - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// diff --git a/zypp2/cache/CacheFSCK.h b/zypp2/cache/CacheFSCK.h deleted file mode 100644 index ade9be1..0000000 --- a/zypp2/cache/CacheFSCK.h +++ /dev/null @@ -1,71 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ -/** \file zypp2/cache/CacheFSCK.h - * -*/ -#ifndef ZYPP2_CACHE_CACHEFSCK_H -#define ZYPP2_CACHE_CACHEFSCK_H - -#include - -#include "zypp/base/PtrTypes.h" -#include "zypp/Pathname.h" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace cache - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : CacheFSCK - // - /** - * Check for consistency of the cache - **/ - class CacheFSCK - { - friend std::ostream & operator<<( std::ostream & str, const CacheFSCK & obj ); - - public: - /** Implementation */ - class Impl; - - public: - /** - * Default ctor - * - * \param dbdir Cache directory - */ - CacheFSCK( const Pathname &dbdir ); - - void start(); - /** Dtor */ - ~CacheFSCK(); - - public: - - private: - /** Pointer to implementation */ - RWCOW_pointer _pimpl; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates CacheFSCK Stream output */ - std::ostream & operator<<( std::ostream & str, const CacheFSCK & obj ); - - ///////////////////////////////////////////////////////////////// - } // namespace cache - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp2 -/////////////////////////////////////////////////////////////////// -#endif // ZYPP2_CACHE_CACHEFSCK_H diff --git a/zypp2/cache/CacheInitializer.cpp b/zypp2/cache/CacheInitializer.cpp deleted file mode 100644 index 9f7d308..0000000 --- a/zypp2/cache/CacheInitializer.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ - -#include -#include -#include - -#include "zypp/base/Logger.h" -#include "zypp/base/String.h" -#include "zypp/base/Measure.h" -#include "zypp2/cache/CacheInitializer.h" -#include "zypp2/cache/schema/schema.h" -#include "zypp/target/store/PersistentStorage.h" -#include "zypp2/cache/Utils.h" - -#include "schema.h" - -#define ZYPP_DB_FILE "/var/lib/zypp/zypp.db" - -using namespace sqlite3x; -using namespace std; -using zypp::debug::Measure; - -////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -namespace cache -{ ///////////////////////////////////////////////////////////////// - -struct CacheInitializer::Impl -{ - Impl( const Pathname &root_r ) - : root(root_r), just_initialized(false) - { - } - //typedef std::map MediaMap - shared_ptr con; - Pathname root; - bool just_initialized; -}; - -CacheInitializer::CacheInitializer( const Pathname &root_r, const Pathname &db_file ) - : _pimpl( new Impl( root_r ) ) -{ - try - { - _pimpl->con.reset( new sqlite3_connection( ( _pimpl->root + db_file).asString().c_str()) ); - - if( ! tablesCreated() ) - { - createTables(); - _pimpl->just_initialized = true; - _pimpl->con->close(); - MIL << "Source cache initialized" << std::endl; - } - else - { - MIL << "Source cache already initialized" << std::endl; - } - } - catch( const exception &ex ) - { - ZYPP_RETHROW(Exception(ex.what())); - //ERR << "Exception Occured: " << ex.what() << endl; - } - -} - -bool CacheInitializer::justInitialized() const -{ - return _pimpl->just_initialized; -} - -CacheInitializer::~CacheInitializer() -{ - -} - -bool CacheInitializer::tablesCreated() const -{ - Measure timer("Check tables exist"); - unsigned int count = _pimpl->con->executeint("select count(*) from sqlite_master where type='table';"); - timer.elapsed(); - return ( count > 0 ); -} - -void CacheInitializer::createTables() -{ - Measure timer("Create database tables"); - MIL << "Initializing cache schema..." << endl; - sqlite3_transaction trans(*_pimpl->con); - { - string sql( schemaData, _schemaData_size); - //ERR << "Executing " << statements[i] << endl; - MIL << "Schema size: " << sql.size() << endl; - _pimpl->con->execute(sql.c_str()); - } - trans.commit(); - timer.elapsed(); -} - -std::ostream & CacheInitializer::dumpOn( std::ostream & str ) const -{ - return str; -} - -} -} - diff --git a/zypp2/cache/CacheInitializer.h b/zypp2/cache/CacheInitializer.h deleted file mode 100644 index ba10281..0000000 --- a/zypp2/cache/CacheInitializer.h +++ /dev/null @@ -1,74 +0,0 @@ -/*---------------------------------------------------------------------\ -| ____ _ __ __ ___ | -| |__ / \ / / . \ . \ | -| / / \ V /| _/ _/ | -| / /__ | | | | | | | -| /_____||_| |_| |_| | -| | -\---------------------------------------------------------------------*/ - -#ifndef ZYPP_CacheInitializer_H -#define ZYPP_CacheInitializer_H - -#include -#include - -#include "zypp/base/PtrTypes.h" -#include "zypp/base/ReferenceCounted.h" -#include "zypp/base/NonCopyable.h" -#include "zypp/Pathname.h" -#include "zypp2/cache/sqlite3x/sqlite3x.hpp" - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - namespace cache - { ///////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : CacheInitializer - // - class CacheInitializer - { - friend std::ostream & operator<<( std::ostream & str, const CacheInitializer & obj ); - - public: - /** - * Tries to initialize the source cache if it was not - * \throws Exception When cant initialize - */ - CacheInitializer( const Pathname &root_r, const Pathname &db_file ); - virtual ~CacheInitializer(); - - /** - * only true when cache was not initialized before - * and was just initialized with success - */ - bool justInitialized() const; - protected: - bool tablesCreated() const; - void createTables(); - /** Overload to realize stream output. */ - virtual std::ostream & dumpOn( std::ostream & str ) const; - private: - /** Implementation. */ - class Impl; - /** Pointer to implementation. */ - RW_pointer _pimpl; - }; - /////////////////////////////////////////////////////////////////// - - /** \relates CacheInitializer Stream output */ - inline std::ostream & operator<<( std::ostream & str, const CacheInitializer & obj ) - { return obj.dumpOn( str ); } - - - ///////////////////////////////////////////////////////////////// - } // namespace cache - /////////////////////////////////////////////////////////////////// - ///////////////////////////////////////////////////////////////// -} // namespace zypp -/////////////////////////////////////////////////////////////////// -#endif // ZYPP_SOURCE_CacheInitializer_H diff --git a/zypp2/cache/CacheStore.cpp b/zypp2/cache/CacheStore.cpp deleted file mode 100644 index 542f1f0..0000000 --- a/zypp2/cache/CacheStore.cpp +++ /dev/null @@ -1,1036 +0,0 @@ - -#include -#include -#include "zypp2/cache/sqlite3x/sqlite3x.hpp" - -#include "zypp/base/Logger.h" -#include "zypp/base/Measure.h" -#include "zypp/ZYppFactory.h" -#include "zypp/ZYpp.h" -#include "zypp/ZConfig.h" - -#include "zypp2/cache/CacheInitializer.h" -#include "zypp2/cache/CacheStore.h" -#include "zypp2/cache/CacheException.h" - -using namespace std; -using namespace zypp; -using namespace zypp::capability; -using namespace zypp::cache; -using zypp::data::RecordId; -using namespace sqlite3x; - -using zypp::debug::Measure; - -/////////////////////////////////////////////////////////////////// -namespace zypp -{ ///////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////////// -namespace cache -{ ///////////////////////////////////////////////////////////////// - -typedef shared_ptr sqlite3_command_ptr; - -struct CacheStore::Impl -{ - Impl( const Pathname &dbdir ) - : name_cache_hits(0) - { - cache::CacheInitializer initializer(dbdir, "zypp.db"); - if ( initializer.justInitialized() ) - { - MIL << "database " << (dbdir + "zypp.db") << " was just created" << endl; - } - - try - { - con.open( (dbdir + "zypp.db").asString().c_str()); - //_insert_resolvable_cmd = new sqlite3_command( *_con, INSERT_RESOLVABLE_QUERY ); - //_insert_package_cmd = new sqlite3_command( *_con, INSERT_PACKAGE_QUERY ); - } - catch(exception &ex) - { - //ZYPP_CAUGHT(ex); - ZYPP_THROW(Exception(ex.what())); - } - - - // initialize all pre-compiled statements - - insert_resolvable_in_repository_cmd.reset( new sqlite3_command( con, "insert into resolvables_repositories (resolvable_id, repository_id) values (:resolvable_id, :repository_id);" )); - - update_repository_cmd.reset( new sqlite3_command( con, "update repositories set checksum=:checksum, timestamp=:timestamp where id=:repository_id;" )); - - select_repository_cmd.reset( new sqlite3_command( con, "select id from repositories where alias=:alias;" )); - insert_repository_cmd.reset( new sqlite3_command( con, "insert into repositories (alias,timestamp) values (:alias, :timestamp);" )); - - select_name_cmd.reset( new sqlite3_command( con, "select id from names where name=:name;" )); - insert_name_cmd.reset( new sqlite3_command( con, "insert into names (name) values (:name);" )); - - select_dirname_cmd.reset( new sqlite3_command( con, "select id from dir_names where name=:name;" )); - insert_dirname_cmd.reset( new sqlite3_command( con, "insert into dir_names (name) values (:name);" )); - - select_filename_cmd.reset( new sqlite3_command( con, "select id from file_names where name=:name;" )); - insert_filename_cmd.reset( new sqlite3_command( con, "insert into file_names (name) values (:name);" )); - - select_file_cmd.reset( new sqlite3_command( con, "select id from files where dir_name_id=:dir_name_id and file_name_id=:file_name_id;" )); - insert_file_cmd.reset( new sqlite3_command( con, "insert into files (dir_name_id,file_name_id) values (:dir_name_id,:file_name_id);" )); - - select_type_cmd.reset( new sqlite3_command( con, "select id from types where class=:class and name=:name;" )); - insert_type_cmd.reset( new sqlite3_command( con, "insert into types (class,name) values (:class,:name);" )); - - set_shared_flag_cmd.reset( new sqlite3_command( con, "update resolvables set shared_id=:shared_id where id=:resolvable_id;" )); - - append_text_attribute_cmd.reset( new sqlite3_command( con, "insert into text_attributes ( weak_resolvable_id, lang_id, attr_id, text ) values ( :rid, :lang_id, :attr_id, :text );" )); - append_num_attribute_cmd.reset( new sqlite3_command( con, "insert into numeric_attributes ( weak_resolvable_id, attr_id, value ) values ( :rid, :attr_id, :value );" )); - - //insert_dependency_entry_cmd.reset( new sqlite3_command( con, "insert into capabilities ( resolvable_id, dependency_type, refers_kind ) values ( :resolvable_id, :dependency_type, :refers_kind );" )); - append_file_dependency_cmd.reset( new sqlite3_command( con, "insert into file_capabilities ( resolvable_id, dependency_type, refers_kind, file_id ) values ( :resolvable_id, :dependency_type, :refers_kind, :file_id );" )); - append_named_dependency_cmd.reset( new sqlite3_command( con, "insert into named_capabilities ( resolvable_id, dependency_type, refers_kind, name_id, version, release, epoch, relation ) values ( :resolvable_id, :dependency_type, :refers_kind, :name_id, :version, :release, :epoch, :relation );" )); - - append_modalias_dependency_cmd.reset( new sqlite3_command( con, "insert into modalias_capabilities ( resolvable_id, dependency_type, refers_kind, name, value, relation ) values ( :resolvable_id, :dependency_type, :refers_kind, :name, :value, :relation );" )); - - append_hal_dependency_cmd.reset( new sqlite3_command( con, "insert into hal_capabilities ( resolvable_id, dependency_type, refers_kind, name, value, relation ) values ( :resolvable_id, :dependency_type, :refers_kind, :name, :value, :relation );" )); - - append_other_dependency_cmd.reset( new sqlite3_command( con, "insert into other_capabilities ( resolvable_id, dependency_type, refers_kind, value ) values ( :resolvable_id, :dependency_type, :refers_kind, :value );" )); - - append_resolvable_cmd.reset( new sqlite3_command( con, "insert into resolvables ( name, version, release, epoch, arch, kind, repository_id ) values ( :name, :version, :release, :epoch, :arch, :kind, :repository_id );" )); - - count_shared_cmd.reset( new sqlite3_command( con, "select count(id) from resolvables where shared_id=:rid;" )); - - insert_patchrpm_cmd.reset( new sqlite3_command (con, - "insert into patch_packages (media_nr, location, checksum, download_size, build_time) " - "values (:media_nr, :location, :checksum, :download_size, :build_time);" )); - insert_deltarpm_cmd.reset( new sqlite3_command (con, - "insert into delta_packages (media_nr, location, checksum, download_size, build_time, " - "baseversion_version, baseversion_release, baseversion_epoch, baseversion_checksum, " - "baseversion_build_time, baseversion_sequence_info) " - "values (:media_nr, :location, :checksum, :download_size, :build_time, " - ":baseversion_version, :baseversion_release, :baseversion_epoch, :baseversion_checksum, " - ":baseversion_build_time, :baseversion_sequence_info);" )); - append_patch_baseversion_cmd.reset( new sqlite3_command (con, - "insert into patch_packages_baseversions (patch_package_id, version, release, epoch) " - "values (:patch_package_id, :version, :release, :epoch)" )); - - - // disable autocommit - con.executenonquery("BEGIN;"); - } - - Impl() - { - Impl( getZYpp()->homePath() ); - } - - ~Impl() - { - MIL << "name cache hits: " << name_cache_hits << " | cache size: " << name_cache.size() << endl; - } - - /** - * SQL statements - * (we precompile them - */ - sqlite3_connection con; - - sqlite3_command_ptr update_repository_cmd; - sqlite3_command_ptr insert_resolvable_in_repository_cmd; - - sqlite3_command_ptr select_name_cmd; - sqlite3_command_ptr insert_name_cmd; - - sqlite3_command_ptr select_dirname_cmd; - sqlite3_command_ptr insert_dirname_cmd; - - sqlite3_command_ptr select_filename_cmd; - sqlite3_command_ptr insert_filename_cmd; - - sqlite3_command_ptr select_repository_cmd; - sqlite3_command_ptr insert_repository_cmd; - - sqlite3_command_ptr select_file_cmd; - sqlite3_command_ptr insert_file_cmd; - - sqlite3_command_ptr select_type_cmd; - sqlite3_command_ptr insert_type_cmd; - - //sqlite3_command_ptr insert_dependency_entry_cmd; - - sqlite3_command_ptr append_file_dependency_cmd; - sqlite3_command_ptr append_named_dependency_cmd; - sqlite3_command_ptr append_modalias_dependency_cmd; - sqlite3_command_ptr append_hal_dependency_cmd; - sqlite3_command_ptr append_other_dependency_cmd; - - sqlite3_command_ptr append_resolvable_cmd; - - sqlite3_command_ptr append_text_attribute_cmd; - sqlite3_command_ptr append_num_attribute_cmd; - - sqlite3_command_ptr set_shared_flag_cmd; - - sqlite3_command_ptr count_shared_cmd; - - sqlite3_command_ptr insert_patchrpm_cmd; - sqlite3_command_ptr insert_deltarpm_cmd; - sqlite3_command_ptr append_patch_baseversion_cmd; - - map name_cache; - map< pair, RecordId> type_cache; - int name_cache_hits; -}; - - -CacheStore::CacheStore( const Pathname &dbdir ) - : _pimpl( new Impl(dbdir) ) -{ - -} - -CacheStore::CacheStore() - : _pimpl( new Impl() ) -{ - -} - -CacheStore::~CacheStore() -{ - -} - -void CacheStore::commit() -{ - _pimpl->con.executenonquery("COMMIT;"); -} - -void CacheStore::appendResObjectAttributes( const data::RecordId &rid, - const data::ResObject_Ptr & res ) -{ - appendTranslatedStringAttribute( rid, "ResObject", "description", res->description ); - appendTranslatedStringAttribute( rid, "ResObject", "summary", res->summary ); - appendNumericAttribute( rid, "ResObject", "installedSize", res->installedSize ); - appendNumericAttribute( rid, "ResObject", "buildTime", res->buildTime ); - appendBooleanAttribute( rid, "ResObject", "installOnly", res->installOnly ); - appendStringAttribute( rid, "ResObject", "vendor", res->vendor ); - appendTranslatedStringAttribute( rid, "ResObject", "licenseToConfirm", res->licenseToConfirm ); - appendTranslatedStringAttribute( rid, "ResObject", "insnotify", res->insnotify ); - appendTranslatedStringAttribute( rid, "ResObject", "delnotify", res->delnotify ); -} - - -void CacheStore::appendPackageBaseAttributes( const RecordId & pkgid, - const data::Packagebase_Ptr & package ) -{ - appendStringAttribute( pkgid, "Package", "checksum", package->repositoryLocation.fileChecksum.checksum() ); - appendStringAttribute( pkgid, "Package", "checksumType", package->repositoryLocation.fileChecksum.type() ); - appendStringAttribute( pkgid, "Package", "buildhost", package->buildhost ); - appendStringAttribute( pkgid, "Package", "distribution", package->distribution ); - appendStringAttribute( pkgid, "Package", "license", package->license ); - appendStringAttribute( pkgid, "Package", "group", package->packager ); - appendStringAttribute( pkgid, "Package", "url", package->url ); - appendStringAttribute( pkgid, "Package", "operatingSystem", package->operatingSystem ); - appendStringAttribute( pkgid, "Package", "prein", package->prein ); - appendStringAttribute( pkgid, "Package", "postin", package->postin ); - appendStringAttribute( pkgid, "Package", "preun", package->preun ); - appendStringAttribute( pkgid, "Package", "postun", package->postun ); - appendStringContainerAttribute( pkgid, "Package", "keywords", package->keywords ); - appendStringContainerAttribute( pkgid, "Package", "authors", package->authors ); - appendStringAttribute( pkgid, "Package", "location", package->repositoryLocation.filePath.asString() ); -} - -void CacheStore::consumePackage( const RecordId & repository_id, - const data::Package_Ptr & package ) -{ - RecordId pkgid = appendResolvable( repository_id, ResTraits::kind, - NVRA( package->name, package->edition, package->arch ), package->deps ); - appendResObjectAttributes( pkgid, package ); - appendPackageBaseAttributes( pkgid, package ); -} - -void CacheStore::consumeSourcePackage( const data::RecordId & repository_id, - const data::SrcPackage_Ptr & package ) -{ - RecordId pkgid = appendResolvable( repository_id, ResTraits::kind, - NVRA( package->name, package->edition, package->arch ), package->deps ); - appendResObjectAttributes( pkgid, package ); - appendPackageBaseAttributes( pkgid, package ); -#warning TBD -} - -void CacheStore::consumePatch( const data::RecordId & repository_id, - const data::Patch_Ptr & patch) -{ - RecordId id = appendResolvable( - repository_id, ResTraits::kind, - NVRA( patch->name, patch->edition, patch->arch ), patch->deps ); - - appendResObjectAttributes( id, patch ); - - // patch attributes - appendNumericAttribute( id, "Patch", "timestamp", patch->timestamp ); - appendStringAttribute( id, "Patch", "category", patch->category ); - appendBooleanAttribute( id, "Patch", "rebootNeeded", patch->rebootNeeded ); - appendBooleanAttribute( id, "Patch", "affectsPkgManager", patch->affectsPkgManager ); - - - DBG << "got patch " << patch->name << ", atoms: "; - // cosume atoms - for (set::const_iterator p = patch->atoms.begin(); - p != patch->atoms.end(); ++p) - { - data::PackageAtom_Ptr atom = dynamic_pointer_cast(*p); - if (atom) - { - DBG << atom->name << "(atom) "; - consumePackageAtom(repository_id, atom); - continue; - } - - data::Script_Ptr script = dynamic_pointer_cast(*p); - if (script) - { - DBG << script->name << "(script) "; - consumeScript(repository_id, script); - continue; - } - - data::Message_Ptr message = dynamic_pointer_cast(*p); - if (message) - { - DBG << message->name << "(message) "; - consumeMessage(repository_id, message); - continue; - } - - ERR << " ignoring !badatom! "; - if (*p) ERR << (*p)->name; - ERR << endl; - } - - DBG << endl; -} - -void CacheStore::consumePackageAtom( const data::RecordId & repository_id, - const data::PackageAtom_Ptr & atom ) -{ - RecordId id = appendResolvable( repository_id, ResTraits::kind, - NVRA( atom->name, atom->edition, atom->arch ), atom->deps ); - appendResObjectAttributes( id, atom ); - appendPackageBaseAttributes( id, atom ); - - for (set::const_iterator p = atom->patchRpms.begin(); - p != atom->patchRpms.end(); ++p) - appendPatchRpm(*p); - - for (set::const_iterator d = atom->deltaRpms.begin(); - d != atom->deltaRpms.end(); ++d) - appendDeltaRpm(*d); -} - -void CacheStore::consumeMessage( const data::RecordId & repository_id, - const data::Message_Ptr & message ) -{ - RecordId id = appendResolvable( repository_id, ResTraits::kind, - NVRA( message->name, message->edition, message->arch ), message->deps ); - appendResObjectAttributes( id, message ); - - appendTranslatedStringAttribute( id, "Message", "text", message->text ); -} - -void CacheStore::consumeScript( const data::RecordId & repository_id, - const data::Script_Ptr & script ) -{ - RecordId id = appendResolvable( repository_id, ResTraits