19 #include <sys/types.h>
70 inline void sigMultiversionSpecChanged()
72 sat::detail::PoolMember::myPool().multiversionSpecChanged();
88 for (
const Transaction::Step & step : steps_r )
90 if ( step.stepType() != Transaction::TRANSACTION_IGNORE )
100 static const std::string strType(
"type" );
101 static const std::string strStage(
"stage" );
102 static const std::string strSolvable(
"solvable" );
104 static const std::string strTypeDel(
"-" );
105 static const std::string strTypeIns(
"+" );
106 static const std::string strTypeMul(
"M" );
108 static const std::string strStageDone(
"ok" );
109 static const std::string strStageFailed(
"err" );
111 static const std::string strSolvableN(
"n" );
112 static const std::string strSolvableE(
"e" );
113 static const std::string strSolvableV(
"v" );
114 static const std::string strSolvableR(
"r" );
115 static const std::string strSolvableA(
"a" );
122 case Transaction::TRANSACTION_IGNORE:
break;
123 case Transaction::TRANSACTION_ERASE: ret.
add( strType, strTypeDel );
break;
124 case Transaction::TRANSACTION_INSTALL: ret.
add( strType, strTypeIns );
break;
125 case Transaction::TRANSACTION_MULTIINSTALL: ret.
add( strType, strTypeMul );
break;
130 case Transaction::STEP_TODO:
break;
131 case Transaction::STEP_DONE: ret.
add( strStage, strStageDone );
break;
132 case Transaction::STEP_ERROR: ret.
add( strStage, strStageFailed );
break;
141 ident = solv.ident();
148 ident = step_r.
ident();
150 arch = step_r.
arch();
155 { strSolvableV, ed.
version() },
156 { strSolvableR, ed.
release() },
160 s.add( strSolvableE, epoch );
162 ret.
add( strSolvable, s );
176 SolvIdentFile::Data getUserInstalledFromHistory(
const Pathname & historyFile_r )
178 SolvIdentFile::Data onSystemByUserList;
181 std::ifstream infile( historyFile_r.c_str() );
182 for( iostr::EachLine in( infile ); in; in.next() )
184 const char * ch( (*in).c_str() );
186 if ( *ch <
'1' ||
'9' < *ch )
188 const char * sep1 = ::strchr( ch,
'|' );
193 bool installs =
true;
194 if ( ::strncmp( sep1,
"install|", 8 ) )
196 if ( ::strncmp( sep1,
"remove |", 8 ) )
203 const char * sep2 = ::strchr( sep1,
'|' );
204 if ( !sep2 || sep1 == sep2 )
206 (*in)[sep2-ch] =
'\0';
207 IdString pkg( sep1 );
211 onSystemByUserList.erase( pkg );
215 if ( (sep1 = ::strchr( sep2+1,
'|' ))
216 && (sep1 = ::strchr( sep1+1,
'|' ))
217 && (sep2 = ::strchr( sep1+1,
'|' )) )
219 (*in)[sep2-ch] =
'\0';
220 if ( ::strchr( sep1+1,
'@' ) )
223 onSystemByUserList.insert( pkg );
228 MIL <<
"onSystemByUserList found: " << onSystemByUserList.size() << endl;
229 return onSystemByUserList;
247 if ( ! _scripts.empty() )
254 {
return _scripts.empty(); }
262 DBG <<
"+++++++++++++++ send " << frame_r << endl;
263 for (
auto it = _scripts.begin(); it != _scripts.end(); )
265 doSend( *it, frame_r );
269 it = _scripts.erase( it );
271 DBG <<
"--------------- send " << frame_r << endl;
280 void load(
const Pathname & path_r )
282 PathInfo pi( path_r );
283 DBG <<
"+++++++++++++++ load " << pi << endl;
286 std::list<Pathname> entries;
289 WAR <<
"Plugin dir is not readable: " << pi << endl;
292 for_( it, entries.begin(), entries.end() )
295 if ( pii.isFile() && pii.userMayRX() )
299 else if ( pi.isFile() )
301 if ( pi.userMayRX() )
304 WAR <<
"Plugin file is not executable: " << pi << endl;
308 WAR <<
"Plugin path is neither dir nor file: " << pi << endl;
310 DBG <<
"--------------- load " << pi << endl;
324 script_r.
send( frame_r );
332 WAR <<
"Bad plugin response from " << script_r << endl;
343 MIL <<
"Load plugin: " << pi_r << endl;
349 if ( ZConfig::instance().hasUserData() )
350 frame.
setHeader(
"userdata", ZConfig::instance().userData() );
352 doSend( plugin, frame );
353 if ( plugin.isOpen() )
354 _scripts.push_back( plugin );
358 WAR <<
"Failed to load plugin " << pi_r << endl;
368 USR <<
"+++++" << endl;
372 USR <<
"=====" << endl;
374 USR <<
"-----" << endl;
383 {
"TransactionStepList", steps_r }
392 unsigned toKeep( ZConfig::instance().solver_upgradeTestcasesToKeep() );
393 MIL <<
"Testcases to keep: " << toKeep << endl;
396 Target_Ptr target( getZYpp()->getTarget() );
399 WAR <<
"No Target no Testcase!" << endl;
403 std::string stem(
"updateTestcase" );
404 Pathname dir( target->assertRootPrefix(
"/var/log/") );
405 Pathname next( dir / Date::now().
form( stem+
"-%Y-%m-%d-%H-%M-%S" ) );
408 std::list<std::string> content;
410 std::set<std::string> cases;
411 for_( c, content.begin(), content.end() )
416 if ( cases.size() >= toKeep )
418 unsigned toDel = cases.size() - toKeep + 1;
419 for_( c, cases.begin(), cases.end() )
428 MIL <<
"Write new testcase " << next << endl;
429 getZYpp()->resolver()->createSolverTestcase( next.asString(),
false );
446 std::pair<bool,PatchScriptReport::Action> doExecuteScript(
const Pathname & root_r,
447 const Pathname & script_r,
450 MIL <<
"Execute script " << PathInfo(Pathname::assertprefix( root_r,script_r)) << endl;
453 historylog.
comment(script_r.asString() +
_(
" executed"),
true);
454 ExternalProgram prog( script_r.asString(), ExternalProgram::Stderr_To_Stdout,
false, -1,
true, root_r );
456 for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
459 if ( ! report_r->progress( PatchScriptReport::OUTPUT, output ) )
461 WAR <<
"User request to abort script " << script_r << endl;
468 std::pair<bool,PatchScriptReport::Action> ret( std::make_pair(
false, PatchScriptReport::ABORT ) );
470 if ( prog.close() != 0 )
472 ret.second = report_r->problem( prog.execError() );
473 WAR <<
"ACTION" << ret.second <<
"(" << prog.execError() <<
")" << endl;
474 std::ostringstream sstr;
475 sstr << script_r <<
_(
" execution failed") <<
" (" << prog.execError() <<
")" << endl;
476 historylog.
comment(sstr.str(),
true);
488 bool executeScript(
const Pathname & root_r,
489 const Pathname & script_r,
490 callback::SendReport<PatchScriptReport> & report_r )
492 std::pair<bool,PatchScriptReport::Action> action( std::make_pair(
false, PatchScriptReport::ABORT ) );
495 action = doExecuteScript( root_r, script_r, report_r );
499 switch ( action.second )
501 case PatchScriptReport::ABORT:
502 WAR <<
"User request to abort at script " << script_r << endl;
506 case PatchScriptReport::IGNORE:
507 WAR <<
"User request to skip script " << script_r << endl;
511 case PatchScriptReport::RETRY:
514 }
while ( action.second == PatchScriptReport::RETRY );
517 INT <<
"Abort on unknown ACTION request " << action.second <<
" returned" << endl;
526 bool RunUpdateScripts(
const Pathname & root_r,
527 const Pathname & scriptsPath_r,
528 const std::vector<sat::Solvable> & checkPackages_r,
531 if ( checkPackages_r.empty() )
534 MIL <<
"Looking for new update scripts in (" << root_r <<
")" << scriptsPath_r << endl;
535 Pathname scriptsDir( Pathname::assertprefix( root_r, scriptsPath_r ) );
536 if ( ! PathInfo( scriptsDir ).isDir() )
539 std::list<std::string> scripts;
541 if ( scripts.empty() )
549 std::map<std::string, Pathname> unify;
550 for_( it, checkPackages_r.begin(), checkPackages_r.end() )
552 std::string prefix(
str::form(
"%s-%s", it->name().c_str(), it->edition().c_str() ) );
553 for_( sit, scripts.begin(), scripts.end() )
558 if ( (*sit)[prefix.size()] !=
'\0' && (*sit)[prefix.size()] !=
'-' )
561 PathInfo script( scriptsDir / *sit );
562 Pathname localPath( scriptsPath_r/(*sit) );
563 std::string unifytag;
565 if ( script.isFile() )
571 else if ( ! script.isExist() )
579 if ( unifytag.empty() )
583 if ( unify[unifytag].empty() )
585 unify[unifytag] = localPath;
592 std::string msg(
str::form(
_(
"%s already executed as %s)"), localPath.asString().c_str(), unify[unifytag].c_str() ) );
593 MIL <<
"Skip update script: " << msg << endl;
594 HistoryLog().comment( msg,
true );
598 if ( abort || aborting_r )
600 WAR <<
"Aborting: Skip update script " << *sit << endl;
601 HistoryLog().comment(
602 localPath.asString() +
_(
" execution skipped while aborting"),
607 MIL <<
"Found update script " << *sit << endl;
608 callback::SendReport<PatchScriptReport>
report;
609 report->start( make<Package>( *it ), script.path() );
611 if ( ! executeScript( root_r, localPath, report ) )
623 inline void copyTo( std::ostream & out_r,
const Pathname & file_r )
625 std::ifstream infile( file_r.c_str() );
626 for( iostr::EachLine in( infile ); in; in.next() )
628 out_r << *in << endl;
632 inline std::string notificationCmdSubst(
const std::string & cmd_r,
const UpdateNotificationFile & notification_r )
634 std::string ret( cmd_r );
635 #define SUBST_IF(PAT,VAL) if ( ret.find( PAT ) != std::string::npos ) ret = str::gsub( ret, PAT, VAL )
636 SUBST_IF(
"%p", notification_r.solvable().asString() );
637 SUBST_IF(
"%P", notification_r.file().asString() );
642 void sendNotification(
const Pathname & root_r,
645 if ( notifications_r.empty() )
648 std::string cmdspec( ZConfig::instance().updateMessagesNotify() );
649 MIL <<
"Notification command is '" << cmdspec <<
"'" << endl;
650 if ( cmdspec.empty() )
654 if ( pos == std::string::npos )
656 ERR <<
"Can't send Notification: Missing 'format |' in command spec." << endl;
657 HistoryLog().comment( str::Str() <<
_(
"Error sending update message notification."),
true );
662 std::string commandStr(
str::trim( cmdspec.substr( pos + 1 ) ) );
664 enum Format { UNKNOWN, NONE, SINGLE, DIGEST, BULK };
665 Format format = UNKNOWN;
666 if ( formatStr ==
"none" )
668 else if ( formatStr ==
"single" )
670 else if ( formatStr ==
"digest" )
672 else if ( formatStr ==
"bulk" )
676 ERR <<
"Can't send Notification: Unknown format '" << formatStr <<
" |' in command spec." << endl;
677 HistoryLog().comment( str::Str() <<
_(
"Error sending update message notification."),
true );
685 if ( format == NONE || format == SINGLE )
687 for_( it, notifications_r.begin(), notifications_r.end() )
689 std::vector<std::string> command;
690 if ( format == SINGLE )
691 command.push_back(
"<"+Pathname::assertprefix( root_r, it->file() ).
asString() );
692 str::splitEscaped( notificationCmdSubst( commandStr, *it ), std::back_inserter( command ) );
694 ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout,
false, -1,
true, root_r );
697 for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
701 int ret = prog.close();
704 ERR <<
"Notification command returned with error (" << ret <<
")." << endl;
705 HistoryLog().comment( str::Str() <<
_(
"Error sending update message notification."),
true );
711 else if ( format == DIGEST || format == BULK )
713 filesystem::TmpFile tmpfile;
714 ofstream out( tmpfile.path().c_str() );
715 for_( it, notifications_r.begin(), notifications_r.end() )
717 if ( format == DIGEST )
719 out << it->file() << endl;
721 else if ( format == BULK )
723 copyTo( out <<
'\f', Pathname::assertprefix( root_r, it->file() ) );
727 std::vector<std::string> command;
728 command.push_back(
"<"+tmpfile.path().asString() );
729 str::splitEscaped( notificationCmdSubst( commandStr, *notifications_r.begin() ), std::back_inserter( command ) );
731 ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout,
false, -1,
true, root_r );
734 for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
738 int ret = prog.close();
741 ERR <<
"Notification command returned with error (" << ret <<
")." << endl;
742 HistoryLog().comment( str::Str() <<
_(
"Error sending update message notification."),
true );
749 INT <<
"Can't send Notification: Missing handler for 'format |' in command spec." << endl;
750 HistoryLog().comment( str::Str() <<
_(
"Error sending update message notification."),
true );
761 void RunUpdateMessages(
const Pathname & root_r,
762 const Pathname & messagesPath_r,
763 const std::vector<sat::Solvable> & checkPackages_r,
764 ZYppCommitResult & result_r )
766 if ( checkPackages_r.empty() )
769 MIL <<
"Looking for new update messages in (" << root_r <<
")" << messagesPath_r << endl;
770 Pathname messagesDir( Pathname::assertprefix( root_r, messagesPath_r ) );
771 if ( ! PathInfo( messagesDir ).isDir() )
774 std::list<std::string> messages;
776 if ( messages.empty() )
782 HistoryLog historylog;
783 for_( it, checkPackages_r.begin(), checkPackages_r.end() )
785 std::string prefix(
str::form(
"%s-%s", it->name().c_str(), it->edition().c_str() ) );
786 for_( sit, messages.begin(), messages.end() )
791 if ( (*sit)[prefix.size()] !=
'\0' && (*sit)[prefix.size()] !=
'-' )
794 PathInfo message( messagesDir / *sit );
795 if ( ! message.isFile() || message.size() == 0 )
798 MIL <<
"Found update message " << *sit << endl;
799 Pathname localPath( messagesPath_r/(*sit) );
800 result_r.rUpdateMessages().push_back( UpdateNotificationFile( *it, localPath ) );
801 historylog.comment( str::Str() <<
_(
"New update message") <<
" " << localPath,
true );
804 sendNotification( root_r, result_r.updateMessages() );
812 const Pathname & messagesPath_r,
813 const std::vector<sat::Solvable> & checkPackages_r,
815 { RunUpdateMessages( root_r, messagesPath_r, checkPackages_r, result_r ); }
826 TargetImpl::TargetImpl(
const Pathname & root_r,
bool doRebuild_r )
828 , _requestedLocalesFile( home() /
"RequestedLocales" )
829 , _autoInstalledFile( home() /
"AutoInstalled" )
830 , _hardLocksFile( Pathname::assertprefix( _root,
ZConfig::instance().locksFile() ) )
837 sigMultiversionSpecChanged();
838 MIL <<
"Initialized target on " <<
_root << endl;
846 std::ifstream uuidprovider(
"/proc/sys/kernel/random/uuid" );
856 boost::function<
bool ()> condition,
857 boost::function<
string ()> value )
859 string val = value();
867 MIL <<
"updating '" << filename <<
"' content." << endl;
871 std::ofstream filestr;
874 filestr.open( filename.c_str() );
876 if ( filestr.good() )
892 return ! PathInfo(pathname).isExist();
900 Pathname idpath(
home() /
"AnonymousUniqueId");
910 WAR <<
"Can't create anonymous id file" << endl;
919 Pathname flavorpath(
home() /
"LastDistributionFlavor");
925 WAR <<
"No base product, I won't create flavor cache" << endl;
929 string flavor = p->flavor();
941 WAR <<
"Can't create flavor cache" << endl;
954 sigMultiversionSpecChanged();
955 MIL <<
"Targets closed" << endl;
978 Pathname rpmsolv = base/
"solv";
979 Pathname rpmsolvcookie = base/
"cookie";
981 bool build_rpm_solv =
true;
986 bool solvexisted = PathInfo(rpmsolv).isExist();
990 PathInfo cookie( rpmsolvcookie );
991 MIL <<
"Read cookie: " << cookie << endl;
992 if ( cookie.isExist() )
996 if ( status == rpmstatus )
997 build_rpm_solv =
false;
998 MIL <<
"Read cookie: " << rpmsolvcookie <<
" says: "
999 << (build_rpm_solv ?
"outdated" :
"uptodate") << endl;
1003 if ( build_rpm_solv )
1008 Pathname oldSolvFile( solvexisted ? rpmsolv : Pathname() );
1017 bool switchingToTmpSolvfile =
false;
1018 Exception ex(
"Failed to cache rpm database.");
1024 rpmsolv = base/
"solv";
1025 rpmsolvcookie = base/
"cookie";
1032 WAR <<
"Using a temporary solv file at " << base << endl;
1033 switchingToTmpSolvfile =
true;
1042 if ( ! switchingToTmpSolvfile )
1052 cmd.push_back(
"rpmdb2solv" );
1053 if ( !
_root.empty() ) {
1054 cmd.push_back(
"-r" );
1055 cmd.push_back(
_root.asString() );
1057 cmd.push_back(
"-X" );
1058 cmd.push_back(
"-A" );
1059 cmd.push_back(
"-p" );
1060 cmd.push_back( Pathname::assertprefix(
_root,
"/etc/products.d" ).
asString() );
1062 if ( ! oldSolvFile.empty() )
1063 cmd.push_back( oldSolvFile.asString() );
1065 cmd.push_back(
"-o" );
1069 std::string errdetail;
1072 WAR <<
" " << output;
1073 if ( errdetail.empty() ) {
1077 errdetail += output;
1080 int ret = prog.
close();
1103 Pathname script( Pathname::assertprefix(
_root,
ZConfig::instance().pluginsPath()/
"system/spacewalk" ) );
1104 if ( PathInfo( script ).isX() )
1110 spacewalk.
send( notify );
1114 if ( ret.command() ==
"ERROR" )
1115 ret.writeTo(
WAR ) << endl;
1126 if ( ! PathInfo(base/
"solv.idx").isExist() )
1129 return build_rpm_solv;
1147 MIL <<
"New cache built: " << (newCache?
"true":
"false") <<
1148 ", force loading: " << (force?
"true":
"false") << endl;
1153 MIL <<
"adding " << rpmsolv <<
" to pool(" << satpool.
systemRepoAlias() <<
")" << endl;
1160 if ( newCache || force )
1177 MIL <<
"adding " << rpmsolv <<
" to system" << endl;
1183 MIL <<
"Try to handle exception by rebuilding the solv-file" << endl;
1208 if ( PathInfo( historyFile ).isExist() )
1215 if ( onSystemByUser.find( ident ) == onSystemByUser.end() )
1216 onSystemByAuto.insert( ident );
1232 if ( ! hardLocks.empty() )
1241 MIL <<
"Target loaded: " << system.
solvablesSize() <<
" resolvables" << endl;
1260 if (
root() ==
"/" )
1270 MIL <<
"TargetImpl::commit(<pool>, " << policy_r <<
")" << endl;
1289 steps.push_back( *it );
1296 MIL <<
"Todo: " << result << endl;
1305 commitPlugins.
load( plugindir );
1307 if ( ! commitPlugins.
empty() )
1308 commitPlugins.
send( transactionPluginFrame(
"COMMITBEGIN", steps ) );
1313 if ( getZYpp()->resolver()->upgradeMode() )
1315 if ( ! policy_r.
dryRun() )
1321 DBG <<
"dryRun: Not writing upgrade testcase." << endl;
1328 if ( ! policy_r.
dryRun() )
1350 DBG <<
"dryRun: Not stroring non-package data." << endl;
1357 if ( ! policy_r.
dryRun() )
1359 for_( it, steps.begin(), steps.end() )
1361 if ( ! it->satSolvable().isKind<
Patch>() )
1369 if ( ! patch ||patch->message().empty() )
1372 MIL <<
"Show message for " << patch << endl;
1374 if ( ! report->show( patch ) )
1376 WAR <<
"commit aborted by the user" << endl;
1383 DBG <<
"dryRun: Not checking patch messages." << endl;
1402 for_( it, steps.begin(), steps.end() )
1404 switch ( it->stepType() )
1426 localfile = packageCache.
get( pi );
1436 INT <<
"Don't know howto cache: Neither Package nor SrcPackage: " << pi << endl;
1441 catch (
const AbortRequestException & exp )
1445 WAR <<
"commit cache preload aborted by the user" << endl;
1449 catch (
const SkipRequestException & exp )
1454 WAR <<
"Skipping cache preload package " << pi->asKind<
Package>() <<
" in commit" << endl;
1464 INT <<
"Unexpected Error: Skipping cache preload package " << pi->asKind<
Package>() <<
" in commit" << endl;
1474 ERR <<
"Some packages could not be provided. Aborting commit."<< endl;
1478 if ( ! policy_r.
dryRun() )
1482 commit( policy_r, packageCache, result );
1486 DBG <<
"dryRun/downloadOnly: Not installing/deleting anything." << endl;
1492 DBG <<
"dryRun: Not downloading/installing/deleting anything." << endl;
1498 if ( ! commitPlugins.
empty() )
1499 commitPlugins.
send( transactionPluginFrame(
"COMMITEND", steps ) );
1504 if ( ! policy_r.
dryRun() )
1509 MIL <<
"TargetImpl::commit(<pool>, " << policy_r <<
") returns: " << result << endl;
1520 struct NotifyAttemptToModify
1538 MIL <<
"TargetImpl::commit(<list>" << policy_r <<
")" << steps.size() << endl;
1543 NotifyAttemptToModify attemptToModify( result_r );
1548 std::vector<sat::Solvable> successfullyInstalledPackages;
1551 for_( step, steps.begin(), steps.end() )
1573 localfile = packageCache_r.
get( citem );
1575 catch (
const AbortRequestException &e )
1577 WAR <<
"commit aborted by the user" << endl;
1582 catch (
const SkipRequestException &e )
1585 WAR <<
"Skipping package " << p <<
" in commit" << endl;
1594 INT <<
"Unexpected Error: Skipping package " << p <<
" in commit" << endl;
1599 #warning Exception handling
1604 bool success =
false;
1630 if ( progress.aborted() )
1632 WAR <<
"commit aborted by the user" << endl;
1651 WAR <<
"dry run failed" << endl;
1656 if ( progress.aborted() )
1658 WAR <<
"commit aborted by the user" << endl;
1663 WAR <<
"Install failed" << endl;
1669 if ( success && !policy_r.
dryRun() )
1672 successfullyInstalledPackages.push_back( citem.
satSolvable() );
1681 bool success =
false;
1692 if ( progress.aborted() )
1694 WAR <<
"commit aborted by the user" << endl;
1708 if ( progress.aborted() )
1710 WAR <<
"commit aborted by the user" << endl;
1716 WAR <<
"removal of " << p <<
" failed";
1719 if ( success && !policy_r.
dryRun() )
1726 else if ( ! policy_r.
dryRun() )
1730 if ( ! citem.
buddy() )
1737 ERR <<
"Can't install orphan product without release-package! " << citem << endl;
1743 std::string referenceFilename( p->referenceFilename() );
1744 if ( referenceFilename.empty() )
1746 ERR <<
"Can't remove orphan product without 'referenceFilename'! " << citem << endl;
1750 PathInfo referenceFile( Pathname::assertprefix(
_root, Pathname(
"/etc/products.d" ) ) / referenceFilename );
1753 ERR <<
"Delete orphan product failed: " << referenceFile << endl;
1781 if ( ! successfullyInstalledPackages.empty() )
1784 successfullyInstalledPackages, abort ) )
1786 WAR <<
"Commit aborted by the user" << endl;
1792 successfullyInstalledPackages,
1826 PathInfo baseproduct( Pathname::assertprefix( root_r,
"/etc/products.d/baseproduct" ) );
1828 if ( baseproduct.isFile() )
1839 else if ( PathInfo( Pathname::assertprefix( root_r,
"/etc/products.d" ) ).isDir() )
1841 ERR <<
"baseproduct symlink is dangling or missing: " << baseproduct << endl;
1846 inline Pathname staticGuessRoot(
const Pathname & root_r )
1848 if ( root_r.empty() )
1853 return Pathname(
"/");
1859 inline std::string firstNonEmptyLineIn(
const Pathname & file_r )
1861 std::ifstream idfile( file_r.c_str() );
1862 for( iostr::EachLine in( idfile ); in; in.next() )
1865 if ( ! line.empty() )
1868 return std::string();
1879 if ( p->isTargetDistribution() )
1887 const Pathname needroot( staticGuessRoot(root_r) );
1888 const Target_constPtr target( getZYpp()->getTarget() );
1889 if ( target && target->root() == needroot )
1890 return target->requestedLocales();
1895 {
return baseproductdata(
_root ).registerTarget(); }
1898 {
return baseproductdata( staticGuessRoot(root_r) ).registerTarget(); }
1901 {
return baseproductdata(
_root ).registerRelease(); }
1904 {
return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
1907 {
return baseproductdata(
_root ).registerFlavor(); }
1910 {
return baseproductdata( staticGuessRoot(root_r) ).registerFlavor();}
1943 std::string
distributionVersion = baseproductdata( staticGuessRoot(root_r) ).edition().version();
1944 if ( distributionVersion.empty() )
1950 scoped_ptr<rpm::RpmDb> tmprpmdb;
1956 tmprpmdb->initDatabase( );
1965 distributionVersion = it->tag_version();
1973 return firstNonEmptyLineIn(
home() /
"LastDistributionFlavor" );
1978 return firstNonEmptyLineIn( staticGuessRoot(root_r) /
"/var/lib/zypp/LastDistributionFlavor" );
1985 return firstNonEmptyLineIn(
home() /
"AnonymousUniqueId" );
1990 return firstNonEmptyLineIn( staticGuessRoot(root_r) /
"/var/lib/zypp/AnonymousUniqueId" );
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
std::string asString(const Patch::Category &obj)
StringQueue autoInstalled() const
Return the ident strings of all packages that would be auto-installed after the transaction is run...
static bool fileMissing(const Pathname &pathname)
helper functor
ZYppCommitResult commit(ResPool pool_r, const ZYppCommitPolicy &policy_r)
Commit changes in the pool.
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string asJSON() const
JSON representation.
std::string shortName() const
Interface to the rpm program.
sat::Transaction getTransaction()
Return the Transaction computed by the last solver run.
CommitPlugins()
Default ctor: Empty plugin list.
A Solvable object within the sat Pool.
std::vector< sat::Transaction::Step > TransactionStepList
Save and restore locale set from file.
Alternating download and install.
Target::DistributionLabel distributionLabel() const
This is shortName and summary attribute of the installed base product.
ZYppCommitPolicy & rpmNoSignature(bool yesNo_r)
Use rpm option –nosignature (default: false)
[M] Install(multiversion) item (
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
byKind_iterator byKindBegin(const ResKind &kind_r) const
Result returned from ZYpp::commit.
static ZConfig & instance()
Singleton ctor.
void addSolv(const Pathname &file_r)
Load Solvables from a solv-file.
const std::string & asString() const
std::string md5sum(const Pathname &file)
Compute a files md5sum.
Command frame for communication with PluginScript.
Pathname home() const
The directory to store things.
std::string distroverpkg() const
Package telling the "product version" on systems not using /etc/product.d/baseproduct.
Pathname _tmpSolvfilesPath
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
void setData(const Data &data_r)
Store new Data.
SolvIdentFile _autoInstalledFile
user/auto installed database
detail::IdType value_type
static ProductFileData scanFile(const Pathname &file_r)
Parse one file (or symlink) and return the ProductFileData parsed.
void updateFileContent(const Pathname &filename, boost::function< bool()> condition, boost::function< string()> value)
updates the content of filename if condition is true, setting the content the the value returned by v...
void stampCommand()
Log info about the current process.
std::string release() const
Release.
Target::commit helper optimizing package provision.
const std::string & asString() const
String representation.
const std::string & command() const
The command we're executing.
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
ZYppCommitPolicy & rpmInstFlags(target::rpm::RpmInstFlags newFlags_r)
The default target::rpm::RpmInstFlags.
TransactionStepList & rTransactionStepList()
Manipulate transactionStepList.
const Data & data() const
Return the data.
void discardScripts()
Discard all remembered scrips.
Pathname root() const
The root set for this target.
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
ZYppCommitPolicy & dryRun(bool yesNo_r)
Set dry run (default: false).
#define N_(MSG)
Just tag text for translation.
ZYppCommitPolicy & rpmExcludeDocs(bool yesNo_r)
Use rpm option –excludedocs (default: false)
std::string _distributionVersion
Cache distributionVersion.
void commitFindFileConflicts(const ZYppCommitPolicy &policy_r, ZYppCommitResult &result_r)
Commit helper checking for file conflicts after download.
void setData(const Data &data_r)
Store new Data.
void setAutoInstalled(const Queue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
SolvableIterator solvablesEnd() const
Iterator behind the last Solvable.
void load(const Pathname &path_r)
Find and launch plugins sending PLUGINSTART message.
Access to the sat-pools string space.
Libsolv transaction wrapper.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Edition represents [epoch:]version[-release]
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Similar to DownloadInAdvance, but try to split the transaction into heaps, where at the end of each h...
TraitsType::constPtrType constPtr
Provide a new empty temporary file and delete it when no longer needed.
unsigned epoch_t
Type of an epoch.
void writeUpgradeTestcase()
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
static RepoStatus fromCookieFile(const Pathname &path)
Reads the status from a cookie file.
byKind_iterator byKindEnd(const ResKind &kind_r) const
Class representing a patch.
void installSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Install a source package on the Target.
bool isKind(const ResKind &kind_r) const
LocaleSet requestedLocales() const
Languages to be supported by the system.
std::string summary() const
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r) const
Provide SrcPackage in a local file.
void install(const PoolItem &pi)
Log installation (or update) of a package.
std::string distributionVersion() const
This is version attribute of the installed base product.
std::vector< std::string > Arguments
PluginFrame doSend(PluginScript &script_r, const PluginFrame &frame_r)
Send PluginFrame and expect valid answer (ACK|_ENOMETHOD).
std::string asString() const
Conversion to std::string
Extract and remember posttrans scripts for later execution.
const_iterator begin() const
Iterator to the first TransactionStep.
Subclass to retrieve database content.
void remember(const Exception &old_r)
Store an other Exception as history.
StepStage stepStage() const
Step action result.
rpm::RpmDb _rpm
RPM database.
Repository systemRepo()
Return the system repository, create it if missing.
Date timestamp() const
return the last modification date of the target
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
void push(value_type val_r)
Push a value to the end off the Queue.
const Data & data() const
Return the data.
std::string getline(std::istream &str)
Read one line from stream.
StepType stepType() const
Type of action to perform in this step.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Store and operate on date (time_t).
static Pool instance()
Singleton ctor.
SolvableIterator solvablesBegin() const
Iterator to the first Solvable.
Pathname _root
Path to the target.
~CommitPlugins()
Dtor: Send PLUGINEND message and close plugins.
Pathname defaultSolvfilesPath() const
The systems default solv file location.
bool empty() const
Whether no plugins are waiting.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::string trim(const std::string &s, const Trim trim_r)
int unlink(const Pathname &path)
Like 'unlink'.
static const std::string & systemRepoAlias()
Reserved system repository alias .
bool collectScriptFromPackage(ManagedFile rpmPackage_r)
Extract and remember a packages posttrans script for later execution.
static const Pathname & fname()
Get the current log file path.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
Just download all packages to the local cache.
Options and policies for ZYpp::commit.
void send(const PluginFrame &frame_r)
Send PluginFrame to all open plugins.
libzypp will decide what to do.
bool solvfilesPathIsTemp() const
Whether we're using a temp.
A single step within a Transaction.
ZYppCommitPolicy & downloadMode(DownloadMode val_r)
Commit download policy to use.
RequestedLocalesFile _requestedLocalesFile
Requested Locales database.
bool providesFile(const std::string &path_str, const std::string &name_str) const
If the package is installed and provides the file Needed to evaluate split provides during Resolver::...
void setLocales(const LocaleSet &locales_r)
Store a new locale set.
void getHardLockQueries(HardLockQueries &activeLocks_r)
Suggest a new set of queries based on the current selection.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
Interim helper class to collect global options and settings.
bool isAckCommand() const
Convenience to identify an ACK command.
void createLastDistributionFlavorCache() const
generates a cache of the last product flavor
std::string targetDistributionFlavor() const
This is register.flavor attribute of the installed base product.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
epoch_t epoch() const
Epoch.
std::string version() const
Version.
Pathname rootDir() const
Get rootdir (for file conflicts check)
ResStatus & status() const
Returns the current status.
const LocaleSet & getRequestedLocales() const
Return the requested locales.
bool order()
Order transaction steps for commit.
void updateSolvFileIndex(const Pathname &solvfile_r)
Create solv file content digest for zypper bash completion.
void open()
Setup connection and execute script.
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
TraitsType::constPtrType constPtr
Pathname solvfilesPath() const
The solv file location actually in use (default or temp).
std::string receiveLine()
Read one line from the input stream.
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
ZYppCommitPolicy & restrictToMedia(unsigned mediaNr_r)
Restrict commit to media 1.
std::list< PoolItem > PoolItemList
list of pool items
std::string anonymousUniqueId() const
anonymous unique id
bool solvablesEmpty() const
Whether Repository contains solvables.
PluginFrame receive() const
Receive a PluginFrame.
std::string toLower(const std::string &s)
Return lowercase version of s.
static std::string generateRandomId()
generates a random id using uuidgen
void resetDispose()
Set no dispose function.
ManagedFile get(const PoolItem &citem_r)
Provide a package.
HardLocksFile _hardLocksFile
Hard-Locks database.
Solvable satSolvable() const
Return the corresponding Solvable.
std::string asJSON() const
JSON representation.
void testCommitPlugins(const Pathname &path_r)
static void setRoot(const Pathname &root)
Set new root directory to the default history log file path.
std::string targetDistribution() const
This is register.target attribute of the installed base product.
int close()
Wait for the progamm to complete.
size_type solvablesSize() const
Number of solvables in Repository.
void setHardLockQueries(const HardLockQueries &newLocks_r)
Set a new set of queries.
#define SUBST_IF(PAT, VAL)
std::list< UpdateNotificationFile > UpdateNotifications
Libsolv Id queue wrapper.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
void doLoad(const PathInfo &pi_r)
Launch a plugin sending PLUGINSTART message.
const LocaleSet & locales() const
Return the loacale set.
std::string distributionFlavor() const
This is flavor attribute of the installed base product but does not require the target to be loaded a...
sat::Solvable buddy() const
Return the buddy we share our status object with.
Pathname systemRoot() const
The target root directory.
ZYppCommitPolicy & allMedia()
Process all media (default)
pool::PoolTraits::HardLockQueries Data
const sat::Transaction & transaction() const
The full transaction list.
void add(const Value &val_r)
Push JSON Value to Array.
int close()
Close any open connection.
Base class for Exception.
Resolver & resolver() const
The Resolver.
bool isToBeInstalled() const
Data returned by ProductFileReader.
const_iterator end() const
Iterator behind the last TransactionStep.
void remove(const PoolItem &pi)
Log removal of a package.
Product::constPtr baseProduct() const
returns the target base installed product, also known as the distribution or platform.
Solvable satSolvable() const
Return the corresponding sat::Solvable.
void initDatabase(Pathname root_r=Pathname(), Pathname dbPath_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database.
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
virtual ~TargetImpl()
Dtor.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void eraseFromPool()
Remove this Repository from it's Pool.
bool hasFile(const std::string &file_r, const std::string &name_r="") const
Return true if at least one package owns a certain file (name_r empty) Return true if package name_r ...
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
TraitsType::constPtrType constPtr
Date timestamp() const
timestamp of the rpm database (last modification)
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Helper for commit plugin execution.
sat::Transaction & rTransaction()
Manipulate transaction.
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurences of key_r.
Combining sat::Solvable and ResStatus.
void executeScripts()
Execute te remembered scripts.
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Provides a source package on the Target.
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Track changing files or directories.
std::string toJSON(const sat::Transaction::Step &step_r)
See COMMITBEGIN (added in v1) on page Commit plugin for the specs.
void XRunUpdateMessages(const Pathname &root_r, const Pathname &messagesPath_r, const std::vector< sat::Solvable > &checkPackages_r, ZYppCommitResult &result_r)
Interface to pluigin scripts using a Stomp inspired communication protocol.
std::string targetDistributionRelease() const
This is register.release attribute of the installed base product.
std::unordered_set< IdString > Data
void add(const String &key_r, const Value &val_r)
Add key/value pair.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
void createAnonymousId() const
generates the unique anonymous id which is called when creating the target
void send(const PluginFrame &frame_r) const
Send a PluginFrame.
bool empty() const
Whether this is an empty object without valid data.
detail::Dump< Tp > dump(const Tp &obj_r)
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
const Pathname & file() const
Return the file path.
std::unordered_set< Locale > LocaleSet
rpm::RpmDb & rpm()
The RPM database.
TraitsType::constPtrType constPtr
#define IMPL_PTR_TYPE(NAME)
bool preloaded() const
Whether preloaded hint is set.
ZYppCommitResult & _result
static ResPool instance()
Singleton ctor.
std::list< PluginScript > _scripts
void load(bool force=true)