Author: dmacvicar Date: Mon May 21 10:27:31 2007 New Revision: 5577 URL: http://svn.opensuse.org/viewcvs/zypp?rev=5577&view=rev Log: hide fetcher implementation in order to operate over jobs instead of onmedialocations Modified: trunk/libzypp/tests/CMakeLists.txt trunk/libzypp/zypp/Fetcher.cc trunk/libzypp/zypp/Fetcher.h trunk/libzypp/zypp/MediaSetAccess.cc trunk/libzypp/zypp/MediaSetAccess.h trunk/libzypp/zypp/source/yum/YUMDownloader.cc Modified: trunk/libzypp/tests/CMakeLists.txt URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/CMakeLists.txt?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/tests/CMakeLists.txt (original) +++ trunk/libzypp/tests/CMakeLists.txt Mon May 21 10:27:31 2007 @@ -1,4 +1,5 @@ ENABLE_TESTING() + INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ADD_DEFINITIONS( -DTESTS_SRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" ) Modified: trunk/libzypp/zypp/Fetcher.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Fetcher.cc?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/zypp/Fetcher.cc (original) +++ trunk/libzypp/zypp/Fetcher.cc Mon May 21 10:27:31 2007 @@ -6,122 +6,232 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ +/** \file zypp/Fetcher.cc + * +*/ +#include <iostream> +#include <list> #include "zypp/base/Logger.h" +#include "zypp/base/DefaultIntegral.h" #include "zypp/Fetcher.h" -#include "zypp/MediaSetAccess.h" -#include "zypp/PathInfo.h" + using namespace std; -using namespace zypp::filesystem; +/////////////////////////////////////////////////////////////////// namespace zypp -{ +{ ///////////////////////////////////////////////////////////////// + + struct FetcherJob + { + FetcherJob( const OnMediaLocation &loc ) + : location(loc) + { -Fetcher::Fetcher() -{ + } + + OnMediaLocation location; + }; + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : Fetcher::Impl + // + /** Fetcher implementation. */ + struct Fetcher::Impl + { -} + public: -void Fetcher::enqueue( const OnMediaLocation &resource ) -{ - _resources.push_back(resource); -} - -void Fetcher::reset() -{ - _resources.clear(); - _caches.clear(); -} - -void Fetcher::addCachePath( const Pathname &cache_dir ) -{ - _caches.push_back(cache_dir); -} - -void Fetcher::start( const Pathname &dest_dir, MediaSetAccess &media ) -{ - for ( list<OnMediaLocation>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res ) + void enqueue( const OnMediaLocation &resource ); + void addCachePath( const Pathname &cache_dir ); + void reset(); + void start( const Pathname &dest_dir, MediaSetAccess &media ); + + /** Offer default Impl. */ + static shared_ptr<Impl> nullimpl() + { + static shared_ptr<Impl> _nullimpl( new Impl ); + return _nullimpl; + } + + private: + friend Impl * rwcowClone<Impl>( const Impl * rhs ); + /** clone for RWCOW_pointer */ + Impl * clone() const + { return new Impl( *this ); } + + std::list<FetcherJob> _resources; + std::list<Pathname> _caches; + }; + /////////////////////////////////////////////////////////////////// + + + void Fetcher::Impl::enqueue( const OnMediaLocation &resource ) + { + _resources.push_back(FetcherJob(resource)); + } + + void Fetcher::Impl::reset() + { + _resources.clear(); + _caches.clear(); + } + + void Fetcher::Impl::addCachePath( const Pathname &cache_dir ) + { + _caches.push_back(cache_dir); + } + + void Fetcher::Impl::start( const Pathname &dest_dir, MediaSetAccess &media ) { - bool got_from_cache = false; - for ( list<Pathname>::const_iterator it_cache = _caches.begin(); it_cache != _caches.end(); ++it_cache ) + for ( list<FetcherJob>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res ) { - // Pathinfos could be cached to avoid too many stats? - PathInfo info(*it_cache); - if ( info.isDir() ) + bool got_from_cache = false; + for ( list<Pathname>::const_iterator it_cache = _caches.begin(); it_cache != _caches.end(); ++it_cache ) { - // does the current file exists in the current cache? - Pathname cached_file = *it_cache + (*it_res).filename(); - if ( PathInfo( cached_file ).isExist() ) + // Pathinfos could be cached to avoid too many stats? + PathInfo info(*it_cache); + if ( info.isDir() ) { - // check the checksum - if ( is_checksum( cached_file, (*it_res).checksum() ) ) + // does the current file exists in the current cache? + Pathname cached_file = *it_cache + (*it_res).location.filename(); + if ( PathInfo( cached_file ).isExist() ) { - // cached - MIL << "file " << (*it_res).filename() << " found in previous cache. Using cached copy." << endl; - // checksum is already checked. - // we could later implement double failover and try to download if file copy fails. - - // replicate the complete path in the target directory - Pathname dest_full_path = dest_dir + (*it_res).filename(); - if ( assert_dir( dest_full_path.dirname() ) != 0 ) - ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString())); - - if ( filesystem::copy(cached_file, dest_full_path ) != 0 ) - { //copy_file2dir - //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString())); - ERR << "Can't copy " << cached_file + " to " + dest_dir << endl; - // try next cache - continue; + // check the checksum + if ( is_checksum( cached_file, (*it_res).location.checksum() ) ) + { + // cached + MIL << "file " << (*it_res).location.filename() << " found in previous cache. Using cached copy." << endl; + // checksum is already checked. + // we could later implement double failover and try to download if file copy fails. + + // replicate the complete path in the target directory + Pathname dest_full_path = dest_dir + (*it_res).location.filename(); + if ( assert_dir( dest_full_path.dirname() ) != 0 ) + ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString())); + + if ( filesystem::copy(cached_file, dest_full_path ) != 0 ) + { //copy_file2dir + //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString())); + ERR << "Can't copy " << cached_file + " to " + dest_dir << endl; + // try next cache + continue; + } + + got_from_cache = true; + break; } - - got_from_cache = true; - break; + } + else + { + // File exists in cache but with a different checksum + // so just try next cache + continue; } } else { - // File exists in cache but with a different checksum - // so just try next cache + // skip bad cache directory and try with next one + ERR << "Skipping cache : " << *it_cache << endl; continue; } } - else - { - // skip bad cache directory and try with next one - ERR << "Skipping cache : " << *it_cache << endl; - continue; - } - } - - if ( ! got_from_cache ) - { - // try to get the file from the net - try + + if ( ! got_from_cache ) { - Pathname tmp_file = media.provideFile(*it_res); - Pathname dest_full_path = dest_dir + (*it_res).filename(); - if ( assert_dir( dest_full_path.dirname() ) != 0 ) - ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString())); - if ( filesystem::copy(tmp_file, dest_full_path ) != 0 ) + // try to get the file from the net + try { - ZYPP_THROW( Exception("Can't copy " + tmp_file.asString() + " to " + dest_dir.asString())); + Pathname tmp_file = media.provideFile((*it_res).location); + Pathname dest_full_path = dest_dir + (*it_res).location.filename(); + if ( assert_dir( dest_full_path.dirname() ) != 0 ) + ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString())); + if ( filesystem::copy(tmp_file, dest_full_path ) != 0 ) + { + ZYPP_THROW( Exception("Can't copy " + tmp_file.asString() + " to " + dest_dir.asString())); + } + } + catch (const Exception & excpt_r) + { + ZYPP_CAUGHT(excpt_r); + ZYPP_THROW(Exception("Can't provide " + (*it_res).location.filename().asString() + " : " + excpt_r.msg() )); } } - catch (const Exception & excpt_r) + else { - ZYPP_CAUGHT(excpt_r); - ZYPP_THROW(Exception("Can't provide " + (*it_res).filename().asString() + " : " + excpt_r.msg() )); + // We got the file from cache + // continue with next file + continue; } } - else - { - // We got the file from cache - // continue with next file - continue; - } } -} + + /** \relates Fetcher::Impl Stream output */ + inline std::ostream & operator<<( std::ostream & str, const Fetcher::Impl & obj ) + { + return str << "Fetcher::Impl"; + } + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : Fetcher + // + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : Fetcher::Fetcher + // METHOD TYPE : Ctor + // + Fetcher::Fetcher() + : _pimpl( Impl::nullimpl() ) + {} + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : Fetcher::~Fetcher + // METHOD TYPE : Dtor + // + Fetcher::~Fetcher() + {} + + void Fetcher::enqueue( const OnMediaLocation &resource ) + { + _pimpl->enqueue(resource); + } + + void Fetcher::addCachePath( const Pathname &cache_dir ) + { + _pimpl->addCachePath(cache_dir); + } + + void Fetcher::reset() + { + _pimpl->reset(); + } + + void Fetcher::start( const Pathname &dest_dir, MediaSetAccess &media ) + { + _pimpl->start(dest_dir, media); + } + + + /****************************************************************** + ** + ** FUNCTION NAME : operator<< + ** FUNCTION TYPE : std::ostream & + */ + std::ostream & operator<<( std::ostream & str, const Fetcher & obj ) + { + return str << *obj._pimpl; + } + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// + // callback::SendReport<DigestReport> report; // if ( checksum.empty() ) // { @@ -142,4 +252,3 @@ // ZYPP_THROW(SourceMetadataException( file_url.asString() + " " + N_(" fails checksum verification.") )); // } -} // namespace zypp Modified: trunk/libzypp/zypp/Fetcher.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/Fetcher.h?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/zypp/Fetcher.h (original) +++ trunk/libzypp/zypp/Fetcher.h Mon May 21 10:27:31 2007 @@ -6,20 +6,25 @@ | /_____||_| |_| |_| | | | \---------------------------------------------------------------------*/ - +/** \file zypp/Fetcher.h + * +*/ #ifndef ZYPP_FETCHER_H #define ZYPP_FETCHER_H -#include <list> +#include <iosfwd> + +#include "zypp/base/PtrTypes.h" #include "zypp/Pathname.h" #include "zypp/Url.h" #include "zypp/OnMediaLocation.h" #include "zypp/MediaSetAccess.h" +/////////////////////////////////////////////////////////////////// namespace zypp -{ +{ ///////////////////////////////////////////////////////////////// - /** + /** * This class allows to retrieve a group of files which can * be cached already on the local disk. * @@ -34,13 +39,20 @@ */ class Fetcher { + friend std::ostream & operator<<( std::ostream & str, const Fetcher & obj ); + public: - /** - * Constructor - */ + /** Implementation */ + class Impl; + + public: + /** Default ctor */ Fetcher(); + /** Dtor */ + ~Fetcher(); - /** + public: + /** * Enqueue a object for transferal, they will not * be transfered until \ref start() is called */ @@ -66,9 +78,15 @@ void start( const Pathname &dest_dir, MediaSetAccess &media ); private: - std::list<OnMediaLocation> _resources; - std::list<Pathname> _caches; + /** Pointer to implementation */ + RWCOW_pointer<Impl> _pimpl; }; + /////////////////////////////////////////////////////////////////// + + /** \relates Fetcher Stream output */ + std::ostream & operator<<( std::ostream & str, const Fetcher & obj ); -} // ns zypp -#endif + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_FETCHER_H Modified: trunk/libzypp/zypp/MediaSetAccess.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/MediaSetAccess.cc?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/zypp/MediaSetAccess.cc (original) +++ trunk/libzypp/zypp/MediaSetAccess.cc Mon May 21 10:27:31 2007 @@ -109,6 +109,11 @@ } + bool MediaSetAccess::doesFileExist(const Pathname & file, unsigned media_nr ) + { + return false; + } + Pathname MediaSetAccess::provideFile(const Pathname & file, unsigned media_nr, FileChecker checker ) { Pathname p = provideFileInternal( file, media_nr, false, false); @@ -120,7 +125,6 @@ return p; } - Pathname MediaSetAccess::provideFileInternal(const Pathname & file, unsigned media_nr, bool cached, bool checkonly ) { callback::SendReportmedia::MediaChangeReport report; Modified: trunk/libzypp/zypp/MediaSetAccess.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/MediaSetAccess.h?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/zypp/MediaSetAccess.h (original) +++ trunk/libzypp/zypp/MediaSetAccess.h Mon May 21 10:27:31 2007 @@ -128,6 +128,14 @@ Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker ); /** + * check if a file exists on the specified media + * + * \param file file to check + * \param media_nr Media number + */ + bool doesFileExist(const Pathname & file, unsigned media_nr ); + + /** * Replaces media number in specified url with given \a medianr. * * Media number in the URL is searched for with regex Modified: trunk/libzypp/zypp/source/yum/YUMDownloader.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/source/yum/YUMDownloader.cc?rev=5577&r1=5576&r2=5577&view=diff ============================================================================== --- trunk/libzypp/zypp/source/yum/YUMDownloader.cc (original) +++ trunk/libzypp/zypp/source/yum/YUMDownloader.cc Mon May 21 10:27:31 2007 @@ -64,6 +64,9 @@ _dest_dir = dest_dir; _fetcher.enqueue( OnMediaLocation().filename("/repodata/repomd.xml") ); _fetcher.start( dest_dir, _media); + + //if ( _media.doesFile + _fetcher.reset(); Reader reader( dest_dir + "/repodata/repomd.xml" ); -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org