From cc6f9cf98b511b424606fd3948f1c8d6b1baa4fc Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Sat, 4 Feb 2006 19:11:06 +0000 Subject: [PATCH] - backup; start fixing Source init. --- zypp/Source.cc | 19 ++++++---- zypp/Source.h | 11 ++---- zypp/source/SourceImpl.cc | 37 ++++++++++---------- zypp/source/SourceImpl.h | 67 ++++++++++++++++++++++-------------- zypp/source/susetags/SuseTagsImpl.cc | 60 +++----------------------------- zypp/source/susetags/SuseTagsImpl.h | 16 +++------ zypp/source/yum/YUMSourceImpl.h | 5 +-- 7 files changed, 87 insertions(+), 128 deletions(-) diff --git a/zypp/Source.cc b/zypp/Source.cc index aa4d651..e9a9434 100644 --- a/zypp/Source.cc +++ b/zypp/Source.cc @@ -52,18 +52,15 @@ namespace zypp /////////////////////////////////////////////////////////////////// const ResStore & Source_Ref::resolvables() const - { return _pimpl->resolvables(*this); } - - std::ostream & Source_Ref::dumpOn( std::ostream & str ) const - { return _pimpl->dumpOn( str ); } + { return _pimpl->resolvables(); } const Pathname Source_Ref::provideFile(const Pathname & file_r, const unsigned media_nr) { return _pimpl->provideFile(file_r, media_nr); } const Pathname Source_Ref::provideDir(const Pathname & dir_r, - const unsigned media_nr, - const bool recursive) + const unsigned media_nr, + const bool recursive) { return _pimpl->provideDir(dir_r, media_nr, recursive); } const bool Source_Ref::enabled() const @@ -99,6 +96,16 @@ namespace zypp const Pathname & Source_Ref::path (void) const { return _pimpl->path (); } + /****************************************************************** + ** + ** FUNCTION NAME : operator<< + ** FUNCTION TYPE : std::ostream & + */ + std::ostream & operator<<( std::ostream & str, const Source_Ref & obj ) + { + return str << *obj._pimpl; + } + ///////////////////////////////////////////////////////////////// } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/Source.h b/zypp/Source.h index 0a1c148..b599042 100644 --- a/zypp/Source.h +++ b/zypp/Source.h @@ -41,6 +41,7 @@ namespace zypp */ class Source_Ref { + friend std::ostream & operator<<( std::ostream & str, const Source_Ref & obj ); friend bool operator==( const Source_Ref & lhs, const Source_Ref & rhs ); friend bool operator<( const Source_Ref & lhs, const Source_Ref & rhs ); @@ -112,7 +113,7 @@ namespace zypp private: /** Factory */ friend class SourceFactory; - friend class SourceManager; + friend class source::SourceImpl; private: /** Factory ctor */ @@ -120,19 +121,13 @@ namespace zypp Source_Ref( const Impl_Ptr & impl_r ); private: - friend std::ostream & operator<<( std::ostream & str, Source_Ref obj ); - /** Stream output. */ - std::ostream & dumpOn( std::ostream & str ) const; - - private: /** Pointer to implementation */ Impl_Ptr _pimpl; }; /////////////////////////////////////////////////////////////////// /** \relates Source Stream output. */ - inline std::ostream & operator<<( std::ostream & str, Source_Ref obj ) - { return obj.dumpOn( str ); } + std::ostream & operator<<( std::ostream & str, const Source_Ref & obj ); /** \relates Source_Ref Equal if same implementation class. */ inline bool operator==( const Source_Ref & lhs, const Source_Ref & rhs ) diff --git a/zypp/source/SourceImpl.cc b/zypp/source/SourceImpl.cc index 4b576e0..e6be99d 100644 --- a/zypp/source/SourceImpl.cc +++ b/zypp/source/SourceImpl.cc @@ -59,57 +59,58 @@ namespace zypp SourceImpl::~SourceImpl() {} - const ResStore & SourceImpl::resolvables(Source_Ref source_r) const + const ResStore & SourceImpl::resolvables() const { if ( !_res_store_initialized ) { // cast away const to allow late init - const_cast(this)->createResolvables(source_r); + Source_Ref self( const_cast(this)->selfSourceRef() ); + const_cast(this)->createResolvables(self); const_cast(this)->_res_store_initialized = true; } return _store; } const Pathname SourceImpl::provideFile(const Pathname & file_r, - const unsigned media_nr, - bool cached, + const unsigned media_nr, + bool cached, bool checkonly ) { - + callback::SendReport report; - + SourceFactory source_factory; - + do { try { media_mgr.provideFile (_media, media_nr, file_r, cached, checkonly); break; - } + } catch ( Exception & excp ) { - media::MediaChangeReport::Action user - = checkonly ? media::MediaChangeReport::ABORT : - report->requestMedia ( + media::MediaChangeReport::Action user + = checkonly ? media::MediaChangeReport::ABORT : + report->requestMedia ( source_factory.createFrom(this), media_nr, media::MediaChangeReport::WRONG, // FIXME: proper error excp.msg() ); - - if( user == media::MediaChangeReport::ABORT ) + + if( user == media::MediaChangeReport::ABORT ) { ZYPP_RETHROW ( excp ); - } + } else if ( user == media::MediaChangeReport::EJECT ) { media_mgr.release (_media, true); // FIXME: this will not work, probably } - + // FIXME: IGNORE } } while( true ); - + return media_mgr.localPath(_media, file_r); } @@ -170,10 +171,10 @@ namespace zypp std::string vendor; std::string id; -#warning check the stream status +#warning check the stream status getline(str, vendor); getline(str, id); - + return (vendor == _media_vendor && id == _media_id ); } diff --git a/zypp/source/SourceImpl.h b/zypp/source/SourceImpl.h index 317e661..292d8b4 100644 --- a/zypp/source/SourceImpl.h +++ b/zypp/source/SourceImpl.h @@ -48,23 +48,15 @@ namespace zypp friend std::ostream & operator<<( std::ostream & str, const SourceImpl & obj ); public: - /** Ctor, FIXME it is here only because of target storage, then make it private */ - SourceImpl() - : _res_store_initialized(true) // in case of null source, nothing to read - {} - - /** Ctor. */ - SourceImpl(media::MediaId & media_r, - const Pathname & path_r = "/", - const std::string & alias = "", - const Pathname cache_dir_r = ""); - /** Dtor. */ - virtual ~SourceImpl(); + /** SourceImpl MediaVerifier. */ + class Verifier; public: /** All resolvables provided by this source. */ - const ResStore & resolvables(Source_Ref source_r) const; + const ResStore & resolvables(Source_Ref) const + { return resolvables(); } + const ResStore & resolvables() const; /** * Provide a file to local filesystem @@ -110,8 +102,10 @@ namespace zypp const Pathname & path (void) const; - /** Overload to realize stream output. */ - virtual std::ostream & dumpOn( std::ostream & str ) const; + protected: + /** Provide Source_Ref to \c this. */ + Source_Ref selfSourceRef() + { return Source_Ref( this ); } protected: /** All resolvables provided by this source. */ @@ -131,13 +125,33 @@ namespace zypp /** (user defined) unsubscribed priority of the source */ unsigned _priority_unsubscribed; + /////////////////////////////////////////////////////////////////// + // no playgroung below this line ;) + /////////////////////////////////////////////////////////////////// + protected: + /** Ctor. */ + SourceImpl(media::MediaId & media_r, + const Pathname & path_r = "/", + const std::string & alias = "", + const Pathname cache_dir_r = ""); + /** Dtor. */ + virtual ~SourceImpl(); + + /** Overload to realize stream output. */ + virtual std::ostream & dumpOn( std::ostream & str ) const; + private: - /** */ /** Late initialize the ResStore. */ virtual void createResolvables(Source_Ref source_r); /** Whether the ResStore is initialized. */ bool _res_store_initialized; + private: + /** Ctor, excl. for nullimpl only. */ + SourceImpl() + : _res_store_initialized(true) + {} + public: /** Offer default Impl. */ static SourceImpl_Ptr nullimpl() @@ -146,7 +160,18 @@ namespace zypp return _nullimpl; } - class Verifier : public media::MediaVerifierBase + }; + /////////////////////////////////////////////////////////////////// + + /** \relates SourceImpl Stream output */ + inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj ) + { return obj.dumpOn( str ); } + + /////////////////////////////////////////////////////////////////// + + /** SourceImpl MediaVerifier. + */ + class SourceImpl::Verifier : public media::MediaVerifierBase { public: /** ctor */ @@ -164,14 +189,6 @@ namespace zypp SourceImpl_Ptr _source; }; - - }; - /////////////////////////////////////////////////////////////////// - - /** \relates SourceImpl Stream output */ - inline std::ostream & operator<<( std::ostream & str, const SourceImpl & obj ) - { return obj.dumpOn( str ); } - ///////////////////////////////////////////////////////////////// } // namespace source /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/susetags/SuseTagsImpl.cc b/zypp/source/susetags/SuseTagsImpl.cc index 59d6f12..fddc9fb 100644 --- a/zypp/source/susetags/SuseTagsImpl.cc +++ b/zypp/source/susetags/SuseTagsImpl.cc @@ -40,58 +40,6 @@ namespace zypp // METHOD NAME : SuseTagsImpl::SuseTagsImpl // METHOD TYPE : Ctor // - SuseTagsImpl::SuseTagsImpl( const Pathname & localDir_r ) - { - - media::MediaManager media_mgr; - - try { - Pathname media_file = "/media.1/media"; - - media_mgr.provideFile (_media, 1, media_file); - media_file = media_mgr.localPath(_media, media_file); - -#warning check the stream status - std::ifstream str(media_file.asString().c_str()); - std::string media_vendor; - std::string media_id; - getline(str, media_vendor); - getline(str, media_id); - - media_mgr.delVerifier(_media); - - MIL << "Adding proper media verifier" << endl; - - media_mgr.addVerifier(_media, media::MediaVerifierRef(new Verifier(media_vendor, media_id))); - } - catch (const Exception & excpt_r) - { -#warning FIXME: If media data is not set, verifier is not set. Should the media be refused instead? - ZYPP_CAUGHT(excpt_r); - WAR << "Verifier not found" << endl; - } - - PathInfo p( localDir_r ); - if ( p.isDir() ) - p( localDir_r + "packages" ); - if ( ! p.isFile() ) - ZYPP_THROW( Exception( p.asString()+" is not a file" ) ); - if ( ! p.userMayR() ) - ZYPP_THROW( Exception( p.asString()+" no permission to read" ) ); - - Source_Ref source_r( SourceFactory().createFrom( this ) ); - std::list content( parsePackages( source_r, this, - p.path() ) ); - _store.insert( content.begin(), content.end() ); - DBG << "SuseTagsImpl (fake) from " << p << ": " - << content.size() << " packages" << endl; - } - - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : SuseTagsImpl::SuseTagsImpl - // METHOD TYPE : Ctor - // SuseTagsImpl::SuseTagsImpl( media::MediaId & media_r, const Pathname & path_r, const std::string & alias_r ) : SourceImpl(media_r, path_r, alias_r) { @@ -117,14 +65,14 @@ namespace zypp } catch (...) { MIL << "'selections' file not found" << endl; - + file_found = false; } - + if (file_found) { std::ifstream sels (p.asString().c_str()); - + while (sels && !sels.eof()) { std::string selfile; @@ -151,7 +99,7 @@ namespace zypp // parse patterns file_found = true; - + try { p = provideFile(_path + "suse/setup/descr/patterns"); } catch (...) diff --git a/zypp/source/susetags/SuseTagsImpl.h b/zypp/source/susetags/SuseTagsImpl.h index 8652b01..0a9fab5 100644 --- a/zypp/source/susetags/SuseTagsImpl.h +++ b/zypp/source/susetags/SuseTagsImpl.h @@ -36,28 +36,22 @@ namespace zypp class SuseTagsImpl : public SourceImpl { public: + typedef intrusive_ptr Ptr; + typedef intrusive_ptr constPtr; - typedef intrusive_ptr Ptr; - - /** \deprecated Interim ctor for testing - * \throw EXCEPTION on parse error - */ - SuseTagsImpl( const Pathname & localDir_r ); + public: /** Factory ctor */ SuseTagsImpl( media::MediaId & media_r, const Pathname & path_r = "/", const std::string & alias_r = ""); /** Dtor */ ~SuseTagsImpl(); virtual void createResolvables(Source_Ref source_r); - + Pathname sourceDir( const NVRAD& nvrad ); - public: + protected: /** Stream output. */ virtual std::ostream & dumpOn( std::ostream & str ) const; - - public: - }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/yum/YUMSourceImpl.h b/zypp/source/yum/YUMSourceImpl.h index f8fddb1..beb45dc 100644 --- a/zypp/source/yum/YUMSourceImpl.h +++ b/zypp/source/yum/YUMSourceImpl.h @@ -42,10 +42,7 @@ namespace zypp class YUMSourceImpl : public SourceImpl { public: - /** Ctor, FIXME it is here only because of target storage */ - YUMSourceImpl() - {} - /** Default ctor */ + /** Factory ctor */ YUMSourceImpl(media::MediaId & media_r, const Pathname & path_r = "/", const std::string & alias_r = "", const Pathname cache_dir_r = "/"); virtual void storeMetadata(const Pathname & cache_dir_r); -- 2.7.4