From 2744f0be60e96db50ad1e2b3fc648f7427108433 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Mon, 20 Jul 2009 23:31:42 +0200 Subject: [PATCH] Fill package cache according to download mode --- zypp/target/TargetImpl.cc | 72 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index 1f5ee1c..cead686 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -302,13 +302,15 @@ namespace zypp Package::constPtr p = asKind(pi.resolvable()); - // Build a repository list for repos // contributing to the pool std::list repos( _pool.knownRepositoriesBegin(), _pool.knownRepositoriesEnd() ); repo::DeltaCandidates deltas(repos, p->name()); repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy ); - return pkgProvider.providePackage(); + + ManagedFile ret( pkgProvider.providePackage() ); + INT << ret << " (" << ret.getDispose() << ")" << endl; + return ret; } }; /////////////////////////////////////////////////////////////////// @@ -860,6 +862,7 @@ namespace zypp /////////////////////////////////////////////////////////////////// DBG << "commit log file is set to: " << HistoryLog::fname() << endl; + if ( ! policy_r.dryRun() || policy_r.downloadMode() == DownloadOnly ) { // somewhat uggly constraint: The iterator passed to the CommitPackageCache // must match begin and end of the install PoolItemList passed to commit. @@ -876,8 +879,58 @@ namespace zypp CommitPackageCache packageCache( items.begin(), items.end(), root() / "tmp", repoProvidePackage ); - commit ( to_uninstall, policy_r, packageCache ); + bool miss = false; + if ( policy_r.downloadMode() != DownloadAsNeeded ) + { + // Preload the cache. Until now this means pre-loading all packages. + // Once DownloadInHeaps is fully implemented, this will change and + // we may actually have more than one heap. + for_( it, items.begin(), items.end() ) + { + if ( (*it)->isKind() ) + { + ManagedFile localfile; + try + { + localfile = packageCache.get( it ); + localfile.resetDispose(); // keep the package file in the cache + } + catch ( const AbortRequestException & exp ) + { + miss = true; + WAR << "commit cache preload aborted by the user" << endl; + ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) ); + break; + } + catch ( const SkipRequestException & exp ) + { + ZYPP_CAUGHT( exp ); + miss = true; + WAR << "Skipping cache preload package " << (*it)->asKind() << " in commit" << endl; + continue; + } + catch ( const Exception & exp ) + { + // bnc #395704: missing catch causes abort. + // TODO see if packageCache fails to handle errors correctly. + ZYPP_CAUGHT( exp ); + miss = true; + INT << "Unexpected Error: Skipping cache preload package " << (*it)->asKind() << " in commit" << endl; + continue; + } + } + } + } + + if ( miss ) + { + ERR << "Some packages could not be provided. Aborting commit."<< endl; + result._remaining.insert( result._remaining.end(), to_install.begin(), to_install.end() ); + result._srcremaining.insert( result._srcremaining.end(), to_srcinstall.begin(), to_srcinstall.end() ); + } + else if ( ! policy_r.dryRun() ) { + commit ( to_uninstall, policy_r, packageCache ); TargetImpl::PoolItemList bad = commit( items, policy_r, packageCache ); if ( ! bad.empty() ) { @@ -890,10 +943,18 @@ namespace zypp } } } + else + { + DBG << "dryRun: Not installing/deleting anything." << endl; + } + } + else + { + DBG << "dryRun: Not downloading/installing/deleting anything." << endl; } /////////////////////////////////////////////////////////////////// - // Try to rebuild solv file while rpm database is still in cache. + // Try to rebuild solv file while rpm database is still in cache /////////////////////////////////////////////////////////////////// if ( ! policy_r.dryRun() ) { @@ -986,6 +1047,7 @@ namespace zypp if ( progress.aborted() ) { WAR << "commit aborted by the user" << endl; + localfile.resetDispose(); // keep the package file in the cache abort = true; break; } @@ -997,6 +1059,8 @@ namespace zypp catch ( Exception & excpt_r ) { ZYPP_CAUGHT(excpt_r); + localfile.resetDispose(); // keep the package file in the cache + if ( policy_r.dryRun() ) { WAR << "dry run failed" << endl; -- 2.7.4