From 9ab00976e71935df78c5eff11c6caa6913b3b5bb Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Fri, 15 Feb 2008 12:58:44 +0000 Subject: [PATCH] - merge Stano's patch to keep downloaded rpms --- zypp/Fetcher.cc | 29 ++++++++++++++++++++--------- zypp/RepoInfo.cc | 24 ++++++++++++++++++++++++ zypp/RepoInfo.h | 28 ++++++++++++++++++++++++++++ zypp/RepoManager.cc | 27 ++++++++++++++++++++++++--- zypp/RepoManager.h | 1 + zypp/ZConfig.cc | 11 +++++++++++ zypp/ZConfig.h | 5 +++++ zypp/parser/RepoFileReader.cc | 2 ++ zypp/repo/RepoProvideFile.cc | 16 ++++++++++++++-- 9 files changed, 129 insertions(+), 14 deletions(-) diff --git a/zypp/Fetcher.cc b/zypp/Fetcher.cc index 31e4903..fd444ac 100644 --- a/zypp/Fetcher.cc +++ b/zypp/Fetcher.cc @@ -139,8 +139,13 @@ namespace zypp { // does the current file exists in the current cache? Pathname cached_file = *it_cache + (*it_res)->location.filename(); + + MIL << "Trying cached file: " << cached_file << endl; + if ( PathInfo( cached_file ).isExist() ) { + MIL << "File exist, testing checksum " << (*it_res)->location.checksum() << endl; + // check the checksum if ( is_checksum( cached_file, (*it_res)->location.checksum() ) && (! (*it_res)->location.checksum().empty() ) ) { @@ -151,16 +156,20 @@ namespace zypp // 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( dest_full_path != cached_file ) + { + 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; - } + 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; @@ -170,6 +179,8 @@ namespace zypp if ( ! got_from_cache ) { + MIL << "Not found in cache, downloading" << endl; + // try to get the file from the net try { diff --git a/zypp/RepoInfo.cc b/zypp/RepoInfo.cc index 7257973..66473b9 100644 --- a/zypp/RepoInfo.cc +++ b/zypp/RepoInfo.cc @@ -33,6 +33,7 @@ namespace zypp : enabled (false), autorefresh(false), gpgcheck(true), + keeppackages(false), type(repo::RepoType::NONE_e) {} @@ -44,6 +45,7 @@ namespace zypp bool enabled; bool autorefresh; bool gpgcheck; + bool keeppackages; Url gpgkey_url; repo::RepoType type; Url mirrorlist_url; @@ -54,6 +56,7 @@ namespace zypp std::string name; Pathname filepath; Pathname metadatapath; + Pathname packagespath; public: private: @@ -185,6 +188,18 @@ namespace zypp return *this; } + RepoInfo & RepoInfo::setPackagesPath( const Pathname &path ) + { + _pimpl->packagespath = path; + return *this; + } + + RepoInfo & RepoInfo::setKeepPackages( bool keep ) + { + _pimpl->keeppackages = keep; + return *this; + } + bool RepoInfo::enabled() const { return _pimpl->enabled; } @@ -217,6 +232,9 @@ namespace zypp Pathname RepoInfo::metadataPath() const { return _pimpl->metadatapath; } + Pathname RepoInfo::packagesPath() const + { return _pimpl->packagespath; } + repo::RepoType RepoInfo::type() const { return _pimpl->type; } @@ -264,6 +282,9 @@ namespace zypp bool RepoInfo::baseUrlsEmpty() const { return _pimpl->baseUrls.empty(); } + bool RepoInfo::keepPackages() const + { return _pimpl->keeppackages; } + std::ostream & RepoInfo::dumpOn( std::ostream & str ) const { str << "--------------------------------------" << std::endl; @@ -281,6 +302,7 @@ namespace zypp str << "- autorefresh : " << autorefresh() << std::endl; str << "- gpgcheck : " << gpgCheck() << std::endl; str << "- gpgkey : " << gpgKeyUrl() << std::endl; + str << "- keeppackages : " << keepPackages() << std::endl; return str; } @@ -312,6 +334,8 @@ namespace zypp str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl; if ( ! (gpgKeyUrl().asString().empty()) ) str << "gpgkey=" <cfg_metadata_path ); } + Pathname ZConfig::repoPackagesPath() const + { + return ( _pimpl->cfg_packages_path.empty() + ? Pathname("/var/cache/zypp/packages") : _pimpl->cfg_packages_path ); + } + Pathname ZConfig::repoCachePath() const { return ( _pimpl->cfg_cache_path.empty() diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h index abb6528..ef2a8bb 100644 --- a/zypp/ZConfig.h +++ b/zypp/ZConfig.h @@ -93,6 +93,11 @@ namespace zypp Pathname repoMetadataPath() const; /** + * Path where the repo packages are downloaded and kept. + */ + Pathname repoPackagesPath() const; + + /** * Path where the processed cache is kept * (this is where zypp.db is located. */ diff --git a/zypp/parser/RepoFileReader.cc b/zypp/parser/RepoFileReader.cc index ff98834..4327511 100644 --- a/zypp/parser/RepoFileReader.cc +++ b/zypp/parser/RepoFileReader.cc @@ -69,6 +69,8 @@ namespace zypp info.setGpgKeyUrl( Url(it->second) ); else if ( it->first == "gpgcheck" ) info.setGpgCheck( it->second == "1" ); + else if ( it->first == "keeppackages" ) + info.setKeepPackages( it->second == "1" ); else ERR << "Unknown attribute " << it->second << " ignored" << endl; } diff --git a/zypp/repo/RepoProvideFile.cc b/zypp/repo/RepoProvideFile.cc index 52a8f8d..0ca120c 100644 --- a/zypp/repo/RepoProvideFile.cc +++ b/zypp/repo/RepoProvideFile.cc @@ -28,6 +28,7 @@ #include "zypp/repo/SUSEMediaVerifier.h" #include "zypp/repo/RepoException.h" #include "zypp/FileChecker.h" +#include "zypp/Fetcher.h" using std::endl; using std::set; @@ -214,7 +215,12 @@ namespace zypp repo_excpt.remember(RepoException(_("No url in repository."))); ZYPP_THROW(repo_excpt); } + + Fetcher fetcher; + fetcher.addCachePath( info.packagesPath() ); + MIL << "Added cache path " << info.packagesPath() << endl; + for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin(); it != info.baseUrlsEnd(); /* incremented in the loop */ ) @@ -227,11 +233,17 @@ namespace zypp << "' from " << url << endl; shared_ptr access = _impl->mediaAccessForUrl(url); _impl->setVerifierForRepo(repo_r, access); + + fetcher.enqueue( loc_r ); + + // FIXME: works for packages only + fetcher.start( info.packagesPath(), *access ); - ManagedFile ret( access->provideFile(loc_r) ); + // reached if no exception has been thrown, so this is the correct file + ManagedFile ret( info.packagesPath() + loc_r.filename() ); std::string scheme( url.getScheme() ); - if ( scheme == "http" || scheme == "https" || scheme == "ftp" ) + if ( !info.keepPackages() ) { ret.setDispose( filesystem::unlink ); } -- 2.7.4