From bf3f93e6d60969f1d93ee148976de50c6c1f401c Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 26 Feb 2007 09:39:39 +0000 Subject: [PATCH] - some plays trying to deal with ids in the store API - Clean MediaSetAccess, now it can be used!, well, getPossiblyCachedFile is not, but at least you can download stuff. - a test file in my devel dir to test media set access - Put the suse media verifier in its own file - move ProvideFilePolicy to zypp/ so it can be used by MediaSetAccess later - Make media set access use OnMediaLocation too. --- devel/devel.dmacvicar/CMakeLists.txt | 34 +++++++------ devel/devel.dmacvicar/mediaaccess.cc | 69 +++++++++++++++++++++++++ zypp/CMakeLists.txt | 7 ++- zypp/MediaSetAccess.cc | 97 +++++++++++++++++++----------------- zypp/MediaSetAccess.h | 44 ++++++++-------- zypp/ProvideFilePolicy.cc | 60 ++++++++++++++++++++++ zypp/ProvideFilePolicy.h | 65 ++++++++++++++++++++++++ zypp/data/RecordId.cc | 4 ++ zypp/data/RecordId.h | 16 ++++++ zypp/data/ResolvableData.cc | 1 + zypp/data/ResolvableData.h | 58 ++++++++++++++------- zypp/source/OnMediaLocation.h | 7 ++- zypp/source/PackageProvider.cc | 6 +-- zypp/source/SUSEMediaVerifier.cc | 37 ++++++++++++++ zypp/source/SUSEMediaVerifier.h | 31 ++++++++++++ zypp/source/SourceProvideFile.cc | 37 -------------- zypp/source/SourceProvideFile.h | 44 +--------------- zypp2/cache/CacheStore.cpp | 19 ++++--- zypp2/cache/CacheStore.h | 10 ++-- 19 files changed, 451 insertions(+), 195 deletions(-) create mode 100644 devel/devel.dmacvicar/mediaaccess.cc create mode 100644 zypp/ProvideFilePolicy.cc create mode 100644 zypp/ProvideFilePolicy.h create mode 100644 zypp/data/RecordId.cc create mode 100644 zypp/data/RecordId.h create mode 100644 zypp/source/SUSEMediaVerifier.cc create mode 100644 zypp/source/SUSEMediaVerifier.h diff --git a/devel/devel.dmacvicar/CMakeLists.txt b/devel/devel.dmacvicar/CMakeLists.txt index 5b05dcb..71aa282 100644 --- a/devel/devel.dmacvicar/CMakeLists.txt +++ b/devel/devel.dmacvicar/CMakeLists.txt @@ -7,9 +7,8 @@ SET(test_SRCS zypp-keyring.cc ) -ADD_EXECUTABLE(test ${test_SRCS}) - -TARGET_LINK_LIBRARIES(test zypp ) +#ADD_EXECUTABLE(test ${test_SRCS}) +#TARGET_LINK_LIBRARIES(test zypp ) ########### next target ############### @@ -17,8 +16,8 @@ SET(lock_SRCS zypp-lock.cc ) -ADD_EXECUTABLE(lock ${lock_SRCS}) -TARGET_LINK_LIBRARIES(lock zypp ) +#ADD_EXECUTABLE(lock ${lock_SRCS}) +#TARGET_LINK_LIBRARIES(lock zypp ) ########### next target ############### @@ -27,9 +26,8 @@ SET(testbed_SRCS testbed.cc ) -ADD_EXECUTABLE(testbed ${testbed_SRCS}) -TARGET_LINK_LIBRARIES(testbed zypp ) - +#ADD_EXECUTABLE(testbed ${testbed_SRCS}) +#TARGET_LINK_LIBRARIES(testbed zypp ) ########### next target ############### @@ -37,8 +35,8 @@ SET(aj_SRCS aj.cc ) -ADD_EXECUTABLE(aj ${aj_SRCS}) -TARGET_LINK_LIBRARIES(aj zypp ) +#ADD_EXECUTABLE(aj ${aj_SRCS}) +#TARGET_LINK_LIBRARIES(aj zypp ) ########### next target ############### @@ -47,8 +45,8 @@ SET(yumparser_SRCS yum-parser.cc ) -ADD_EXECUTABLE(yumparser ${yumparser_SRCS}) -TARGET_LINK_LIBRARIES(yumparser zypp ) +#ADD_EXECUTABLE(yumparser ${yumparser_SRCS}) +#TARGET_LINK_LIBRARIES(yumparser zypp ) ########### next target ############### @@ -57,6 +55,14 @@ SET(media_SRCS media-glob.cc ) -ADD_EXECUTABLE(media ${media_SRCS}) -TARGET_LINK_LIBRARIES(media zypp ) +#ADD_EXECUTABLE(media ${media_SRCS}) +#TARGET_LINK_LIBRARIES(media zypp ) + +########### next target ############### + +SET(mediaaccess_SRCS +mediaaccess.cc +) +ADD_EXECUTABLE(mediaaccess ${mediaaccess_SRCS}) +TARGET_LINK_LIBRARIES(mediaaccess zypp ) diff --git a/devel/devel.dmacvicar/mediaaccess.cc b/devel/devel.dmacvicar/mediaaccess.cc new file mode 100644 index 0000000..cddad60 --- /dev/null +++ b/devel/devel.dmacvicar/mediaaccess.cc @@ -0,0 +1,69 @@ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "zypp/Product.h" +#include "zypp/Package.h" + + +using namespace std; +using namespace zypp; +using namespace media; + +class SimpleVerifier : public zypp::media::MediaVerifierBase +{ + public: + + SimpleVerifier( const std::string &id ) + { + _media_id = id; + } + + virtual bool isDesiredMedia(const media::MediaAccessRef &ref) + { + return ref->doesFileExist(Pathname("/." + _media_id )); + } + + private: + std::string _media_id; + media::MediaNr _media_nr; +}; + +int main(int argc, char **argv) +{ + try + { + ZYpp::Ptr z = getZYpp(); + + MediaSetAccess access(Url("dir:/home/duncanmv/tmp/url/CD1"), "/"); + access.setVerifier( 1, media::MediaVerifierRef( + new SimpleVerifier("cd1") ) + ); + access.setVerifier( 2, media::MediaVerifierRef( + new SimpleVerifier("cd2") ) + ); + access.setVerifier( 3, media::MediaVerifierRef( + new SimpleVerifier("cd3") ) + ); + + Pathname file1 = access.provideFile("/hello.text", 1 ); + Pathname file2 = access.provideFile("/hello.text", 2 ); + Pathname file3 = access.provideFile("/hello.text", 3 ); + } + catch ( const Exception &e ) + { + ERR << "ups! " << e.msg() << std::endl; + } + return 0; +} + + + diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index 5ddff17..6cd8618 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -47,6 +47,7 @@ SET( zypp_SRCS PoolItem.cc ProblemSolution.cc Product.cc + ProvideFilePolicy.cc PublicKey.cc Range.cc Rel.cc @@ -131,6 +132,7 @@ SET( zypp_HEADERS ProblemSolution.h ProblemTypes.h Product.h + ProvideFilePolicy.h PublicKey.h Range.h Rel.h @@ -266,11 +268,13 @@ INSTALL( FILES SET( zypp_data_SRCS data/ResolvableData.cc + data/RecordId.cc data/ResolvableDataConsumer.cc ) SET( zypp_data_HEADERS data/ResolvableData.h + data/RecordId.h data/ResolvableDataConsumer.h ) @@ -625,6 +629,7 @@ SET( zypp_source_SRCS source/SourceImpl.cc source/SourceInfo.cc source/SourceProvideFile.cc + source/SUSEMediaVerifier.cc ) SET( zypp_source_HEADERS @@ -637,6 +642,7 @@ SET( zypp_source_HEADERS source/SourceImpl.h source/SourceInfo.h source/SourceProvideFile.h + source/SUSEMediaVerifier.h ) INSTALL( FILES @@ -928,7 +934,6 @@ INSTALL( FILES DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/zypp/detail ) - SET( zypp_lib_SRCS ${zypp_source_plaindir_SRCS} ${zypp_target_store_xml_SRCS} diff --git a/zypp/MediaSetAccess.cc b/zypp/MediaSetAccess.cc index ca26bfb..16f23c5 100644 --- a/zypp/MediaSetAccess.cc +++ b/zypp/MediaSetAccess.cc @@ -62,9 +62,26 @@ namespace zypp { } - void MediaSetAccess::setVerifiers( const std::vector &verifiers ) + + void MediaSetAccess::setVerifier( unsigned media_nr, media::MediaVerifierRef verifier ) { - _verifiers = verifiers; + if (_medias.find(media_nr) != _medias.end()) + { + // the media already exists, set theverifier + media::MediaAccessId id = _medias[media_nr]; + media::MediaManager media_mgr; + media_mgr.addVerifier( id, verifier ); + // remove any saved verifier for this media + _verifiers.erase(media_nr); + //if (! noattach && ! media_mgr.isAttached(id)) + //media_mgr.attach(id); + } + else + { + // save the verifier in the map, and set it when + // the media number is first attached + _verifiers[media_nr] = verifier; + } } // callback::SendReport report; @@ -100,6 +117,12 @@ namespace zypp } } + Pathname MediaSetAccess::provideFile( const source::OnMediaLocation & on_media_file ) + { + return provideFile( on_media_file.filename(), on_media_file.medianr() ); + } + + Pathname MediaSetAccess::provideFile(const Pathname & file, unsigned media_nr ) { return provideFileInternal( file, media_nr, false, false); @@ -151,7 +174,7 @@ namespace zypp MIL << "Failed to release media " << media << endl; } - MIL << "Releasing all medias of all sources" << endl; + MIL << "Releasing all _medias of all sources" << endl; try { //zypp::SourceManager::sourceManager()->releaseAllSources(); @@ -239,9 +262,9 @@ namespace zypp { media::MediaManager media_mgr; - if (medias.find(medianr) != medias.end()) + if (_medias.find(medianr) != _medias.end()) { - media::MediaAccessId id = medias[medianr]; + media::MediaAccessId id = _medias[medianr]; //if (! noattach && ! media_mgr.isAttached(id)) //media_mgr.attach(id); return id; @@ -249,21 +272,29 @@ namespace zypp Url url; url = rewriteUrl (_url, medianr); media::MediaAccessId id = media_mgr.open(url, _path); - //try { - // MIL << "Adding media verifier" << endl; - // media_mgr.delVerifier(id); - // media_mgr.addVerifier(id, _source.verifier(medianr)); - //} - //catch (const Exception & excpt_r) - //{ - // ZYPP_CAUGHT(excpt_r); - // WAR << "Verifier not found" << endl; - //} - medias[medianr] = id; - - //if (! noattach) - // media_mgr.attach(id); + _medias[medianr] = id; + try + { + if (_verifiers.find(medianr) != _verifiers.end()) + { + // there is a setted verifier for this media + // FIXME check the case where the verifier exists + // but we have no access id for the media + media::MediaAccessId id = _medias[medianr]; + media::MediaManager media_mgr; + media_mgr.delVerifier(id); + media_mgr.addVerifier( id, _verifiers[medianr] ); + // remove any saved verifier for this media + _verifiers.erase(medianr); + } + } + catch ( const Exception &e ) + { + ZYPP_CAUGHT(e); + WAR << "Verifier not found" << endl; + } + return id; } @@ -314,32 +345,6 @@ namespace zypp // media::MediaVerifierRef MediaSetAccess::verifier(unsigned media_nr) // { return media::MediaVerifierRef(new media::NoVerifier()); } - MediaVerifier::MediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr) - : _media_vendor(vendor_r) - , _media_id(id_r) - , _media_nr(media_nr) - {} - - bool MediaVerifier::isDesiredMedia(const media::MediaAccessRef &ref) - { - if (_media_vendor.empty() || _media_id.empty()) - return true; - - Pathname media_file = "/media." + str::numstring(_media_nr) + "/media"; - ref->provideFile (media_file); - media_file = ref->localPath(media_file); - std::ifstream str(media_file.asString().c_str()); - std::string vendor; - std::string id; - -#warning check the stream status - getline(str, vendor); - getline(str, id); - - return (vendor == _media_vendor && id == _media_id ); - } - - ///////////////////////////////////////////////////////////////// -} // namespace source +} // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/MediaSetAccess.h b/zypp/MediaSetAccess.h index 846be75..54a4004 100644 --- a/zypp/MediaSetAccess.h +++ b/zypp/MediaSetAccess.h @@ -21,6 +21,7 @@ #include "zypp/media/MediaManager.h" #include "zypp/Pathname.h" #include "zypp/CheckSum.h" +#include "zypp/source/OnMediaLocation.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -29,22 +30,6 @@ namespace zypp DEFINE_PTR_TYPE(MediaSetAccess); - class MediaVerifier : public zypp::media::MediaVerifierBase - { - public: - /** ctor */ - MediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1); - /** - * Check if the specified attached media contains - * the desired media number (e.g. SLES10 CD1). - */ - virtual bool isDesiredMedia(const media::MediaAccessRef &ref); - private: - std::string _media_vendor; - std::string _media_id; - media::MediaNr _media_nr; - }; - class OnMediaLocation { public: @@ -82,17 +67,33 @@ namespace zypp public: /** * creates a callback enabled media access for \param url and \param path. - * with only media no verified + * with only 1 media no verified */ MediaSetAccess( const Url &url, const Pathname &path ); ~MediaSetAccess(); + /** - * the media change callbacks depend on the verifiers given for each media. + * Sets a verifier for given media number */ - void setVerifiers( const std::vector &verifiers ); + void setVerifier( unsigned media_nr, media::MediaVerifierRef verifier ); + + /** + * provide a file fom a multiple media + */ + Pathname provideFile( const source::OnMediaLocation & on_media_file ); + + /** + * provides a file on multiple media which is possibly cached + * The cached_file is provided and the Checksums are compared. + * if they match, the cached one is copied to the destination directory + * if not the file is provided and copied to the destination directory. + */ + void providePossiblyCachedMetadataFile( const source::OnMediaLocation &file_on_media, const Pathname &destination, const Pathname &cached_file); + Pathname provideFile(const Pathname & file, unsigned media_nr = 1 ); Pathname provideFile(const Pathname & file, unsigned media_nr, const FileChecker checker ); void providePossiblyCachedMetadataFile( const Pathname &file_to_download, unsigned medianr, const Pathname &destination, const Pathname &cached_file, const CheckSum &checksum ); + protected: Pathname provideFileInternal(const Pathname & file, unsigned media_nr, bool checkonly, bool cached); Url rewriteUrl (const Url & url_r, const media::MediaNr medianr); @@ -101,10 +102,11 @@ namespace zypp private: Url _url; Pathname _path; - std::vector _verifiers; typedef std::map MediaMap; + typedef std::map VerifierMap; /** Mapping between each CD and Media Access ID */ - MediaMap medias; + MediaMap _medias; + VerifierMap _verifiers; }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/ProvideFilePolicy.cc b/zypp/ProvideFilePolicy.cc new file mode 100644 index 0000000..9eff514 --- /dev/null +++ b/zypp/ProvideFilePolicy.cc @@ -0,0 +1,60 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#include +#include +#include +#include "zypp/base/Logger.h" + +#include "zypp/ProvideFilePolicy.h" + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : ProvideFilePolicy + // + /////////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + namespace + { ///////////////////////////////////////////////////////////////// + + bool yes() { return true; } + bool no() { return false; } + + ///////////////////////////////////////////////////////////////// + } // namespace + /////////////////////////////////////////////////////////////////// + + ProvideFilePolicy & ProvideFilePolicy::failOnChecksumErrorCB( bool yesno_r ) + { + _failOnChecksumErrorCB = (yesno_r ? &yes : &no); + return *this; + } + + bool ProvideFilePolicy::progress( int value ) const + { + if ( _progressCB ) + return _progressCB( value ); + return true; + } + + bool ProvideFilePolicy::failOnChecksumError() const + { + if ( _failOnChecksumErrorCB ) + return _failOnChecksumErrorCB(); + return true; + } + +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/ProvideFilePolicy.h b/zypp/ProvideFilePolicy.h new file mode 100644 index 0000000..d57d048 --- /dev/null +++ b/zypp/ProvideFilePolicy.h @@ -0,0 +1,65 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_PROVIDEFILEPOLICY_H +#define ZYPP_PROVIDEFILEPOLICY_H + +#include + +#include "zypp/base/Function.h" +#include "zypp/base/Functional.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// +// CLASS NAME : ProvideFilePolicy + + /** Policy for \ref provideFile. + * Provides callback hooks for e.g progress reporting or + * behaviour on checksum failure. Provides default + * implementations if no callback is set. + */ + class ProvideFilePolicy + { + public: + /** Progress callback signature. */ + typedef function ProgressCB; + + /** Set callback. */ + ProvideFilePolicy & progressCB( ProgressCB progressCB_r ) + { _progressCB = progressCB_r; return *this; } + + /** Evaluate callback. */ + bool progress( int value ) const; + + public: + /** FailOnChecksumError callback signature. */ + typedef function FailOnChecksumErrorCB; + + /** Set callback. */ + ProvideFilePolicy & failOnChecksumErrorCB( FailOnChecksumErrorCB failOnChecksumErrorCB_r ) + { _failOnChecksumErrorCB = failOnChecksumErrorCB_r; return *this; } + + /** Set callback convenience. + * Let callback return \c yesno_r. + */ + ProvideFilePolicy & failOnChecksumErrorCB( bool yesno_r ); + + /** Evaluate callback. */ + bool failOnChecksumError() const; + + private: + FailOnChecksumErrorCB _failOnChecksumErrorCB; + ProgressCB _progressCB; + }; + +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_PROVIDEFILEPOLICY_H diff --git a/zypp/data/RecordId.cc b/zypp/data/RecordId.cc new file mode 100644 index 0000000..a5b8a11 --- /dev/null +++ b/zypp/data/RecordId.cc @@ -0,0 +1,4 @@ + +#include "zypp/data/RecordId.h" + + diff --git a/zypp/data/RecordId.h b/zypp/data/RecordId.h new file mode 100644 index 0000000..8414a60 --- /dev/null +++ b/zypp/data/RecordId.h @@ -0,0 +1,16 @@ + +#ifndef ZYPP_DATA_RECORDID_H +#define ZYPP_DATA_RECORDID_H + +namespace zypp +{ +namespace data +{ + +typedef long long RecordId; + +} +} + +#endif + diff --git a/zypp/data/ResolvableData.cc b/zypp/data/ResolvableData.cc index 3a6bc31..b63a806 100644 --- a/zypp/data/ResolvableData.cc +++ b/zypp/data/ResolvableData.cc @@ -83,6 +83,7 @@ std::ostream& operator<<(std::ostream& out, const Script& data) return out; } + std::ostream& operator<<(std::ostream& out, const Message& data) { out << "Message Data: " << endl diff --git a/zypp/data/ResolvableData.h b/zypp/data/ResolvableData.h index 8af90d7..53fa9d1 100644 --- a/zypp/data/ResolvableData.h +++ b/zypp/data/ResolvableData.h @@ -42,17 +42,36 @@ namespace data }; typedef std::list DependencyList; - - class ResObject : public base::ReferenceCounted, private base::NonCopyable + + class Resolvable : public base::ReferenceCounted, private base::NonCopyable + { + public: + Resolvable() + {}; + + std::string name; + Edition edition; + Arch arch; + + DependencyList provides; + DependencyList conflicts; + DependencyList obsoletes; + DependencyList freshens; + DependencyList requires; + DependencyList prerequires; + DependencyList recommends; + DependencyList suggests; + DependencyList supplements; + DependencyList enhances; + }; + //a + class ResObject : public Resolvable { public: ResObject() : source_media_nr(1), install_only(false) {} - std::string name; - Edition edition; - Arch arch; TranslatedText summary; TranslatedText description; @@ -74,17 +93,6 @@ namespace data Date build_time; Date install_time; - - DependencyList provides; - DependencyList conflicts; - DependencyList obsoletes; - DependencyList freshens; - DependencyList requires; - DependencyList prerequires; - DependencyList recommends; - DependencyList suggests; - DependencyList supplements; - DependencyList enhances; }; class AtomBase : public ResObject @@ -139,19 +147,29 @@ namespace data Patch() {}; }; + /* + * Data Object for Pattern + * resolvable + */ class Pattern : public ResObject { public: - Pattern() {}; + Pattern() + : user_visible(true) + {}; std::string default_; - std::string user_visible; + bool user_visible; TranslatedText category; std::string icon; std::string script; }; + /* + * Data Object for Product + * resolvable + */ class Product : public ResObject { public: @@ -168,6 +186,10 @@ namespace data std::string releasenotesurl; }; + /* + * Data Object for Package + * resolvable + */ class Package : public ResObject { public: diff --git a/zypp/source/OnMediaLocation.h b/zypp/source/OnMediaLocation.h index 4b676f5..381296f 100644 --- a/zypp/source/OnMediaLocation.h +++ b/zypp/source/OnMediaLocation.h @@ -29,7 +29,12 @@ namespace zypp // // CLASS NAME : OnMediaLocation // - /** */ + /** + * Describes a path ona certain media amongs as the information + * required to download it, like its media number, checksum and + * size. + * it does not specifies the URI of the file. + */ class OnMediaLocation { friend std::ostream & operator<<( std::ostream & str, const OnMediaLocation & obj ); diff --git a/zypp/source/PackageProvider.cc b/zypp/source/PackageProvider.cc index 43a8b1f..2cfccc3 100644 --- a/zypp/source/PackageProvider.cc +++ b/zypp/source/PackageProvider.cc @@ -163,7 +163,7 @@ namespace zypp .checksum( _package->checksum() ) .downloadsize( _package->archivesize() ); - source::ProvideFilePolicy policy; + ProvideFilePolicy policy; policy.progressCB( bind( &PackageProvider::progressPackageDownload, this, _1 ) ); policy.failOnChecksumErrorCB( bind( &PackageProvider::failOnChecksumError, this ) ); @@ -184,7 +184,7 @@ namespace zypp ManagedFile delta; try { - source::ProvideFilePolicy policy; + ProvideFilePolicy policy; policy.progressCB( bind( &PackageProvider::progressDeltaDownload, this, _1 ) ); delta = source::provideFile( _package->source(), delta_r.location(), policy ); } @@ -234,7 +234,7 @@ namespace zypp ManagedFile patch; try { - source::ProvideFilePolicy policy; + ProvideFilePolicy policy; policy.progressCB( bind( &PackageProvider::progressPatchDownload, this, _1 ) ); patch = source::provideFile( _package->source(), patch_r.location(), policy ); } diff --git a/zypp/source/SUSEMediaVerifier.cc b/zypp/source/SUSEMediaVerifier.cc new file mode 100644 index 0000000..3a3bbee --- /dev/null +++ b/zypp/source/SUSEMediaVerifier.cc @@ -0,0 +1,37 @@ + +#include +#include "zypp/source/SUSEMediaVerifier.h" + +using namespace std; + +namespace zypp +{ +namespace source +{ + +SUSEMediaVerifier::SUSEMediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr) + : _media_vendor(vendor_r) + , _media_id(id_r) + , _media_nr(media_nr) +{} + +bool SUSEMediaVerifier::isDesiredMedia(const media::MediaAccessRef &ref) +{ + if (_media_vendor.empty() || _media_id.empty()) + return true; + + Pathname media_file = "/media." + str::numstring(_media_nr) + "/media"; + ref->provideFile (media_file); + media_file = ref->localPath(media_file); + std::ifstream str(media_file.asString().c_str()); + std::string vendor; + std::string id; +#warning check the stream status + getline(str, vendor); + getline(str, id); + + return (vendor == _media_vendor && id == _media_id ); +} + +} +} diff --git a/zypp/source/SUSEMediaVerifier.h b/zypp/source/SUSEMediaVerifier.h new file mode 100644 index 0000000..4bc1ed0 --- /dev/null +++ b/zypp/source/SUSEMediaVerifier.h @@ -0,0 +1,31 @@ + +#ifndef ZYPP_SUSE_MEDIAVERIFIER_H +#define ZYPP_SUSE_MEDIAVERIFIER_H + +#include "zypp/media/MediaManager.h" +#include "zypp/media/MediaAccess.h" + +namespace zypp +{ + namespace source + { + + class SUSEMediaVerifier : public zypp::media::MediaVerifierBase + { + public: + /** ctor */ + SUSEMediaVerifier(const std::string & vendor_r, const std::string & id_r, const media::MediaNr media_nr = 1); + /** + * Check if the specified attached media contains + * the desired media number (e.g. SLES10 CD1). + */ + virtual bool isDesiredMedia(const media::MediaAccessRef &ref); + private: + std::string _media_vendor; + std::string _media_id; + media::MediaNr _media_nr; + }; + + } +} +#endif \ No newline at end of file diff --git a/zypp/source/SourceProvideFile.cc b/zypp/source/SourceProvideFile.cc index 2d8531d..3be04ac 100644 --- a/zypp/source/SourceProvideFile.cc +++ b/zypp/source/SourceProvideFile.cc @@ -28,43 +28,6 @@ namespace zypp /////////////////////////////////////////////////////////////////// // - // CLASS NAME : ProvideFilePolicy - // - /////////////////////////////////////////////////////////////////// - - /////////////////////////////////////////////////////////////////// - namespace - { ///////////////////////////////////////////////////////////////// - - bool yes() { return true; } - bool no() { return false; } - - ///////////////////////////////////////////////////////////////// - } // namespace - /////////////////////////////////////////////////////////////////// - - ProvideFilePolicy & ProvideFilePolicy::failOnChecksumErrorCB( bool yesno_r ) - { - _failOnChecksumErrorCB = (yesno_r ? &yes : &no); - return *this; - } - - bool ProvideFilePolicy::progress( int value ) const - { - if ( _progressCB ) - return _progressCB( value ); - return true; - } - - bool ProvideFilePolicy::failOnChecksumError() const - { - if ( _failOnChecksumErrorCB ) - return _failOnChecksumErrorCB(); - return true; - } - - /////////////////////////////////////////////////////////////////// - // // provideFile // /////////////////////////////////////////////////////////////////// diff --git a/zypp/source/SourceProvideFile.h b/zypp/source/SourceProvideFile.h index 665af5f..ed00ee2 100644 --- a/zypp/source/SourceProvideFile.h +++ b/zypp/source/SourceProvideFile.h @@ -19,6 +19,7 @@ #include "zypp/Source.h" #include "zypp/ManagedFile.h" #include "zypp/source/OnMediaLocation.h" +#include "zypp/ProvideFilePolicy.h" /////////////////////////////////////////////////////////////////// namespace zypp @@ -29,49 +30,6 @@ namespace zypp /////////////////////////////////////////////////////////////////// // - // CLASS NAME : ProvideFilePolicy - // - /** Policy for \ref provideFile. - * Provides callback hooks for e.g progress reporting or - * behaviour on checksum failure. Provides default - * implementations if no callback is set. - */ - class ProvideFilePolicy - { - public: - /** Progress callback signature. */ - typedef function ProgressCB; - - /** Set callback. */ - ProvideFilePolicy & progressCB( ProgressCB progressCB_r ) - { _progressCB = progressCB_r; return *this; } - - /** Evaluate callback. */ - bool progress( int value ) const; - - public: - /** FailOnChecksumError callback signature. */ - typedef function FailOnChecksumErrorCB; - - /** Set callback. */ - ProvideFilePolicy & failOnChecksumErrorCB( FailOnChecksumErrorCB failOnChecksumErrorCB_r ) - { _failOnChecksumErrorCB = failOnChecksumErrorCB_r; return *this; } - - /** Set callback convenience. - * Let callback return \c yesno_r. - */ - ProvideFilePolicy & failOnChecksumErrorCB( bool yesno_r ); - - /** Evaluate callback. */ - bool failOnChecksumError() const; - - private: - FailOnChecksumErrorCB _failOnChecksumErrorCB; - ProgressCB _progressCB; - }; - - /////////////////////////////////////////////////////////////////// - // // provideFile // /////////////////////////////////////////////////////////////////// diff --git a/zypp2/cache/CacheStore.cpp b/zypp2/cache/CacheStore.cpp index a3420fb..93a278f 100644 --- a/zypp2/cache/CacheStore.cpp +++ b/zypp2/cache/CacheStore.cpp @@ -1,4 +1,6 @@ +#include + #include "zypp/ZYppFactory.h" #include "zypp/ZYpp.h" @@ -34,7 +36,7 @@ namespace zypp /////////////////////////////////////////////////////////////////// namespace cache { ///////////////////////////////////////////////////////////////// - + CacheStore::CacheStore( const Pathname &dbdir ) { cache::CacheInitializer initializer(dbdir, "zypp.db"); @@ -71,11 +73,10 @@ CacheStore::~CacheStore() void CacheStore::consumePackage( const data::Package &package ) { - long long id = insertResObject( ResTraits::kind, package ); - + data::RecordId id = insertResObject( ResTraits::kind, package ); } -long long CacheStore::insertResObject( const Resolvable::Kind &kind, const data::ResObject &res ) +data::RecordId CacheStore::insertResObject( const Resolvable::Kind &kind, const data::ResObject &res ) { _insert_resolvable_cmd->bind(1, res.name.c_str(), -1); _insert_resolvable_cmd->bind(2, res.edition.version().c_str(), -1); @@ -98,18 +99,19 @@ long long CacheStore::insertResObject( const Resolvable::Kind &kind, const data: _insert_resolvable_cmd->bind(18, static_cast(res.build_time) ); // FIX cast? _insert_resolvable_cmd->bind(19, static_cast(res.install_time) ); // FIX cast? _insert_resolvable_cmd->executenonquery(); - return _con->insertid(); + return static_cast( _con->insertid() ); } -void CacheStore::insertPackage( long long id, const data::Package &pkg ) +void CacheStore::insertPackage( data::RecordId id, const data::Package &pkg ) { + sqlite_int64 sqid = static_cast(id); /* " resolvable_id, checksum, changelog, buildhost, distribution, license" \ " , packager, package_group, url, os, prein, postin, preun, postun, source_size" \ " , authors, filenames, location ) values ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );" */ - _insert_package_cmd->bind( 1, id ); + _insert_package_cmd->bind( 1, sqid ); _insert_package_cmd->bind( 2 ); //_insert_package_cmd->bind( 2, pkg.checksum.asString().c_str() ); _insert_package_cmd->bind( 3 ); @@ -119,4 +121,5 @@ void CacheStore::insertPackage( long long id, const data::Package &pkg ) } -} \ No newline at end of file +} + diff --git a/zypp2/cache/CacheStore.h b/zypp2/cache/CacheStore.h index 0482afb..02f86ca 100644 --- a/zypp2/cache/CacheStore.h +++ b/zypp2/cache/CacheStore.h @@ -18,6 +18,9 @@ #include "zypp/base/PtrTypes.h" #include "zypp/Pathname.h" #include "zypp/data/ResolvableDataConsumer.h" +#include "zypp/data/RecordId.h" + +#include "zypp/data/RecordId.h" #include "zypp2/cache/sqlite3x/sqlite3x.hpp" /////////////////////////////////////////////////////////////////// @@ -38,8 +41,8 @@ namespace zypp void consumePackage( const data::Package &package ); protected: - long long insertResObject( const Resolvable::Kind &kind, const data::ResObject &res ); - void insertPackage( long long id, const data::Package &package ); + data::RecordId insertResObject( const Resolvable::Kind &kind, const data::ResObject &res ); + void insertPackage( const data::RecordId id, const data::Package &package ); private: shared_ptr _con; @@ -50,4 +53,5 @@ namespace zypp } } -#endif \ No newline at end of file +#endif + -- 2.7.4