--- Note: this changes the abi, so a version bump is in order. zypp/Fetcher.cc | 52 ++++++++++++++++++++++++++++++++++------------------ zypp/Fetcher.h | 17 +++++++++++++---- 2 files changed, 47 insertions(+), 22 deletions(-) diff --git a/zypp/Fetcher.cc b/zypp/Fetcher.cc index 14b2325..c0c9820 100644 --- a/zypp/Fetcher.cc +++ b/zypp/Fetcher.cc @@ -88,6 +88,7 @@ namespace zypp // check checksums even if there is no such // checksum (warns of no checksum) AlwaysVerifyChecksum = 0x0004, + Cancelled = 0x0008, }; ZYPP_DECLARE_FLAGS(Flags, Flag); @@ -111,7 +112,6 @@ namespace zypp }; ZYPP_DECLARE_OPERATORS_FOR_FLAGS(FetcherJob::Flags); - typedef shared_ptr<FetcherJob> FetcherJob_Ptr; std::ostream & operator<<( std::ostream & str, const FetcherJob_Ptr & obj ) { @@ -137,12 +137,13 @@ namespace zypp void addIndex( const OnMediaLocation &resource ); - void enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() ); - void enqueueDigestedDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() ); + FetcherJob_Ptr enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() ); + FetcherJob_Ptr enqueueDigestedDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() ); - void enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); - void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); + FetcherJob_Ptr enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); + FetcherJob_Ptr enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); void addCachePath( const Pathname &cache_dir ); + void cancelJob(FetcherJob_Ptr job); void reset(); void start( const Pathname &dest_dir, MediaSetAccess &media, @@ -232,12 +233,13 @@ namespace zypp }; /////////////////////////////////////////////////////////////////// - void Fetcher::Impl::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker ) + FetcherJob_Ptr Fetcher::Impl::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker ) { FetcherJob_Ptr job; job.reset(new FetcherJob(resource)); job->flags |= FetcherJob:: AlwaysVerifyChecksum; _resources.push_back(job); + return job; } Fetcher::Impl::Impl() @@ -251,7 +253,7 @@ namespace zypp Fetcher::Options Fetcher::Impl::options() const { return _options; } - void Fetcher::Impl::enqueueDir( const OnMediaLocation &resource, + FetcherJob_Ptr Fetcher::Impl::enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker ) { @@ -264,9 +266,10 @@ namespace zypp job->flags |= FetcherJob::Directory; _resources.push_back(job); + return job; } - void Fetcher::Impl::enqueueDigestedDir( const OnMediaLocation &resource, + FetcherJob_Ptr Fetcher::Impl::enqueueDigestedDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker ) { @@ -280,16 +283,17 @@ namespace zypp job->flags |= FetcherJob::AlwaysVerifyChecksum; _resources.push_back(job); - + return job; } - void Fetcher::Impl::enqueue( const OnMediaLocation &resource, const FileChecker &checker ) + FetcherJob_Ptr Fetcher::Impl::enqueue( const OnMediaLocation &resource, const FileChecker &checker ) { FetcherJob_Ptr job; job.reset(new FetcherJob(resource)); if ( checker ) job->checkers.push_back(checker); _resources.push_back(job); + return job; } void Fetcher::Impl::addIndex( const OnMediaLocation &resource ) @@ -330,6 +334,11 @@ namespace zypp } + void Fetcher::Impl::cancelJob(FetcherJob_Ptr job) + { + job->flags |= FetcherJob::Cancelled; + } + // tries to provide resource to dest_dir from any of the configured additional // cache paths where the file may already be present. returns true if the // file was provided from the cache. @@ -750,6 +759,8 @@ namespace zypp for ( list<FetcherJob_Ptr>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res ) { + if ( (*it_res)->flags & FetcherJob::Cancelled ) + continue; if ( (*it_res)->flags & FetcherJob::Directory ) { const OnMediaLocation location((*it_res)->location); @@ -860,23 +871,23 @@ namespace zypp return _pimpl->options(); } - void Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker ) + FetcherJob_Ptr Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker ) { - _pimpl->enqueueDigested(resource, checker); + return _pimpl->enqueueDigested(resource, checker); } - void Fetcher::enqueueDir( const OnMediaLocation &resource, + FetcherJob_Ptr Fetcher::enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker ) { - _pimpl->enqueueDir(resource, recursive, checker); + return _pimpl->enqueueDir(resource, recursive, checker); } - void Fetcher::enqueueDigestedDir( const OnMediaLocation &resource, + FetcherJob_Ptr Fetcher::enqueueDigestedDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker ) { - _pimpl->enqueueDigestedDir(resource, recursive, checker); + return _pimpl->enqueueDigestedDir(resource, recursive, checker); } @@ -886,9 +897,9 @@ namespace zypp } - void Fetcher::enqueue( const OnMediaLocation &resource, const FileChecker &checker ) + FetcherJob_Ptr Fetcher::enqueue( const OnMediaLocation &resource, const FileChecker &checker ) { - _pimpl->enqueue(resource, checker); + return _pimpl->enqueue(resource, checker); } void Fetcher::addCachePath( const Pathname &cache_dir ) @@ -896,6 +907,11 @@ namespace zypp _pimpl->addCachePath(cache_dir); } + void Fetcher::cancelJob(FetcherJob_Ptr job) + { + _pimpl->cancelJob(job); + } + void Fetcher::reset() { _pimpl->reset(); diff --git a/zypp/Fetcher.h b/zypp/Fetcher.h index 90babd8..4e407a5 100644 --- a/zypp/Fetcher.h +++ b/zypp/Fetcher.h @@ -29,6 +29,9 @@ namespace zypp { ///////////////////////////////////////////////////////////////// + class FetcherJob; + typedef shared_ptr<FetcherJob> FetcherJob_Ptr; + /** * This class allows to retrieve a group of files in a confortable * way, providing some smartness that does not belong to the @@ -102,6 +105,7 @@ namespace zypp public: /** Implementation */ class Impl; + public: /** @@ -177,7 +181,7 @@ namespace zypp * be transfered until \ref start() is called * */ - void enqueue( const OnMediaLocation &resource, + FetcherJob_Ptr enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); /** @@ -191,7 +195,7 @@ namespace zypp * * \todo FIXME implement checker == operator to avoid this. */ - void enqueueDigested( const OnMediaLocation &resource, + FetcherJob_Ptr enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() ); @@ -234,7 +238,7 @@ namespace zypp * not be transfered and will be ignored. * */ - void enqueueDir( const OnMediaLocation &resource, + FetcherJob_Ptr enqueueDir( const OnMediaLocation &resource, bool recursive = false, const FileChecker &checker = FileChecker() ); @@ -278,7 +282,7 @@ namespace zypp * not be transfered and will be ignored. * */ - void enqueueDigestedDir( const OnMediaLocation &resource, + FetcherJob_Ptr enqueueDigestedDir( const OnMediaLocation &resource, bool recursive = false, const FileChecker &checker = FileChecker() ); @@ -287,6 +291,11 @@ namespace zypp * where to look for cached files */ void addCachePath( const Pathname &cache_dir ); + + /** + * Cancels a previously enqueued job + */ + void cancelJob(FetcherJob_Ptr job); /** * Reset the transfer (jobs) list -- 1.7.0.3 -- To unsubscribe, e-mail: zypp-devel+unsubscribe@opensuse.org For additional commands, e-mail: zypp-devel+help@opensuse.org