From 89ed2774e82a62243070d488e98bf560cf0c40e4 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Tue, 4 Apr 2006 09:33:52 +0000 Subject: [PATCH] no feedback, tests passes, go on --- zypp/Package.cc | 15 +++++++----- zypp/Package.h | 8 ++++-- zypp/Source.cc | 6 +++-- zypp/Source.h | 3 +++ zypp/detail/PackageImplIf.cc | 3 +++ zypp/detail/PackageImplIf.h | 3 +++ zypp/source/SourceImpl.cc | 38 ++++++++++++++++++++++++++++- zypp/source/SourceImpl.h | 3 +++ zypp/source/susetags/SuseTagsPackageImpl.cc | 4 ++- zypp/source/susetags/SuseTagsPackageImpl.h | 2 +- zypp/target/TargetImpl.cc | 20 ++------------- zypp/target/TargetImpl.h | 3 --- zypp/target/store/XMLFilesBackend.cc | 7 +++++- 13 files changed, 80 insertions(+), 35 deletions(-) diff --git a/zypp/Package.cc b/zypp/Package.cc index 0e323f5..671f0c0 100644 --- a/zypp/Package.cc +++ b/zypp/Package.cc @@ -59,6 +59,9 @@ namespace zypp std::string Package::buildhost() const { return pimpl().buildhost(); } + CheckSum Package::checksum() const + { return pimpl().checksum(); } + /** */ std::string Package::distribution() const { return pimpl().distribution(); } @@ -129,8 +132,8 @@ namespace zypp { return pimpl().licenseToConfirm(); } /** */ - Pathname Package::plainRpm() const - { return pimpl().location(); } + //Pathname Package::plainRpm() const + //{ return pimpl().location(); } /** */ std::list Package::patchRpms() const @@ -141,8 +144,8 @@ namespace zypp { return pimpl().deltaRpms(); } /** */ - Pathname Package::getPlainRpm() const - { return source().provideFile(plainRpm(), mediaId()); } + //Pathname Package::getPlainRpm() const + //{ return source().provideFile(plainRpm(), mediaId()); } /** */ Pathname Package::getDeltaRpm(BaseVersion & base_r) const @@ -156,7 +159,7 @@ namespace zypp return source().provideFile(it->filename()); } ZYPP_THROW(Exception("No matching delta RPM found")); - return source().provideFile(plainRpm()); // never reached + return source().provideFile(location()); // never reached } /** */ @@ -175,7 +178,7 @@ namespace zypp } } ZYPP_THROW(Exception("No matching patch RPM found")); - return source().provideFile(plainRpm()); // never reached + return source().provideFile(location()); // never reached } bool Package::installOnly() const diff --git a/zypp/Package.h b/zypp/Package.h index e4623f3..6398f69 100644 --- a/zypp/Package.h +++ b/zypp/Package.h @@ -38,6 +38,10 @@ namespace zypp typedef TraitsType::constPtrType constPtr; public: + /** + * Checksum the source says this package should have + */ + CheckSum checksum() const; /** Time of package installation */ Date installtime() const; /** Get the package change log */ @@ -84,7 +88,7 @@ namespace zypp /** */ License licenseToConfirm() const; /** */ - Pathname plainRpm() const; + //Pathname plainRpm() const; /** */ std::list patchRpms() const; /** */ @@ -92,7 +96,7 @@ namespace zypp /** * \throws Exception */ - Pathname getPlainRpm() const; + //Pathname getPlainRpm() const; /** * \throws Exception */ diff --git a/zypp/Source.cc b/zypp/Source.cc index f2830a6..51e4329 100644 --- a/zypp/Source.cc +++ b/zypp/Source.cc @@ -65,10 +65,12 @@ namespace zypp { return _pimpl->provideFile(file_r, media_nr); } const Pathname Source_Ref::provideDirTree(const Pathname & dir_r, - const unsigned media_nr) - + const unsigned media_nr) { return _pimpl->provideDirTree(dir_r, media_nr); } + const Pathname Source_Ref::providePackage( Package::constPtr package ) + { return _pimpl->providePackage( package ); } + const void Source_Ref::releaseFile(const Pathname & file_r, const unsigned media_nr) { _pimpl->releaseFile(file_r, media_nr); } diff --git a/zypp/Source.h b/zypp/Source.h index 671fc2c..0de6b48 100644 --- a/zypp/Source.h +++ b/zypp/Source.h @@ -18,6 +18,7 @@ #include "zypp/base/PtrTypes.h" #include "zypp/base/SafeBool.h" +#include "zypp/Package.h" #include "zypp/Pathname.h" #include "zypp/Url.h" #include "zypp/Resolvable.h" @@ -83,6 +84,8 @@ namespace zypp /** All resolvables of a given kind provided by this source. */ const ResStore resolvables(zypp::Resolvable::Kind kind) const; + const Pathname providePackage( Package::constPtr package ); + /** Provide a file to local filesystem */ const Pathname provideFile(const Pathname & file_r, const unsigned media_nr = 1); diff --git a/zypp/detail/PackageImplIf.cc b/zypp/detail/PackageImplIf.cc index 34dc0a5..09bbbab 100644 --- a/zypp/detail/PackageImplIf.cc +++ b/zypp/detail/PackageImplIf.cc @@ -29,6 +29,9 @@ namespace zypp Date PackageImplIf::buildtime() const { return Date(); } + CheckSum PackageImplIf::checksum() const + { return CheckSum(); } + std::string PackageImplIf::buildhost() const { return std::string(); } diff --git a/zypp/detail/PackageImplIf.h b/zypp/detail/PackageImplIf.h index 9ccaae8..d308778 100644 --- a/zypp/detail/PackageImplIf.h +++ b/zypp/detail/PackageImplIf.h @@ -15,6 +15,7 @@ #include #include "zypp/detail/ResObjectImplIf.h" +#include "zypp/CheckSum.h" #include "zypp/Edition.h" #include "zypp/Arch.h" #include "zypp/Changelog.h" @@ -64,6 +65,8 @@ namespace zypp public: /** \name Rpm Package Attributes. */ //@{ + + virtual CheckSum checksum() const PURE_VIRTUAL; /** */ virtual Date buildtime() const PURE_VIRTUAL; /** */ diff --git a/zypp/source/SourceImpl.cc b/zypp/source/SourceImpl.cc index e5f506e..5491a61 100644 --- a/zypp/source/SourceImpl.cc +++ b/zypp/source/SourceImpl.cc @@ -10,8 +10,9 @@ * */ #include +#include #include "zypp/base/Logger.h" - +#include "zypp/Digest.h" #include "zypp/SourceFactory.h" #include "zypp/source/SourceImpl.h" #include "zypp/ZYppCallbacks.h" @@ -122,6 +123,41 @@ namespace zypp media_mgr.dirInfo( _media, retlist, path_r, dots ); } + const Pathname SourceImpl::providePackage( Package::constPtr package ) + { +#warning FIXME: error handling +#warning FIXME: Url + callback::SendReport report; + report->start( package, package->source().url() ); + Pathname file = package->source().provideFile( package->location(), package->mediaId()); + CheckSum checksum = package->checksum(); + std::string calculated_digest; + // check digest + try + { + std::ifstream is(file.asString().c_str(), std::ifstream::binary); + calculated_digest = Digest::digest(checksum.type(), is); + is.close(); + } + catch (std::exception &e) + { + ERR << "Can't open " << file << " for integrity check." << std::endl; + } + + if ( checksum.checksum() != calculated_digest ) + { + ZYPP_THROW(Exception("Package " + package->location().asString() + " fails integrity check. Expected: [" + checksum.checksum() + "] Read: [" + calculated_digest + "]")); + } + else + { + MIL << package->location() << " ok. [" << calculated_digest << "]" << std::endl; + } + + + report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" ); + return file; + } + const Pathname SourceImpl::provideFile(const Pathname & file_r, const unsigned media_nr, bool cached, diff --git a/zypp/source/SourceImpl.h b/zypp/source/SourceImpl.h index 7aedc51..b7870a0 100644 --- a/zypp/source/SourceImpl.h +++ b/zypp/source/SourceImpl.h @@ -115,6 +115,9 @@ namespace zypp const unsigned media_nr = 1, const bool recursive = false); + const Pathname providePackage( Package::constPtr package ); + const Pathname providePackageInteractive( Package::constPtr package ); + /** * Provide info about a directory * diff --git a/zypp/source/susetags/SuseTagsPackageImpl.cc b/zypp/source/susetags/SuseTagsPackageImpl.cc index 8f9b2d6..54cabc9 100644 --- a/zypp/source/susetags/SuseTagsPackageImpl.cc +++ b/zypp/source/susetags/SuseTagsPackageImpl.cc @@ -39,7 +39,9 @@ namespace zypp SuseTagsPackageImpl::~SuseTagsPackageImpl() {} - + CheckSum SuseTagsPackageImpl::checksum() const + { return _checksum; } + TranslatedText SuseTagsPackageImpl::summary() const { return _summary; } diff --git a/zypp/source/susetags/SuseTagsPackageImpl.h b/zypp/source/susetags/SuseTagsPackageImpl.h index 57a57ec..9710af0 100644 --- a/zypp/source/susetags/SuseTagsPackageImpl.h +++ b/zypp/source/susetags/SuseTagsPackageImpl.h @@ -41,7 +41,7 @@ namespace zypp //@{ virtual TranslatedText summary() const; virtual TranslatedText description() const; - + virtual CheckSum checksum() const; /** */ virtual Date buildtime() const; /** */ diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 1c3c7fc..cdc333d 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -138,22 +138,6 @@ namespace zypp return _store; } - - Pathname TargetImpl::getRpmFile(Package::constPtr package) - { - callback::SendReport report; - -#warning FIXME: error handling -#warning FIXME: Url - report->start( package, package->source().url() ); - - Pathname file = package->getPlainRpm(); - - report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" ); - - return file; - } - int TargetImpl::commit( ResPool pool_r, unsigned int medianr, TargetImpl::PoolItemList & errors_r, TargetImpl::PoolItemList & remaining_r, @@ -241,7 +225,7 @@ namespace zypp Package::constPtr p = dynamic_pointer_cast(it->resolvable()); if (it->status().isToBeInstalled()) { - Pathname localfile = getRpmFile( p ); + Pathname localfile = p->source().providePackage(p); lastUsedSource = p->source(); // remember the package source #warning Exception handling @@ -320,7 +304,7 @@ namespace zypp it->status().setTransact( false, ResStatus::USER ); } progress.disconnect(); - p->source().releaseFile( p->plainRpm(), p->mediaId() ); + p->source().releaseFile( p->location(), p->mediaId() ); } else { diff --git a/zypp/target/TargetImpl.h b/zypp/target/TargetImpl.h index 0fa8748..2b1a24b 100644 --- a/zypp/target/TargetImpl.h +++ b/zypp/target/TargetImpl.h @@ -129,9 +129,6 @@ namespace zypp private: /** Null implementation */ static TargetImpl_Ptr _nullimpl; - - /** wrapper with callback around getPlainRpm */ - Pathname getRpmFile(Package::constPtr package); }; /////////////////////////////////////////////////////////////////// diff --git a/zypp/target/store/XMLFilesBackend.cc b/zypp/target/store/XMLFilesBackend.cc index 1782c7f..70ed554 100644 --- a/zypp/target/store/XMLFilesBackend.cc +++ b/zypp/target/store/XMLFilesBackend.cc @@ -515,7 +515,12 @@ XMLFilesBackend::deleteObject( ResObject::constPtr resolvable ) std::string filename = fullPathForResolvable(resolvable); try { - remove(path(filename)); + int ret = filesystem::unlink(Pathname(filename)); + if ( ret != 0 ) + { + ERR << "Error removing resolvable " << resolvable << std::endl; + ZYPP_THROW(Exception("Error deleting " + filename)); + } } catch(std::exception &e) { -- 2.7.4