1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/TargetImpl.cc
19 #include <sys/types.h>
22 #include "zypp/base/LogTools.h"
23 #include "zypp/base/Exception.h"
24 #include "zypp/base/Iterator.h"
25 #include "zypp/base/Gettext.h"
26 #include "zypp/base/IOStream.h"
27 #include "zypp/base/Functional.h"
28 #include "zypp/base/UserRequestException.h"
30 #include "zypp/ZConfig.h"
32 #include "zypp/PoolItem.h"
33 #include "zypp/ResObjects.h"
35 #include "zypp/TmpPath.h"
36 #include "zypp/RepoStatus.h"
37 #include "zypp/ExternalProgram.h"
38 #include "zypp/Repository.h"
40 #include "zypp/ResFilters.h"
41 #include "zypp/HistoryLog.h"
42 #include "zypp/target/TargetImpl.h"
43 #include "zypp/target/TargetCallbackReceiver.h"
44 #include "zypp/target/rpm/librpmDb.h"
45 #include "zypp/target/CommitPackageCache.h"
47 #include "zypp/parser/ProductFileReader.h"
49 #include "zypp/pool/GetResolvablesToInsDel.h"
50 #include "zypp/solver/detail/Helper.h"
52 #include "zypp/repo/DeltaCandidates.h"
53 #include "zypp/repo/PackageProvider.h"
54 #include "zypp/repo/SrcPackageProvider.h"
56 #include "zypp/sat/Pool.h"
60 ///////////////////////////////////////////////////////////////////
62 { /////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////
65 { /////////////////////////////////////////////////////////////////
67 ///////////////////////////////////////////////////////////////////
69 { /////////////////////////////////////////////////////////////////
71 /** Execute script and report against report_r.
72 * Return \c std::pair<bool,PatchScriptReport::Action> to indicate if
73 * execution was successfull (<tt>first = true</tt>), or the desired
74 * \c PatchScriptReport::Action in case execution failed
75 * (<tt>first = false</tt>).
77 * \note The packager is responsible for setting the correct permissions
78 * of the script. If the script is not executable it is reported as an
79 * error. We must not modify the permessions.
81 std::pair<bool,PatchScriptReport::Action> doExecuteScript( const Pathname & root_r,
82 const Pathname & script_r,
83 callback::SendReport<PatchScriptReport> & report_r )
85 MIL << "Execute script " << PathInfo(script_r) << endl;
87 HistoryLog historylog;
88 historylog.comment(script_r.asString() + _(" executed"), /*timestamp*/true);
89 ExternalProgram prog( script_r.asString(), ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
91 for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
93 historylog.comment(output);
94 if ( ! report_r->progress( PatchScriptReport::OUTPUT, output ) )
96 WAR << "User request to abort script " << script_r << endl;
98 // the rest is handled by exit code evaluation
99 // in case the script has meanwhile finished.
103 std::pair<bool,PatchScriptReport::Action> ret( std::make_pair( false, PatchScriptReport::ABORT ) );
105 if ( prog.close() != 0 )
107 ret.second = report_r->problem( prog.execError() );
108 WAR << "ACTION" << ret.second << "(" << prog.execError() << ")" << endl;
109 std::ostringstream sstr;
110 sstr << script_r << _(" execution failed") << " (" << prog.execError() << ")" << endl;
111 historylog.comment(sstr.str(), /*timestamp*/true);
120 /** Execute script and report against report_r.
121 * Return \c false if user requested \c ABORT.
123 bool executeScript( const Pathname & root_r,
124 const Pathname & script_r,
125 callback::SendReport<PatchScriptReport> & report_r )
127 std::pair<bool,PatchScriptReport::Action> action( std::make_pair( false, PatchScriptReport::ABORT ) );
130 action = doExecuteScript( root_r, script_r, report_r );
132 return true; // success
134 switch ( action.second )
136 case PatchScriptReport::ABORT:
137 WAR << "User request to abort at script " << script_r << endl;
138 return false; // requested abort.
141 case PatchScriptReport::IGNORE:
142 WAR << "User request to skip script " << script_r << endl;
143 return true; // requested skip.
146 case PatchScriptReport::RETRY:
149 } while ( action.second == PatchScriptReport::RETRY );
151 // THIS is not intended to be reached:
152 INT << "Abort on unknown ACTION request " << action.second << " returned" << endl;
153 return false; // abort.
156 /** Look for patch scripts named 'name-version-release-*' and
157 * execute them. Return \c false if \c ABORT was requested.
159 bool RunUpdateScripts( const Pathname & root_r,
160 const Pathname & scriptsPath_r,
161 const std::vector<sat::Solvable> & checkPackages_r,
164 if ( checkPackages_r.empty() )
165 return true; // no installed packages to check
167 MIL << "Looking for new patch scripts in (" << root_r << ")" << scriptsPath_r << endl;
168 Pathname scriptsDir( Pathname::assertprefix( root_r, scriptsPath_r ) );
169 if ( ! PathInfo( scriptsDir ).isDir() )
170 return true; // no script dir
172 std::list<std::string> scripts;
173 filesystem::readdir( scripts, scriptsDir, /*dots*/false );
174 if ( scripts.empty() )
175 return true; // no scripts in script dir
177 // Now collect and execute all matching scripts.
178 // On ABORT: at least log all outstanding scripts.
180 for_( it, checkPackages_r.begin(), checkPackages_r.end() )
182 std::string prefix( str::form( "%s-%s-", it->name().c_str(), it->edition().c_str() ) );
183 for_( sit, scripts.begin(), scripts.end() )
185 if ( ! str::hasPrefix( *sit, prefix ) )
188 PathInfo script( scriptsDir / *sit );
189 if ( ! script.isFile() )
192 if ( abort || aborting_r )
194 WAR << "Aborting: Skip patch script " << *sit << endl;
195 HistoryLog().comment(
196 script.path().asString() + _(" execution skipped while aborting"),
201 MIL << "Found patch script " << *sit << endl;
202 callback::SendReport<PatchScriptReport> report;
203 report->start( make<Package>( *it ), script.path() );
205 if ( ! executeScript( root_r, script.path(), report ) )
206 abort = true; // requested abort.
213 /////////////////////////////////////////////////////////////////
215 ///////////////////////////////////////////////////////////////////
217 /** Helper for PackageProvider queries during commit. */
218 struct QueryInstalledEditionHelper
220 bool operator()( const std::string & name_r,
221 const Edition & ed_r,
222 const Arch & arch_r ) const
224 rpm::librpmDb::db_const_iterator it;
225 for ( it.findByName( name_r ); *it; ++it )
227 if ( arch_r == it->tag_arch()
228 && ( ed_r == Edition::noedition || ed_r == it->tag_edition() ) )
238 * \short Let the Source provide the package.
239 * \p pool_r \ref ResPool used to get candidates
240 * \p pi item to be commited
242 struct RepoProvidePackage
245 repo::RepoMediaAccess &_access;
247 RepoProvidePackage( repo::RepoMediaAccess &access, ResPool pool_r )
248 : _pool(pool_r), _access(access)
253 ManagedFile operator()( const PoolItem & pi )
255 // Redirect PackageProvider queries for installed editions
256 // (in case of patch/delta rpm processing) to rpmDb.
257 repo::PackageProviderPolicy packageProviderPolicy;
258 packageProviderPolicy.queryInstalledCB( QueryInstalledEditionHelper() );
260 Package::constPtr p = asKind<Package>(pi.resolvable());
263 // Build a repository list for repos
264 // contributing to the pool
265 std::list<Repository> repos( _pool.knownRepositoriesBegin(), _pool.knownRepositoriesEnd() );
266 repo::DeltaCandidates deltas(repos, p->name());
267 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
268 return pkgProvider.providePackage();
271 ///////////////////////////////////////////////////////////////////
273 IMPL_PTR_TYPE(TargetImpl);
275 TargetImpl_Ptr TargetImpl::_nullimpl;
277 /** Null implementation */
278 TargetImpl_Ptr TargetImpl::nullimpl()
281 _nullimpl = new TargetImpl;
285 ///////////////////////////////////////////////////////////////////
287 // METHOD NAME : TargetImpl::TargetImpl
288 // METHOD TYPE : Ctor
290 TargetImpl::TargetImpl( const Pathname & root_r, bool doRebuild_r )
292 , _requestedLocalesFile( home() / "RequestedLocales" )
293 , _softLocksFile( home() / "SoftLocks" )
294 , _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) )
296 _rpm.initDatabase( root_r, Pathname(), doRebuild_r );
298 HistoryLog::setRoot(_root);
303 MIL << "Initialized target on " << _root << endl;
307 * generates a random id using uuidgen
309 static string generateRandomId()
318 ExternalProgram prog( argv,
319 ExternalProgram::Normal_Stderr,
322 for(line = prog.receiveLine();
324 line = prog.receiveLine() )
335 * updates the content of \p filename
336 * if \p condition is true, setting the content
337 * the the value returned by \p value
339 void updateFileContent( const Pathname &filename,
340 boost::function<bool ()> condition,
341 boost::function<string ()> value )
343 string val = value();
344 // if the value is empty, then just dont
345 // do anything, regardless of the condition
351 MIL << "updating '" << filename << "' content." << endl;
353 // if the file does not exist we need to generate the uuid file
355 std::ofstream filestr;
356 // make sure the path exists
357 filesystem::assert_dir( filename.dirname() );
358 filestr.open( filename.c_str() );
360 if ( filestr.good() )
367 // FIXME, should we ignore the error?
368 ZYPP_THROW(Exception("Can't openfile '" + filename.asString() + "' for writing"));
373 /** helper functor */
374 static bool fileMissing( const Pathname &pathname )
376 return ! PathInfo(pathname).isExist();
379 void TargetImpl::createAnonymousId() const
382 // create the anonymous unique id
383 // this value is used for statistics
384 Pathname idpath( home() / "AnonymousUniqueId");
388 updateFileContent( idpath,
389 boost::bind(fileMissing, idpath),
392 catch ( const Exception &e )
394 WAR << "Can't create anonymous id file" << endl;
399 void TargetImpl::createLastDistributionFlavorCache() const
401 // create the anonymous unique id
402 // this value is used for statistics
403 Pathname flavorpath( home() / "LastDistributionFlavor");
405 // is there a product
406 Product::constPtr p = baseProduct();
409 WAR << "No base product, I won't create flavor cache" << endl;
413 string flavor = p->flavor();
418 updateFileContent( flavorpath,
419 // only if flavor is not empty
420 functor::Constant<bool>( ! flavor.empty() ),
421 functor::Constant<string>(flavor) );
423 catch ( const Exception &e )
425 WAR << "Can't create flavor cache" << endl;
430 ///////////////////////////////////////////////////////////////////
432 // METHOD NAME : TargetImpl::~TargetImpl
433 // METHOD TYPE : Dtor
435 TargetImpl::~TargetImpl()
437 _rpm.closeDatabase();
438 MIL << "Targets closed" << endl;
441 void TargetImpl::clearCache()
443 Pathname base = Pathname::assertprefix( _root,
444 ZConfig::instance().repoSolvfilesPath() / sat::Pool::instance().systemRepoAlias() );
445 filesystem::recursive_rmdir( base );
448 void TargetImpl::buildCache()
450 Pathname base = Pathname::assertprefix( _root,
451 ZConfig::instance().repoSolvfilesPath() / sat::Pool::instance().systemRepoAlias() );
452 Pathname rpmsolv = base/"solv";
453 Pathname rpmsolvcookie = base/"cookie";
455 bool build_rpm_solv = true;
456 // lets see if the rpm solv cache exists
458 RepoStatus rpmstatus( RepoStatus( _root/"/var/lib/rpm/Name" )
459 && (_root/"/etc/products.d") );
461 bool solvexisted = PathInfo(rpmsolv).isExist();
464 // see the status of the cache
465 PathInfo cookie( rpmsolvcookie );
466 MIL << "Read cookie: " << cookie << endl;
467 if ( cookie.isExist() )
469 RepoStatus status = RepoStatus::fromCookieFile(rpmsolvcookie);
470 // now compare it with the rpm database
471 if ( status.checksum() == rpmstatus.checksum() )
472 build_rpm_solv = false;
473 MIL << "Read cookie: " << rpmsolvcookie << " says: "
474 << (build_rpm_solv ? "outdated" : "uptodate") << endl;
478 if ( build_rpm_solv )
480 // Take care we unlink the solvfile on exception
481 ManagedFile guard( base, filesystem::recursive_rmdir );
483 // if it does not exist yet, we better create it
484 filesystem::assert_dir( base );
486 filesystem::TmpFile tmpsolv( filesystem::TmpFile::makeSibling( rpmsolv ) );
489 Exception ex("Failed to cache rpm database.");
490 ex.remember(str::form(
491 "Cannot create temporary file under %s.", base.c_str()));
495 std::ostringstream cmd;
497 if ( ! _root.empty() )
498 cmd << " -r '" << _root << "'";
500 cmd << " -p '" << Pathname::assertprefix( _root, "/etc/products.d" ) << "'";
503 cmd << " '" << rpmsolv << "'";
505 cmd << " > '" << tmpsolv.path() << "'";
507 MIL << "Executing: " << cmd << endl;
508 ExternalProgram prog( cmd.str(), ExternalProgram::Stderr_To_Stdout );
511 for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
512 WAR << " " << output;
513 cmd << " " << output;
516 int ret = prog.close();
519 Exception ex(str::form("Failed to cache rpm database (%d).", ret));
520 ex.remember( cmd.str() );
524 ret = filesystem::rename( tmpsolv, rpmsolv );
526 ZYPP_THROW(Exception("Failed to move cache to final destination"));
527 // if this fails, don't bother throwing exceptions
528 filesystem::chmod( rpmsolv, 0644 );
530 rpmstatus.saveToCookieFile(rpmsolvcookie);
533 guard.resetDispose();
537 void TargetImpl::unload()
539 Repository system( sat::Pool::instance().findSystemRepo() );
541 system.eraseFromPool();
545 void TargetImpl::load()
549 // now add the repos to the pool
550 sat::Pool satpool( sat::Pool::instance() );
551 Pathname rpmsolv( Pathname::assertprefix( _root,
552 ZConfig::instance().repoSolvfilesPath() / satpool.systemRepoAlias() / "solv" ) );
553 MIL << "adding " << rpmsolv << " to pool(" << satpool.systemRepoAlias() << ")" << endl;
555 // Providing an empty system repo, unload any old content
556 Repository system( sat::Pool::instance().findSystemRepo() );
557 if ( system && ! system.solvablesEmpty() )
559 system.eraseFromPool(); // invalidates system
563 system = satpool.systemRepo();
568 system.addSolv( rpmsolv );
570 catch ( const Exception & exp )
573 MIL << "Try to handle exception by rebuilding the solv-file" << endl;
577 system.addSolv( rpmsolv );
580 // (Re)Load the requested locales et al.
581 // If the requested locales are empty, we leave the pool untouched
582 // to avoid undoing changes the application applied. We expect this
583 // to happen on a bare metal installation only. An already existing
584 // target should be loaded before its settings are changed.
586 const LocaleSet & requestedLocales( _requestedLocalesFile.locales() );
587 if ( ! requestedLocales.empty() )
589 satpool.setRequestedLocales( requestedLocales );
593 SoftLocksFile::Data softLocks( _softLocksFile.data() );
594 if ( ! softLocks.empty() )
596 // Don't soft lock any installed item.
597 for_( it, system.solvablesBegin(), system.solvablesEnd() )
599 softLocks.erase( it->ident() );
601 ResPool::instance().setAutoSoftLocks( softLocks );
604 if ( ZConfig::instance().apply_locks_file() )
606 const HardLocksFile::Data & hardLocks( _hardLocksFile.data() );
607 if ( ! hardLocks.empty() )
609 ResPool::instance().setHardLockQueries( hardLocks );
613 // now that the target is loaded, we can cache the flavor
614 createLastDistributionFlavorCache();
616 MIL << "Target loaded: " << system.solvablesSize() << " resolvables" << endl;
619 ///////////////////////////////////////////////////////////////////
623 ///////////////////////////////////////////////////////////////////
624 ZYppCommitResult TargetImpl::commit( ResPool pool_r, const ZYppCommitPolicy & policy_rX )
626 // ----------------------------------------------------------------- //
627 // Fake outstanding YCP fix: Honour restriction to media 1
628 // at installation, but install all remaining packages if post-boot.
629 ZYppCommitPolicy policy_r( policy_rX );
630 if ( policy_r.restrictToMedia() > 1 )
632 // ----------------------------------------------------------------- //
634 MIL << "TargetImpl::commit(<pool>, " << policy_r << ")" << endl;
636 ///////////////////////////////////////////////////////////////////
637 // Store non-package data:
638 ///////////////////////////////////////////////////////////////////
639 filesystem::assert_dir( home() );
641 _requestedLocalesFile.setLocales( pool_r.getRequestedLocales() );
644 SoftLocksFile::Data newdata;
645 pool_r.getActiveSoftLocks( newdata );
646 _softLocksFile.setData( newdata );
649 if ( ZConfig::instance().apply_locks_file() )
651 HardLocksFile::Data newdata;
652 pool_r.getHardLockQueries( newdata );
653 _hardLocksFile.setData( newdata );
656 ///////////////////////////////////////////////////////////////////
658 ///////////////////////////////////////////////////////////////////
660 DBG << "commit log file is set to: " << HistoryLog::fname() << endl;
662 ZYppCommitResult result;
664 TargetImpl::PoolItemList to_uninstall;
665 TargetImpl::PoolItemList to_install;
666 TargetImpl::PoolItemList to_srcinstall;
669 pool::GetResolvablesToInsDel
670 collect( pool_r, policy_r.restrictToMedia() ? pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR
671 : pool::GetResolvablesToInsDel::ORDER_BY_SOURCE );
672 MIL << "GetResolvablesToInsDel: " << endl << collect << endl;
673 to_uninstall.swap( collect._toDelete );
674 to_install.swap( collect._toInstall );
675 to_srcinstall.swap( collect._toSrcinstall );
678 if ( policy_r.restrictToMedia() )
680 MIL << "Restrict to media number " << policy_r.restrictToMedia() << endl;
683 ///////////////////////////////////////////////////////////////////
684 // First collect and display all messages
685 // associated with patches to be installed.
686 ///////////////////////////////////////////////////////////////////
687 for_( it, to_install.begin(), to_install.end() )
689 if ( ! isKind<Patch>(it->resolvable()) )
691 if ( ! it->status().isToBeInstalled() )
694 Patch::constPtr patch( asKind<Patch>(it->resolvable()) );
695 if ( ! patch->message().empty() )
697 MIL << "Show message for " << patch << endl;
698 callback::SendReport<target::PatchMessageReport> report;
699 if ( ! report->show( patch ) )
701 WAR << "commit aborted by the user" << endl;
702 ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
707 ///////////////////////////////////////////////////////////////////
708 // Remove/install packages.
709 ///////////////////////////////////////////////////////////////////
710 commit ( to_uninstall, policy_r, pool_r );
712 if (policy_r.restrictToMedia() == 0)
714 result._remaining = commit( to_install, policy_r, pool_r );
715 result._srcremaining = commit( to_srcinstall, policy_r, pool_r );
719 TargetImpl::PoolItemList current_install;
720 TargetImpl::PoolItemList current_srcinstall;
722 // Collect until the 1st package from an unwanted media occurs.
723 // Further collection could violate install order.
724 bool hitUnwantedMedia = false;
725 for (TargetImpl::PoolItemList::iterator it = to_install.begin(); it != to_install.end(); ++it)
727 ResObject::constPtr res( it->resolvable() );
729 if ( hitUnwantedMedia
730 || ( res->mediaNr() && res->mediaNr() != policy_r.restrictToMedia() ) )
732 hitUnwantedMedia = true;
733 result._remaining.push_back( *it );
737 current_install.push_back( *it );
741 TargetImpl::PoolItemList bad = commit( current_install, policy_r, pool_r );
742 result._remaining.insert(result._remaining.end(), bad.begin(), bad.end());
744 for (TargetImpl::PoolItemList::iterator it = to_srcinstall.begin(); it != to_srcinstall.end(); ++it)
746 Resolvable::constPtr res( it->resolvable() );
747 Package::constPtr pkg( asKind<Package>(res) );
748 if (pkg && policy_r.restrictToMedia() != pkg->mediaNr()) // check medianr for packages only
750 XXX << "Package " << *pkg << ", wrong media " << pkg->mediaNr() << endl;
751 result._srcremaining.push_back( *it );
755 current_srcinstall.push_back( *it );
758 bad = commit( current_srcinstall, policy_r, pool_r );
759 result._srcremaining.insert(result._srcremaining.end(), bad.begin(), bad.end());
762 ///////////////////////////////////////////////////////////////////
763 // Try to rebuild solv file while rpm database is still in cache.
764 ///////////////////////////////////////////////////////////////////
767 result._result = (to_install.size() - result._remaining.size());
768 MIL << "TargetImpl::commit(<pool>, " << policy_r << ") returns: " << result << endl;
773 ///////////////////////////////////////////////////////////////////
777 ///////////////////////////////////////////////////////////////////
778 TargetImpl::PoolItemList
779 TargetImpl::commit( const TargetImpl::PoolItemList & items_r,
780 const ZYppCommitPolicy & policy_r,
781 const ResPool & pool_r )
783 TargetImpl::PoolItemList remaining;
784 repo::RepoMediaAccess access;
785 MIL << "TargetImpl::commit(<list>" << policy_r << ")" << items_r.size() << endl;
788 std::vector<sat::Solvable> successfullyInstalledPackages;
790 // prepare the package cache.
791 RepoProvidePackage repoProvidePackage( access, pool_r );
792 CommitPackageCache packageCache( items_r.begin(), items_r.end(),
793 root() / "tmp", repoProvidePackage );
795 for ( TargetImpl::PoolItemList::const_iterator it = items_r.begin(); it != items_r.end(); it++ )
797 if ( (*it)->isKind<Package>() )
799 Package::constPtr p = (*it)->asKind<Package>();
800 if (it->status().isToBeInstalled())
802 ManagedFile localfile;
805 localfile = packageCache.get( it );
807 catch ( const AbortRequestException &e )
809 WAR << "commit aborted by the user" << endl;
813 catch ( const SkipRequestException &e )
816 WAR << "Skipping package " << p << " in commit" << endl;
819 catch ( const Exception &e )
821 // bnc #395704: missing catch causes abort.
822 // TODO see if packageCache fails to handle errors correctly.
824 INT << "Unexpected Error: Skipping package " << p << " in commit" << endl;
828 #warning Exception handling
829 // create a installation progress report proxy
830 RpmInstallPackageReceiver progress( it->resolvable() );
831 progress.connect(); // disconnected on destruction.
833 bool success = false;
834 rpm::RpmInstFlags flags;
835 // Why force and nodeps?
837 // Because zypp builds the transaction and the resolver asserts that
838 // everything is fine.
839 // We use rpm just to unpack and register the package in the database.
840 // We do this step by step, so rpm is not aware of the bigger context.
841 // So we turn off rpms internal checks, because we do it inside zypp.
842 flags |= rpm::RPMINST_NODEPS;
843 flags |= rpm::RPMINST_FORCE;
845 if (p->installOnly()) flags |= rpm::RPMINST_NOUPGRADE;
846 if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
847 if (policy_r.rpmExcludeDocs()) flags |= rpm::RPMINST_EXCLUDEDOCS;
848 if (policy_r.rpmNoSignature()) flags |= rpm::RPMINST_NOSIGNATURE;
852 progress.tryLevel( target::rpm::InstallResolvableReport::RPM_NODEPS_FORCE );
853 rpm().installPackage( localfile, flags );
854 HistoryLog().install(*it);
856 if ( progress.aborted() )
858 WAR << "commit aborted by the user" << endl;
867 catch ( Exception & excpt_r )
869 ZYPP_CAUGHT(excpt_r);
870 if ( policy_r.dryRun() )
872 WAR << "dry run failed" << endl;
876 if ( progress.aborted() )
878 WAR << "commit aborted by the user" << endl;
883 WAR << "Install failed" << endl;
885 remaining.push_back( *it );
889 if ( success && !policy_r.dryRun() )
891 it->status().resetTransact( ResStatus::USER );
892 // Remember to check this package for presence of patch scripts.
893 successfullyInstalledPackages.push_back( it->satSolvable() );
898 RpmRemovePackageReceiver progress( it->resolvable() );
899 progress.connect(); // disconnected on destruction.
901 bool success = false;
902 rpm::RpmInstFlags flags( rpm::RPMINST_NODEPS );
903 if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
906 rpm().removePackage( p, flags );
907 HistoryLog().remove(*it);
909 if ( progress.aborted() )
911 WAR << "commit aborted by the user" << endl;
920 catch (Exception & excpt_r)
922 ZYPP_CAUGHT( excpt_r );
923 if ( progress.aborted() )
925 WAR << "commit aborted by the user" << endl;
930 WAR << "removal of " << p << " failed";
932 if ( success && !policy_r.dryRun() )
934 it->status().resetTransact( ResStatus::USER );
938 else if ( ! policy_r.dryRun() ) // other resolvables (non-Package)
940 // Status is changed as the buddy package buddy
941 // gets installed/deleted. Handle non-buddies only.
944 if ( (*it)->isKind<Product>() )
946 Product::constPtr p = (*it)->asKind<Product>();
947 if ( it->status().isToBeInstalled() )
949 ERR << "Can't install orphan product without release-package! " << (*it) << endl;
953 // Deleting the corresponding product entry is all we con do.
954 // So the product will no longer be visible as installed.
955 std::string referenceFilename( p->referenceFilename() );
956 if ( referenceFilename.empty() )
958 ERR << "Can't remove orphan product without 'referenceFilename'! " << (*it) << endl;
962 PathInfo referenceFile( Pathname::assertprefix( _root, Pathname( "/etc/products.d" ) ) / referenceFilename );
963 if ( ! referenceFile.isFile() || filesystem::unlink( referenceFile.path() ) != 0 )
965 ERR << "Delete orphan product failed: " << referenceFile << endl;
970 else if ( (*it)->isKind<SrcPackage>() && it->status().isToBeInstalled() )
972 // SrcPackage is install-only
973 SrcPackage::constPtr p = (*it)->asKind<SrcPackage>();
974 installSrcPackage( p );
977 it->status().resetTransact( ResStatus::USER );
979 } // other resolvables
983 // Check presence of patch scripts. If aborting, at least log
985 if ( ! successfullyInstalledPackages.empty() )
987 if ( ! RunUpdateScripts( _root, ZConfig::instance().update_scriptsPath(),
988 successfullyInstalledPackages, abort ) )
990 WAR << "Commit aborted by the user" << endl;
997 ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1003 rpm::RpmDb & TargetImpl::rpm()
1008 bool TargetImpl::providesFile (const std::string & path_str, const std::string & name_str) const
1010 return _rpm.hasFile(path_str, name_str);
1014 Date TargetImpl::timestamp() const
1016 return _rpm.timestamp();
1019 ///////////////////////////////////////////////////////////////////
1021 std::string TargetImpl::release() const
1023 std::ifstream suseRelease( (_root / "/etc/SuSE-release").c_str() );
1024 for( iostr::EachLine in( suseRelease ); in; in.next() )
1026 std::string line( str::trim( *in ) );
1027 if ( ! line.empty() )
1031 return _("Unknown Distribution");
1034 ///////////////////////////////////////////////////////////////////
1036 Product::constPtr TargetImpl::baseProduct() const
1038 ResPool pool(ResPool::instance());
1039 for_( it, pool.byKindBegin<Product>(), pool.byKindEnd<Product>() )
1041 Product::constPtr p = (*it)->asKind<Product>();
1042 if ( p->isTargetDistribution() )
1050 parser::ProductFileData baseproductdata( const Pathname & root_r )
1052 PathInfo baseproduct( Pathname::assertprefix( root_r, "/etc/products.d/baseproduct" ) );
1053 if ( baseproduct.isFile() )
1057 return parser::ProductFileReader::scanFile( baseproduct.path() );
1059 catch ( const Exception & excpt )
1061 ZYPP_CAUGHT( excpt );
1064 return parser::ProductFileData();
1069 std::string TargetImpl::targetDistribution() const
1070 { return baseproductdata( _root ).registerTarget(); }
1072 std::string TargetImpl::targetDistributionRelease() const
1073 { return baseproductdata( _root ).registerRelease(); }
1075 std::string TargetImpl::distributionVersion() const
1077 if ( _distributionVersion.empty() )
1079 _distributionVersion = baseproductdata( _root ).edition().version();
1080 if ( !_distributionVersion.empty() )
1081 MIL << "Remember distributionVersion = '" << _distributionVersion << "'" << endl;
1083 return _distributionVersion;
1086 std::string TargetImpl::distributionFlavor() const
1088 std::ifstream idfile( ( home() / "LastDistributionFlavor" ).c_str() );
1089 for( iostr::EachLine in( idfile ); in; in.next() )
1091 std::string line( str::trim( *in ) );
1092 if ( ! line.empty() )
1095 return std::string();
1098 ///////////////////////////////////////////////////////////////////
1100 std::string TargetImpl::anonymousUniqueId() const
1102 std::ifstream idfile( ( home() / "AnonymousUniqueId" ).c_str() );
1103 for( iostr::EachLine in( idfile ); in; in.next() )
1105 std::string line( str::trim( *in ) );
1106 if ( ! line.empty() )
1109 return std::string();
1112 ///////////////////////////////////////////////////////////////////
1114 void TargetImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
1116 // provide on local disk
1117 repo::RepoMediaAccess access_r;
1118 repo::SrcPackageProvider prov( access_r );
1119 ManagedFile localfile = prov.provideSrcPackage( srcPackage_r );
1121 rpm().installPackage ( localfile );
1124 /////////////////////////////////////////////////////////////////
1125 } // namespace target
1126 ///////////////////////////////////////////////////////////////////
1127 /////////////////////////////////////////////////////////////////
1129 ///////////////////////////////////////////////////////////////////