From 2285a310fd3860241302003f4a65cc7308b7bbae Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 19 Jul 2007 15:07:48 +0000 Subject: [PATCH] - Pass the media set to the Downloaders instead of having one in the object - Make Downloaders have a base class repo::Downloader this will allow to remove some code in RepoManager and interact with the downloader without knowing which type is it - Make Downloader base class inherit from fetcher, then you can set the cache directories to the downloader itself, which RepoManager will do --- tests/repo/susetags/Downloader_test.cc | 5 +-- tests/repo/yum/YUMDownloader_test.cc | 5 +-- zypp/CMakeLists.txt | 2 ++ zypp/Fetcher.h | 13 +++++--- zypp/RepoManager.cc | 14 ++++---- zypp/repo/Downloader.cc | 53 ++++++++++++++++++++++++++++++ zypp/repo/Downloader.h | 60 ++++++++++++++++++++++++++++++++++ zypp/repo/susetags/Downloader.cc | 38 ++++++++++----------- zypp/repo/susetags/Downloader.h | 30 ++++++++++++++--- zypp/repo/yum/Downloader.cc | 57 ++++++++++++++++++-------------- zypp/repo/yum/Downloader.h | 46 ++++++++++++++++---------- 11 files changed, 241 insertions(+), 82 deletions(-) create mode 100644 zypp/repo/Downloader.cc create mode 100644 zypp/repo/Downloader.h diff --git a/tests/repo/susetags/Downloader_test.cc b/tests/repo/susetags/Downloader_test.cc index 131d123..5ecea4e 100644 --- a/tests/repo/susetags/Downloader_test.cc +++ b/tests/repo/susetags/Downloader_test.cc @@ -25,12 +25,13 @@ void susetags_download_test(const string &dir) { Pathname p = dir + "/stable-x86-subset"; Url url("dir:" + p.asString()); - susetags::Downloader downloader(url, "/"); + MediaSetAccess media(url); + susetags::Downloader downloader("/"); filesystem::TmpDir tmp; Pathname localdir(tmp.path()); - downloader.download(localdir); + downloader.download(media,localdir); const char* files[] = { diff --git a/tests/repo/yum/YUMDownloader_test.cc b/tests/repo/yum/YUMDownloader_test.cc index 750076e..84e09b9 100644 --- a/tests/repo/yum/YUMDownloader_test.cc +++ b/tests/repo/yum/YUMDownloader_test.cc @@ -25,12 +25,13 @@ void yum_download_test(const string &dir) { Pathname p = dir + "/10.2-updates-subset"; Url url("dir:" + p.asString()); - yum::Downloader yum(url, "/"); + MediaSetAccess media(url); + yum::Downloader yum("/"); filesystem::TmpDir tmp; Pathname localdir(tmp.path()); - yum.download(localdir); + yum.download(media, localdir); const char* files[] = { diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index c641a65..2c26fb3 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -926,6 +926,7 @@ SET( zypp_repo_SRCS repo/PackageDelta.cc repo/SUSEMediaVerifier.cc repo/MediaInfoDownloader.cc + repo/Downloader.cc ) SET( zypp_repo_HEADERS @@ -939,6 +940,7 @@ SET( zypp_repo_HEADERS repo/PackageDelta.h repo/SUSEMediaVerifier.h repo/MediaInfoDownloader.h + repo/Downloader.h ) INSTALL( FILES diff --git a/zypp/Fetcher.h b/zypp/Fetcher.h index 73784e4..718d810 100644 --- a/zypp/Fetcher.h +++ b/zypp/Fetcher.h @@ -63,7 +63,8 @@ namespace zypp */ class Fetcher { - friend std::ostream & operator<<( std::ostream & str, const Fetcher & obj ); + friend std::ostream & operator<<( std::ostream & str, + const Fetcher & obj ); public: /** Implementation */ @@ -72,7 +73,7 @@ namespace zypp /** Default ctor */ Fetcher(); /** Dtor */ - ~Fetcher(); + virtual ~Fetcher(); public: /** @@ -80,7 +81,8 @@ namespace zypp * be transfered until \ref start() is called * */ - void enqueue( const OnMediaLocation &resource, const FileChecker &checker = NullFileChecker() ); + void enqueue( const OnMediaLocation &resource, + const FileChecker &checker = NullFileChecker() ); /** * Enqueue a object for transferal, they will not @@ -93,17 +95,20 @@ namespace zypp * * \todo FIXME implement checker == operator to avoid this. */ - void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = NullFileChecker() ); + void enqueueDigested( const OnMediaLocation &resource, + const FileChecker &checker = NullFileChecker() ); /** * adds a directory to the list of directories * where to look for cached files */ void addCachePath( const Pathname &cache_dir ); + /** * Reset the transfer list and cache list */ void reset(); + /** * start the transfer to a destination directory * \a dest_dir diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index e59c046..51ea6ea 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -347,9 +347,10 @@ namespace zypp { case RepoType::RPMMD_e : { - yum::Downloader downloader( url, "/" ); + MediaSetAccess media(url); + yum::Downloader downloader(info.path()); - RepoStatus newstatus = downloader.status(); + RepoStatus newstatus = downloader.status(media); bool refresh = false; if ( oldstatus.checksum() == newstatus.checksum() ) { @@ -366,7 +367,7 @@ namespace zypp } if ( refresh ) - downloader.download(tmpdir.path()); + downloader.download( media, tmpdir.path()); else return; // no error @@ -374,9 +375,10 @@ namespace zypp break; case RepoType::YAST2_e : { - susetags::Downloader downloader( url, "/" ); + MediaSetAccess media(url); + susetags::Downloader downloader(info.path()); - RepoStatus newstatus = downloader.status(); + RepoStatus newstatus = downloader.status(media); bool refresh = false; if ( oldstatus.checksum() == newstatus.checksum() ) { @@ -393,7 +395,7 @@ namespace zypp } if ( refresh ) - downloader.download(tmpdir.path()); + downloader.download(media, tmpdir.path()); else return; // no error diff --git a/zypp/repo/Downloader.cc b/zypp/repo/Downloader.cc new file mode 100644 index 0000000..9857646 --- /dev/null +++ b/zypp/repo/Downloader.cc @@ -0,0 +1,53 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#include +#include "zypp/base/String.h" +#include "zypp/base/Logger.h" +#include "zypp/base/Function.h" + +#include "zypp/Date.h" + +#include "Downloader.h" +#include "zypp/repo/MediaInfoDownloader.h" +#include "zypp/base/UserRequestException.h" + +using namespace std; + +namespace zypp +{ +namespace repo +{ + +Downloader::Downloader() +{ +} + +Downloader::~Downloader() +{ +} + +RepoStatus Downloader::status( MediaSetAccess &media ) +{ + WAR << "Non implemented" << endl; + return RepoStatus(); +} + +void Downloader::download( MediaSetAccess &media, + const Pathname &dest_dir, + const ProgressData::ReceiverFnc & progress ) +{ + WAR << "Non implemented" << endl; +} + +}// ns repo +} // ns zypp + + + diff --git a/zypp/repo/Downloader.h b/zypp/repo/Downloader.h new file mode 100644 index 0000000..9a11a4d --- /dev/null +++ b/zypp/repo/Downloader.h @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_REPO_DOWNLOADER +#define ZYPP_REPO_DOWNLOADER + +#include "zypp/Url.h" +#include "zypp/Pathname.h" +#include "zypp/ProgressData.h" +#include "zypp/RepoStatus.h" +#include "zypp/MediaSetAccess.h" +#include "zypp/Fetcher.h" + +namespace zypp +{ + namespace repo + { + /** + * \short Downloader base class + * + * a Downloader encapsulates all the knowledge of + * which files have to be downloaded to the local disk. + * + */ + class Downloader : public Fetcher + { + public: + /** + * \short Constructor + */ + Downloader(); + virtual ~Downloader(); + + /** + * \short Download metadata to a local directory + * + * \param media Media access to the repository url + * \param dest_dir Local destination directory + * \param progress progress receiver + */ + virtual void download( MediaSetAccess &media, + const Pathname &dest_dir, + const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); + /** + * \short Status of the remote repository + */ + virtual RepoStatus status( MediaSetAccess &media ); + + }; + + } // ns repo +} // ns zypp + +#endif diff --git a/zypp/repo/susetags/Downloader.cc b/zypp/repo/susetags/Downloader.cc index 4290e3c..709c4a9 100644 --- a/zypp/repo/susetags/Downloader.cc +++ b/zypp/repo/susetags/Downloader.cc @@ -18,24 +18,22 @@ namespace repo namespace susetags { -Downloader::Downloader( const Url &url, const Pathname &path ) - : _url(url), _path(path) +Downloader::Downloader(const Pathname &path ) + : _path(path) { } -RepoStatus Downloader::status() +RepoStatus Downloader::status( MediaSetAccess &media ) { - MediaSetAccess media(_url, _path); - Pathname content = media.provideFile("/content"); + Pathname content = media.provideFile( _path + "/content"); return RepoStatus(content); } -void Downloader::download( const Pathname &dest_dir, +void Downloader::download( MediaSetAccess &media, + const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress ) { - MediaSetAccess media(_url); - Fetcher fetcher; downloadMediaInfo( dest_dir, media ); SignatureFileChecker sigchecker; @@ -43,9 +41,9 @@ void Downloader::download( const Pathname &dest_dir, Pathname sig = _path + "/content.asc"; if ( media.doesFileExist(sig) ) { - fetcher.enqueue( OnMediaLocation( sig, 1 ) ); - fetcher.start( dest_dir, media ); - fetcher.reset(); + this->enqueue( OnMediaLocation( sig, 1 ) ); + this->start( dest_dir, media ); + this->reset(); sigchecker = SignatureFileChecker( dest_dir + sig ); } @@ -53,16 +51,16 @@ void Downloader::download( const Pathname &dest_dir, Pathname key = _path + "/content.key"; if ( media.doesFileExist(key) ) { - fetcher.enqueue( OnMediaLocation( key, 1 ) ); - fetcher.start( dest_dir, media ); - fetcher.reset(); + this->enqueue( OnMediaLocation( key, 1 ) ); + this->start( dest_dir, media ); + this->reset(); sigchecker.addPublicKey(dest_dir + key); } - fetcher.enqueue( OnMediaLocation( _path + "/content", 1 ), sigchecker ); - fetcher.start( dest_dir, media ); - fetcher.reset(); + this->enqueue( OnMediaLocation( _path + "/content", 1 ), sigchecker ); + this->start( dest_dir, media ); + this->reset(); std::ifstream file((dest_dir + _path + "/content").asString().c_str()); std::string buffer; @@ -93,7 +91,7 @@ void Downloader::download( const Pathname &dest_dir, } OnMediaLocation location( _path + descr_dir + words[3], 1 ); location.setChecksum( CheckSum( words[1], words[2] ) ); - fetcher.enqueueDigested(location); + this->enqueueDigested(location); } else if (buffer.substr( 0, 3 ) == "KEY") { @@ -105,11 +103,11 @@ void Downloader::download( const Pathname &dest_dir, } OnMediaLocation location( _path + words[3], 1 ); location.setChecksum( CheckSum( words[1], words[2] ) ); - fetcher.enqueueDigested(location); + this->enqueueDigested(location); } } file.close(); - fetcher.start( dest_dir, media ); + this->start( dest_dir, media ); } }// ns susetags diff --git a/zypp/repo/susetags/Downloader.h b/zypp/repo/susetags/Downloader.h index 07f4289..384f63b 100644 --- a/zypp/repo/susetags/Downloader.h +++ b/zypp/repo/susetags/Downloader.h @@ -14,6 +14,8 @@ #include "zypp/Pathname.h" #include "zypp/ProgressData.h" #include "zypp/RepoStatus.h" +#include "zypp/MediaSetAccess.h" +#include "zypp/repo/Downloader.h" namespace zypp { @@ -22,18 +24,36 @@ namespace zypp namespace susetags { - class Downloader + /** + * \short Downloader for SUSETags (YaST2) repositories + * Encapsulates all the knowledge of which files have + * to be downloaded to the local disk. + */ + class Downloader : public repo::Downloader { public: - Downloader( const Url &url, const Pathname &path ); - void download( const Pathname &dest_dir, + /** + * \short Constructor + * + * \param path Path to the repostory from the media + */ + Downloader( const Pathname &path ); + + /** + * \short Download metadata to a local directory + * + * \param media Media access to the repository url + * \param dest_dir Local destination directory + * \param progress progress receiver + */ + void download( MediaSetAccess &media, + const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); /** * \short Status of the remote repository */ - RepoStatus status(); + RepoStatus status( MediaSetAccess &media ); private: - Url _url; Pathname _path; }; diff --git a/zypp/repo/yum/Downloader.cc b/zypp/repo/yum/Downloader.cc index 83bef74..0bee6a3 100644 --- a/zypp/repo/yum/Downloader.cc +++ b/zypp/repo/yum/Downloader.cc @@ -19,6 +19,7 @@ #include "Downloader.h" #include "zypp/repo/MediaInfoDownloader.h" #include "zypp/base/UserRequestException.h" +#include "zypp/parser/xml/Reader.h" using namespace std; using namespace zypp::xml; @@ -31,26 +32,28 @@ namespace repo namespace yum { -Downloader::Downloader( const Url &url, const Pathname &path ) - : _url(url), _path(path), _media(url, path) +Downloader::Downloader( const Pathname &path ) + : _path(path), _media_ptr(0L) { } -RepoStatus Downloader::status() +RepoStatus Downloader::status( MediaSetAccess &media ) { - Pathname repomd = _media.provideFile("/repodata/repomd.xml"); + Pathname repomd = media.provideFile( _path + "/repodata/repomd.xml"); return RepoStatus(repomd); } -bool Downloader::patches_Callback( const OnMediaLocation &loc, const string &id ) +bool Downloader::patches_Callback( const OnMediaLocation &loc, + const string &id ) { MIL << id << " : " << loc << endl; - _fetcher.enqueueDigested(loc); + this->enqueueDigested(loc); return true; } -bool Downloader::repomd_Callback( const OnMediaLocation &loc, const ResourceType &dtype ) +bool Downloader::repomd_Callback( const OnMediaLocation &loc, + const ResourceType &dtype ) { MIL << dtype << " : " << loc << endl; @@ -61,28 +64,32 @@ bool Downloader::repomd_Callback( const OnMediaLocation &loc, const ResourceType return true; } - _fetcher.enqueueDigested(loc); + this->enqueueDigested(loc); // We got a patches file we need to read, to add patches listed // there, so we transfer what we have in the queue, and // queue the patches in the patches callback if ( dtype == ResourceType::PATCHES ) { - _fetcher.start( _dest_dir, _media); + this->start( _dest_dir, *_media_ptr ); // now the patches.xml file must exists - PatchesFileReader( _dest_dir + loc.filename(), bind( &Downloader::patches_Callback, this, _1, _2)); + PatchesFileReader( _dest_dir + _path + loc.filename(), + bind( &Downloader::patches_Callback, this, _1, _2)); } return true; } -void Downloader::download( const Pathname &dest_dir, +void Downloader::download( MediaSetAccess &media, + const Pathname &dest_dir, const ProgressData::ReceiverFnc & progressrcv ) { - Pathname repomdpath = "/repodata/repomd.xml"; - Pathname keypath = "/repodata/repomd.xml.key"; - Pathname sigpath = "/repodata/repomd.xml.asc"; + Pathname repomdpath = _path + "/repodata/repomd.xml"; + Pathname keypath = _path + "/repodata/repomd.xml.key"; + Pathname sigpath = _path + "/repodata/repomd.xml.asc"; + _media_ptr = (&media); + ProgressData progress; progress.sendTo(progressrcv); progress.toMin(); @@ -90,13 +97,13 @@ void Downloader::download( const Pathname &dest_dir, //downloadMediaInfo( dest_dir, _media ); _dest_dir = dest_dir; - if ( _media.doesFileExist(keypath) ) - _fetcher.enqueue( OnMediaLocation(keypath,1) ); + if ( _media_ptr->doesFileExist(keypath) ) + this->enqueue( OnMediaLocation(keypath,1) ); - if ( _media.doesFileExist(sigpath) ) - _fetcher.enqueue( OnMediaLocation(sigpath,1) ); + if ( _media_ptr->doesFileExist(sigpath) ) + this->enqueue( OnMediaLocation(sigpath,1) ); - _fetcher.start( dest_dir, _media ); + this->start( dest_dir, *_media_ptr ); if ( ! progress.tick() ) ZYPP_THROW(AbortRequestException()); @@ -109,19 +116,19 @@ void Downloader::download( const Pathname &dest_dir, if ( PathInfo( dest_dir + keypath ).isExist() ) sigchecker.addPublicKey(dest_dir + keypath ); - _fetcher.enqueue( OnMediaLocation(repomdpath,1), sigchecker ); - _fetcher.start( dest_dir, _media); + this->enqueue( OnMediaLocation(repomdpath,1), sigchecker ); + this->start( dest_dir, *_media_ptr); if ( ! progress.tick() ) ZYPP_THROW(AbortRequestException()); - _fetcher.reset(); + this->reset(); - Reader reader( dest_dir + "/repodata/repomd.xml" ); - RepomdFileReader( dest_dir + "/repodata/repomd.xml", bind( &Downloader::repomd_Callback, this, _1, _2)); + Reader reader( dest_dir + _path + "/repodata/repomd.xml" ); + RepomdFileReader( dest_dir + _path + "/repodata/repomd.xml", bind( &Downloader::repomd_Callback, this, _1, _2)); // ready, go! - _fetcher.start( dest_dir, _media); + this->start( dest_dir, *_media_ptr); progress.toMax(); } diff --git a/zypp/repo/yum/Downloader.h b/zypp/repo/yum/Downloader.h index 23184e3..186e2ac 100644 --- a/zypp/repo/yum/Downloader.h +++ b/zypp/repo/yum/Downloader.h @@ -15,10 +15,10 @@ #include "zypp/Fetcher.h" #include "zypp/OnMediaLocation.h" #include "zypp/MediaSetAccess.h" -#include "zypp/parser/xml/Reader.h" -#include "zypp/repo/yum/ResourceType.h" #include "zypp/ProgressData.h" #include "zypp/RepoStatus.h" +#include "zypp/repo/Downloader.h" +#include "zypp/repo/yum/ResourceType.h" namespace zypp { @@ -26,44 +26,54 @@ namespace zypp { namespace yum { - /** - * This class allows to retrieve a YUM repository - * to a local directory + /** + * \short Downloader for YUM (rpm-nmd) repositories + * Encapsulates all the knowledge of which files have + * to be downloaded to the local disk. * * \code - * Downloader yum(url, path); - * yum.download("localdir"); + * MediaSetAccess media(url); + * Downloader yum(path); + * yum.download( media, "localdir"); * \endcode */ - class Downloader + class Downloader : public repo::Downloader { public: + /** - * Create the download object for a repository - * located in \a url with path \a path - */ - Downloader( const Url &url, const Pathname &path ); + * \short Constructor + * + * \param path Path to the repostory from the media + */ + Downloader( const Pathname &path ); + /** - * starts the download to local directory \a dest_dir - */ - void download( const Pathname &dest_dir, + * \short Download metadata to a local directory + * + * \param media Media access to the repository url + * \param dest_dir Local destination directory + * \param progress progress receiver + */ + void download( MediaSetAccess &media, + const Pathname &dest_dir, const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() ); /** * \short Status of the remote repository */ - RepoStatus status(); + RepoStatus status( MediaSetAccess &media ); protected: bool repomd_Callback( const OnMediaLocation &loc, const ResourceType &dtype ); bool patches_Callback( const OnMediaLocation &loc, const std::string &id ); private: - Url _url; Pathname _path; Fetcher _fetcher; Pathname _dest_dir; std::list _patches_files; - MediaSetAccess _media; + + MediaSetAccess *_media_ptr; }; } // ns yum -- 2.7.4