28#include <zypp-core/base/UserRequestException> 
   63#include <zypp-core/zyppng/base/EventLoop> 
   64#include <zypp-core/zyppng/base/UnixSignalSource> 
   65#include <zypp-core/zyppng/io/AsyncDataSource> 
   66#include <zypp-core/zyppng/io/Process> 
   70#include <zypp-core/zyppng/base/EventDispatcher> 
   72#include <shared/commit/CommitMessages.h> 
   79#include "tools/zypp-rpm/errorcodes.h" 
   80#include <rpm/rpmlog.h> 
   87    static bool val = [](){
 
   88      const char * 
env = getenv(
"TRANSACTIONAL_UPDATE");
 
 
  100#include <solv/repo_rpmdb.h> 
  101#include <solv/chksum.h> 
  111      AutoDispose<Chksum*> chk { ::solv_chksum_create( REPOKEY_TYPE_SHA1 ), []( Chksum *chk ) -> 
void {
 
  112        ::solv_chksum_free( chk, 
nullptr );
 
  114      if ( ::rpm_hash_database_state( state, chk ) == 0 )
 
  117        const unsigned char * md5 = ::solv_chksum_get( chk, &md5l );
 
  121        WAR << 
"rpm_hash_database_state failed" << endl;
 
 
  141    inline void sigMultiversionSpecChanged()
 
  159      for ( 
const Transaction::Step & step : steps_r )
 
  161        if ( step.stepType() != Transaction::TRANSACTION_IGNORE )
 
 
  171      static const std::string strType( 
"type" );
 
  172      static const std::string strStage( 
"stage" );
 
  173      static const std::string strSolvable( 
"solvable" );
 
  175      static const std::string strTypeDel( 
"-" );
 
  176      static const std::string strTypeIns( 
"+" );
 
  177      static const std::string strTypeMul( 
"M" );
 
  179      static const std::string strStageDone( 
"ok" );
 
  180      static const std::string strStageFailed( 
"err" );
 
  182      static const std::string strSolvableN( 
"n" );
 
  183      static const std::string strSolvableE( 
"e" );
 
  184      static const std::string strSolvableV( 
"v" );
 
  185      static const std::string strSolvableR( 
"r" );
 
  186      static const std::string strSolvableA( 
"a" );
 
  193        case Transaction::TRANSACTION_IGNORE:    
break;
 
  194        case Transaction::TRANSACTION_ERASE:    ret.
add( strType, strTypeDel ); 
break;
 
  195        case Transaction::TRANSACTION_INSTALL:  ret.
add( strType, strTypeIns ); 
break;
 
  196        case Transaction::TRANSACTION_MULTIINSTALL: ret.
add( strType, strTypeMul ); 
break;
 
  201        case Transaction::STEP_TODO:             
break;
 
  202        case Transaction::STEP_DONE:            ret.
add( strStage, strStageDone ); 
break;
 
  203        case Transaction::STEP_ERROR:           ret.
add( strStage, strStageFailed ); 
break;
 
  212          ident = solv.ident();
 
  219          ident = step_r.
ident();
 
  221          arch  = step_r.
arch();
 
  226          { strSolvableV, ed.
version() },
 
  227          { strSolvableR, ed.
release() },
 
  231          s.
add( strSolvableE, epoch );
 
  233        ret.
add( strSolvable, s );
 
 
  247      class AssertMountedBase
 
  257          if ( ! _mountpoint.empty() ) {
 
  259            MIL << 
"We mounted " << _mountpoint << 
" so we unmount it" << endl;
 
  260            execute({ 
"umount", 
"-R", 
"-l", _mountpoint.asString() });
 
  268          for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
 
  274        Pathname _mountpoint;
 
  280      class AssertProcMounted : 
private AssertMountedBase
 
  283        AssertProcMounted( Pathname root_r )
 
  286          if ( ! PathInfo(root_r/
"self").isDir() ) {
 
  287            MIL << 
"Try to make sure proc is mounted at" << root_r << endl;
 
  289              && execute({ 
"mount", 
"-t", 
"proc", 
"/proc", root_r.asString() }) == 0 ) {
 
  290              _mountpoint = std::move(root_r);  
 
  293              WAR << 
"Mounting proc at " << root_r << 
" failed" << endl;
 
  301      class AssertDevMounted : 
private AssertMountedBase
 
  304        AssertDevMounted( Pathname root_r )
 
  307          if ( ! PathInfo(root_r/
"null").isChr() ) {
 
  308            MIL << 
"Try to make sure dev is mounted at" << root_r << endl;
 
  313              && execute({ 
"mount", 
"--rbind", 
"--make-rslave", 
"/dev", root_r.asString() }) == 0 ) {
 
  314              _mountpoint = std::move(root_r);  
 
  317              WAR << 
"Mounting dev at " << root_r << 
" failed" << endl;
 
  334        std::ifstream infile( historyFile_r.c_str() );
 
  335        for( iostr::EachLine in( infile ); in; in.next() )
 
  337          const char * ch( (*in).c_str() );
 
  339          if ( *ch < 
'1' || 
'9' < *ch )
 
  341          const char * sep1 = ::strchr( ch, 
'|' );      
 
  346          bool installs = 
true;
 
  347          if ( ::strncmp( sep1, 
"install|", 8 ) )
 
  349            if ( ::strncmp( sep1, 
"remove |", 8 ) )
 
  356          const char * sep2 = ::strchr( sep1, 
'|' );    
 
  357          if ( !sep2 || sep1 == sep2 )
 
  359          (*in)[sep2-ch] = 
'\0';
 
  364            onSystemByUserList.erase( pkg );
 
  368          if ( (sep1 = ::strchr( sep2+1, 
'|' ))         
 
  369            && (sep1 = ::strchr( sep1+1, 
'|' ))         
 
  370            && (sep2 = ::strchr( sep1+1, 
'|' )) )       
 
  372            (*in)[sep2-ch] = 
'\0';
 
  373            if ( ::strchr( sep1+1, 
'@' ) )
 
  376              onSystemByUserList.insert( pkg );
 
  381        MIL << 
"onSystemByUserList found: " << onSystemByUserList.size() << endl;
 
  382        return onSystemByUserList;
 
  392        return PluginFrame( command_r, json::Object {
 
  393          { 
"TransactionStepList", steps_r }
 
  403      MIL << 
"Testcases to keep: " << toKeep << endl;
 
  409        WAR << 
"No Target no Testcase!" << endl;
 
  413      std::string stem( 
"updateTestcase" );
 
  418        std::list<std::string> content;
 
  420        std::set<std::string> cases;
 
  421        for_( c, content.begin(), content.end() )
 
  426        if ( cases.size() >= toKeep )
 
  428          unsigned toDel = cases.size() - toKeep + 1; 
 
  429          for_( c, cases.begin(), cases.end() )
 
  438      MIL << 
"Write new testcase " << next << endl;
 
 
  456      std::pair<bool,PatchScriptReport::Action> doExecuteScript( 
const Pathname & root_r,
 
  466        for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
 
  471            WAR << 
"User request to abort script " << script_r << endl;
 
  480        if ( prog.close() != 0 )
 
  482          ret.second = report_r->problem( prog.execError() );
 
  483          WAR << 
"ACTION" << ret.second << 
"(" << prog.execError() << 
")" << endl;
 
  484          std::ostringstream sstr;
 
  485          sstr << script_r << 
_(
" execution failed") << 
" (" << prog.execError() << 
")" << endl;
 
  486          historylog.
comment(sstr.str(), 
true);
 
  498      bool executeScript( 
const Pathname & root_r,
 
  499                          const Pathname & script_r,
 
  500                          callback::SendReport<PatchScriptReport> & report_r )
 
  505          action = doExecuteScript( root_r, script_r, report_r );
 
  509          switch ( action.second )
 
  512              WAR << 
"User request to abort at script " << script_r << endl;
 
  517              WAR << 
"User request to skip script " << script_r << endl;
 
  527        INT << 
"Abort on unknown ACTION request " << action.second << 
" returned" << endl;
 
  536      bool RunUpdateScripts( 
const Pathname & root_r,
 
  537                             const Pathname & scriptsPath_r,
 
  538                             const std::vector<sat::Solvable> & checkPackages_r,
 
  541        if ( checkPackages_r.empty() )
 
  544        MIL << 
"Looking for new update scripts in (" <<  root_r << 
")" << scriptsPath_r << endl;
 
  546        if ( ! PathInfo( scriptsDir ).isDir() )
 
  549        std::list<std::string> scripts;
 
  551        if ( scripts.empty() )
 
  559        std::map<std::string, Pathname> unify; 
 
  560        for_( it, checkPackages_r.begin(), checkPackages_r.end() )
 
  562          std::string prefix( 
str::form( 
"%s-%s", it->name().c_str(), it->edition().c_str() ) );
 
  563          for_( sit, scripts.begin(), scripts.end() )
 
  568            if ( (*sit)[prefix.size()] != 
'\0' && (*sit)[prefix.size()] != 
'-' )
 
  571            PathInfo script( scriptsDir / *sit );
 
  572            Pathname localPath( scriptsPath_r/(*sit) ); 
 
  573            std::string unifytag;                       
 
  575            if ( script.isFile() )
 
  581            else if ( ! script.isExist() )
 
  589            if ( unifytag.empty() )
 
  593            if ( unify[unifytag].
empty() )
 
  595              unify[unifytag] = localPath;
 
  602              std::string msg( 
str::form(
_(
"%s already executed as %s)"), localPath.asString().c_str(), unify[unifytag].c_str() ) );
 
  603              MIL << 
"Skip update script: " << msg << endl;
 
  604              HistoryLog().comment( msg, 
true );
 
  608            if ( abort || aborting_r )
 
  610              WAR << 
"Aborting: Skip update script " << *sit << endl;
 
  611              HistoryLog().comment(
 
  612                  localPath.asString() + 
_(
" execution skipped while aborting"),
 
  617              MIL << 
"Found update script " << *sit << endl;
 
  618              callback::SendReport<PatchScriptReport> report;
 
  621              if ( ! executeScript( root_r, localPath, report ) ) 
 
  633      inline void copyTo( std::ostream & out_r, 
const Pathname & file_r )
 
  635        std::ifstream infile( file_r.c_str() );
 
  636        for( iostr::EachLine in( infile ); in; in.next() )
 
  638          out_r << *in << endl;
 
  642      inline std::string notificationCmdSubst( 
const std::string & cmd_r, 
const UpdateNotificationFile & notification_r )
 
  644        std::string ret( cmd_r );
 
  645#define SUBST_IF(PAT,VAL) if ( ret.find( PAT ) != std::string::npos ) ret = str::gsub( ret, PAT, VAL ) 
  646        SUBST_IF( 
"%p", notification_r.solvable().asString() );
 
  647        SUBST_IF( 
"%P", notification_r.file().asString() );
 
  652      void sendNotification( 
const Pathname & root_r,
 
  655        if ( notifications_r.empty() )
 
  659        MIL << 
"Notification command is '" << cmdspec << 
"'" << endl;
 
  660        if ( cmdspec.empty() )
 
  663        std::string::size_type pos( cmdspec.find( 
'|' ) );
 
  664        if ( pos == std::string::npos )
 
  666          ERR << 
"Can't send Notification: Missing 'format |' in command spec." << endl;
 
  667          HistoryLog().comment( str::Str() << 
_(
"Error sending update message notification."), 
true );
 
  672        std::string commandStr( 
str::trim( cmdspec.substr( pos + 1 ) ) );
 
  674        enum Format { 
UNKNOWN, NONE, SINGLE, DIGEST, BULK };
 
  676        if ( formatStr == 
"none" )
 
  678        else if ( formatStr == 
"single" )
 
  680        else if ( formatStr == 
"digest" )
 
  682        else if ( formatStr == 
"bulk" )
 
  686          ERR << 
"Can't send Notification: Unknown format '" << formatStr << 
" |' in command spec." << endl;
 
  687          HistoryLog().comment( str::Str() << 
_(
"Error sending update message notification."), 
true );
 
  695        if ( format == NONE || format == SINGLE )
 
  697          for_( it, notifications_r.begin(), notifications_r.end() )
 
  699            std::vector<std::string> command;
 
  700            if ( format == SINGLE )
 
  702            str::splitEscaped( notificationCmdSubst( commandStr, *it ), std::back_inserter( command ) );
 
  707              for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
 
  711              int ret = prog.close();
 
  714                ERR << 
"Notification command returned with error (" << ret << 
")." << endl;
 
  715                HistoryLog().comment( str::Str() << 
_(
"Error sending update message notification."), 
true );
 
  721        else if ( format == DIGEST || format == BULK )
 
  723          filesystem::TmpFile tmpfile;
 
  724          std::ofstream out( tmpfile.path().c_str() );
 
  725          for_( it, notifications_r.begin(), notifications_r.end() )
 
  727            if ( format == DIGEST )
 
  729              out << it->file() << endl;
 
  731            else if ( format == BULK )
 
  737          std::vector<std::string> command;
 
  738          command.push_back( 
"<"+tmpfile.path().asString() ); 
 
  739          str::splitEscaped( notificationCmdSubst( commandStr, *notifications_r.begin() ), std::back_inserter( command ) );
 
  744            for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
 
  748            int ret = prog.close();
 
  751              ERR << 
"Notification command returned with error (" << ret << 
")." << endl;
 
  752              HistoryLog().comment( str::Str() << 
_(
"Error sending update message notification."), 
true );
 
  759          INT << 
"Can't send Notification: Missing handler for 'format |' in command spec." << endl;
 
  760          HistoryLog().comment( str::Str() << 
_(
"Error sending update message notification."), 
true );
 
  771      void RunUpdateMessages( 
const Pathname & root_r,
 
  772                              const Pathname & messagesPath_r,
 
  773                              const std::vector<sat::Solvable> & checkPackages_r,
 
  774                              ZYppCommitResult & result_r )
 
  776        if ( checkPackages_r.empty() )
 
  779        MIL << 
"Looking for new update messages in (" <<  root_r << 
")" << messagesPath_r << endl;
 
  781        if ( ! PathInfo( messagesDir ).isDir() )
 
  784        std::list<std::string> messages;
 
  786        if ( messages.empty() )
 
  792        HistoryLog historylog;
 
  793        for_( it, checkPackages_r.begin(), checkPackages_r.end() )
 
  795          std::string prefix( 
str::form( 
"%s-%s", it->name().c_str(), it->edition().c_str() ) );
 
  796          for_( sit, messages.begin(), messages.end() )
 
  801            if ( (*sit)[prefix.size()] != 
'\0' && (*sit)[prefix.size()] != 
'-' )
 
  804            PathInfo message( messagesDir / *sit );
 
  805            if ( ! message.isFile() || message.size() == 0 )
 
  808            MIL << 
"Found update message " << *sit << endl;
 
  809            Pathname localPath( messagesPath_r/(*sit) ); 
 
  810            result_r.rUpdateMessages().push_back( UpdateNotificationFile( *it, localPath ) );
 
  811            historylog.comment( str::Str() << 
_(
"New update message") << 
" " << localPath, 
true );
 
  814        sendNotification( root_r, result_r.updateMessages() );
 
  820      void logPatchStatusChanges( 
const sat::Transaction & transaction_r, 
TargetImpl & target_r )
 
  823        if ( changedPseudoInstalled.empty() )
 
  831          WAR << 
"Need to recompute the patch status changes as commit is incomplete!" << endl;
 
  834          changedPseudoInstalled = establishedStates.changedPseudoInstalled();
 
  837        HistoryLog historylog;
 
  838        for ( 
const auto & el : changedPseudoInstalled )
 
  839          historylog.patchStateChange( el.first, el.second );
 
  848                             const std::vector<sat::Solvable> & checkPackages_r,
 
  850    { RunUpdateMessages( root_r, messagesPath_r, checkPackages_r, result_r ); }
 
 
  868      _rpm.initDatabase( root_r, doRebuild_r );
 
  873      sigMultiversionSpecChanged();     
 
  874      MIL << 
"Initialized target on " << 
_root << endl;
 
 
  882      std::ifstream uuidprovider( 
"/proc/sys/kernel/random/uuid" );
 
 
  892                            boost::function<
bool ()> condition,
 
  893                            boost::function<std::string ()> value )
 
  895        std::string val = value();
 
  903            MIL << 
"updating '" << filename << 
"' content." << endl;
 
  907            std::ofstream filestr;
 
  910            filestr.open( filename.
c_str() );
 
  912            if ( filestr.good() )
 
 
  948        WAR << 
"Can't create anonymous id file" << endl;
 
 
  957      Pathname flavorpath( 
home() / 
"LastDistributionFlavor");
 
  963          WAR << 
"No base product, I won't create flavor cache" << endl;
 
  967      std::string flavor = p->flavor();
 
  979        WAR << 
"Can't create flavor cache" << endl;
 
 
  991      _rpm.closeDatabase();
 
  992      sigMultiversionSpecChanged();     
 
  993      MIL << 
"Closed target on " << 
_root << endl;
 
 
 1019      bool build_rpm_solv = 
true;
 
 1029        MIL << 
"Read cookie: " << cookie << endl;
 
 1034          if ( status == rpmstatus )
 
 1035            build_rpm_solv = 
false;
 
 1036          MIL << 
"Read cookie: " << rpmsolvcookie << 
" says: " 
 1037          << (build_rpm_solv ? 
"outdated" : 
"uptodate") << endl;
 
 1041      if ( build_rpm_solv )
 
 1055          bool switchingToTmpSolvfile = 
false;
 
 1056          Exception ex(
"Failed to cache rpm database.");
 
 1062            rpmsolv       = 
base/
"solv";
 
 1063            rpmsolvcookie = 
base/
"cookie";
 
 1070              WAR << 
"Using a temporary solv file at " << 
base << endl;
 
 1071              switchingToTmpSolvfile = 
true;
 
 1080          if ( ! switchingToTmpSolvfile )
 
 1090#ifdef ZYPP_RPMDB2SOLV_PATH 
 1091        cmd.push_back( ZYPP_RPMDB2SOLV_PATH );
 
 1093        cmd.push_back( 
"rpmdb2solv" );
 
 1095        if ( ! 
_root.empty() ) {
 
 1096          cmd.push_back( 
"-r" );
 
 1097          cmd.push_back( 
_root.asString() );
 
 1099        cmd.push_back( 
"-D" );
 
 1101        cmd.push_back( 
"-X" );  
 
 1103        cmd.push_back( 
"-p" );
 
 1106        if ( ! oldSolvFile.
empty() )
 
 1107          cmd.push_back( oldSolvFile.
asString() );
 
 1109        cmd.push_back( 
"-o" );
 
 1113        std::string errdetail;
 
 1116          WAR << 
"  " << output;
 
 1117          if ( errdetail.empty() ) {
 
 1121          errdetail += output;
 
 1124        int ret = prog.
close();
 
 1145        if ( 
root() == 
"/" )
 
 1159      return build_rpm_solv;
 
 
 1177      MIL << 
"New cache built: " << (newCache?
"true":
"false") <<
 
 1178        ", force loading: " << (force?
"true":
"false") << endl;
 
 1183      MIL << 
"adding " << rpmsolv << 
" to pool(" << satpool.
systemRepoAlias() << 
")" << endl;
 
 1190        if ( newCache || force )
 
 1207        MIL << 
"adding " << rpmsolv << 
" to system" << endl;
 
 1213        MIL << 
"Try to handle exception by rebuilding the solv-file" << endl;
 
 1238          if ( 
PathInfo( historyFile ).isExist() )
 
 1245              if ( onSystemByUser.find( ident ) == onSystemByUser.end() )
 
 1246                onSystemByAuto.insert( ident );
 
 1262        sat::SolvableSpec needrebootSpec;
 
 1263        needrebootSpec.addProvides( 
Capability(
"installhint(reboot-needed)") );
 
 1264        needrebootSpec.addProvides( 
Capability(
"kernel") );
 
 1267        if ( 
PathInfo( needrebootFile ).isFile() )
 
 1268          needrebootSpec.parseFrom( needrebootFile );
 
 1271        if ( 
PathInfo( needrebootDir ).isDir() )
 
 1276                                  [&]( 
const Pathname & dir_r, 
const char *
const str_r )->
bool 
 1278                                    if ( ! isRpmConfigBackup( str_r ) )
 
 1280                                      Pathname needrebootFile { needrebootDir / str_r };
 
 1281                                      if ( 
PathInfo( needrebootFile ).isFile() )
 
 1282                                        needrebootSpec.parseFrom( needrebootFile );
 
 1293        if ( ! hardLocks.empty() )
 
 1302      MIL << 
"Target loaded: " << system.
solvablesSize() << 
" resolvables" << endl;
 
 
 1314      bool explicitDryRun = policy_r.
dryRun();    
 
 1324        if ( 
root() == 
"/" )
 
 1338      MIL << 
"TargetImpl::commit(<pool>, " << policy_r << 
")" << endl;
 
 1357          steps.push_back( *it );
 
 1364      MIL << 
"Todo: " << result << endl;
 
 1375      if ( commitPlugins )
 
 1376        commitPlugins.
send( transactionPluginFrame( 
"COMMITBEGIN", steps ) );
 
 1383        if ( ! policy_r.
dryRun() )
 
 1389          DBG << 
"dryRun: Not writing upgrade testcase." << endl;
 
 1396      if ( ! policy_r.
dryRun() )
 
 1418        DBG << 
"dryRun: Not storing non-package data." << endl;
 
 1425      if ( ! policy_r.
dryRun() )
 
 1427        for_( it, steps.begin(), steps.end() )
 
 1429          if ( ! it->satSolvable().isKind<
Patch>() )
 
 1437          if ( ! patch ||patch->message().empty()  )
 
 1440          MIL << 
"Show message for " << patch << endl;
 
 1442          if ( ! report->show( patch ) )
 
 1444            WAR << 
"commit aborted by the user" << endl;
 
 1451        DBG << 
"dryRun: Not checking patch messages." << endl;
 
 1466        std::unique_ptr<CommitPackagePreloader> preloader;
 
 1472            preloader = std::make_unique<CommitPackagePreloader>();
 
 1473            preloader->preloadTransaction( steps );
 
 1474            miss = preloader->missed ();
 
 1481            for_( it, steps.begin(), steps.end() )
 
 1483              switch ( it->stepType() )
 
 1502                  localfile = packageCache.
get( pi );
 
 1505                catch ( 
const AbortRequestException & exp )
 
 1509                  WAR << 
"commit cache preload aborted by the user" << endl;
 
 1513                catch ( 
const SkipRequestException & exp )
 
 1518                  WAR << 
"Skipping cache preload package " << pi->asKind<
Package>() << 
" in commit" << endl;
 
 1528                  INT << 
"Unexpected Error: Skipping cache preload package " << pi->asKind<
Package>() << 
" in commit" << endl;
 
 1539          ERR << 
"Some packages could not be provided. Aborting commit."<< endl;
 
 1543          if ( ! policy_r.
dryRun() )
 
 1551              commit( policy_r, packageCache, result );
 
 1555              preloader->cleanupCaches ();
 
 1559            DBG << 
"dryRun/downloadOnly: Not installing/deleting anything." << endl;
 
 1560            if ( explicitDryRun ) {
 
 1574        DBG << 
"dryRun: Not downloading/installing/deleting anything." << endl;
 
 1575        if ( explicitDryRun ) {
 
 1587          WAR << 
"(rpm removed in commit?) Inject missing /var/lib/rpm compat symlink to /usr/lib/sysimage/rpm" << endl;
 
 1596      if ( commitPlugins )
 
 1597        commitPlugins.
send( transactionPluginFrame( 
"COMMITEND", steps ) );
 
 1602      if ( ! policy_r.
dryRun() )
 
 1607      MIL << 
"TargetImpl::commit(<pool>, " << policy_r << 
") returns: " << result << endl;
 
 
 1618      struct NotifyAttemptToModify
 
 1620        NotifyAttemptToModify( 
ZYppCommitResult & result_r ) : _result( result_r ) {}
 
 1623        { 
if ( _guard ) { _result.attemptToModify( 
true ); _guard = 
false; } }
 
 1626        ZYppCommitResult & _result;
 
 1636      MIL << 
"TargetImpl::commit(<list>" << policy_r << 
")" << steps.size() << endl;
 
 1641      NotifyAttemptToModify attemptToModify( result_r );
 
 1646      AssertProcMounted assertProcMounted( 
_root );
 
 1647      AssertDevMounted assertDevMounted( 
_root ); 
 
 1650      std::vector<sat::Solvable> successfullyInstalledPackages;
 
 1653      for_( step, steps.begin(), steps.end() )
 
 1658          if ( citem->isKind<
Package>() )
 
 1667        if ( citem->isKind<
Package>() )
 
 1675              localfile = packageCache_r.
get( citem );
 
 1677            catch ( 
const AbortRequestException &e )
 
 1679              WAR << 
"commit aborted by the user" << endl;
 
 1684            catch ( 
const SkipRequestException &e )
 
 1687              WAR << 
"Skipping package " << p << 
" in commit" << endl;
 
 1696              INT << 
"Unexpected Error: Skipping package " << p << 
" in commit" << endl;
 
 1705            bool success = 
false;
 
 1731                WAR << 
"commit aborted by the user" << endl;
 
 1740                  auto rebootNeededFile = 
root() / 
"/run/reboot-needed";
 
 1756                WAR << 
"dry run failed" << endl;
 
 1763                WAR << 
"commit aborted by the user" << endl;
 
 1768                WAR << 
"Install failed" << endl;
 
 1774            if ( success && !policy_r.
dryRun() )
 
 1777              successfullyInstalledPackages.push_back( citem.
satSolvable() );
 
 1786            bool success = 
false;
 
 1799                WAR << 
"commit aborted by the user" << endl;
 
 1815                WAR << 
"commit aborted by the user" << endl;
 
 1821              WAR << 
"removal of " << p << 
" failed";
 
 1824            if ( success && !policy_r.
dryRun() )
 
 1831        else if ( ! policy_r.
dryRun() ) 
 
 1835          if ( ! citem.
buddy() )
 
 1837            if ( citem->isKind<
Product>() )
 
 1842                ERR << 
"Can't install orphan product without release-package! " << citem << endl;
 
 1848                std::string referenceFilename( p->referenceFilename() );
 
 1849                if ( referenceFilename.empty() )
 
 1851                  ERR << 
"Can't remove orphan product without 'referenceFilename'! " << citem << endl;
 
 1855                  Pathname referencePath { 
Pathname(
"/etc/products.d") / referenceFilename };   
 
 1856                  if ( ! 
rpm().hasFile( referencePath.asString() ) )
 
 1861                      ERR << 
"Delete orphan product failed: " << referencePath << endl;
 
 1865                    WAR << 
"Won't remove orphan product: '/etc/products.d/" << referenceFilename << 
"' is owned by a package." << endl;
 
 1894      if ( ! successfullyInstalledPackages.empty() )
 
 1897                                 successfullyInstalledPackages, abort ) )
 
 1899          WAR << 
"Commit aborted by the user" << endl;
 
 1905                           successfullyInstalledPackages,
 
 1912      logPatchStatusChanges( result_r.
transaction(), *
this );
 
 
 1931      void sendLogline( 
const std::string & line_r, ReportType::loglevel level_r = ReportType::loglevel::msg )
 
 1934        data.
set( 
"line", std::cref(line_r) );
 
 1935        data.set( 
"level", level_r );
 
 
 1941        auto u2rpmlevel = []( 
unsigned rpmlevel_r ) -> ReportType::loglevel {
 
 1942          switch ( rpmlevel_r ) {
 
 1943            case RPMLOG_EMERG:  [[fallthrough]];  
 
 1944            case RPMLOG_ALERT:  [[fallthrough]];  
 
 1946              return ReportType::loglevel::crt;
 
 1948              return ReportType::loglevel::err;
 
 1949            case RPMLOG_WARNING:                  
 
 1950              return ReportType::loglevel::war;
 
 1951            default:            [[fallthrough]];
 
 1952            case RPMLOG_NOTICE: [[fallthrough]];  
 
 1954              return ReportType::loglevel::msg;
 
 1956              return ReportType::loglevel::dbg;
 
 
 1964      { (*this)->report( userData_r ); }
 
 
 
 1981      MIL << 
"TargetImpl::commit(<list>" << policy_r << 
")" << steps.size() << endl;
 
 1986      NotifyAttemptToModify attemptToModify( result_r );
 
 1992      AssertProcMounted assertProcMounted( 
_root );
 
 1993      AssertDevMounted assertDevMounted( 
_root ); 
 
 2007      proto::target::Commit 
commit;
 
 2017        for ( 
auto &[
_, value] : data ) {
 
 2019          value.resetDispose();
 
 2025      for ( 
int stepId = 0; (ZYppCommitResult::TransactionStepList::size_type)stepId < steps.size() && !abort ; ++stepId ) {
 
 2026        auto &step = steps[stepId];
 
 2029          if ( citem->isKind<
Package>() )
 
 2038        if ( citem->isKind<
Package>() ) {
 
 2043              locCache.value()[stepId] = packageCache_r.
get( citem );
 
 2045              proto::target::InstallStep tStep;
 
 2046              tStep.stepId        = stepId;
 
 2047              tStep.pathname      = locCache.
value()[stepId]->asString();
 
 2048              tStep.multiversion  = p->multiversionInstall() ;
 
 2050              commit.transactionSteps.push_back( std::move(tStep) );
 
 2052            catch ( 
const AbortRequestException &e )
 
 2054              WAR << 
"commit aborted by the user" << endl;
 
 2059            catch ( 
const SkipRequestException &e )
 
 2062              WAR << 
"Skipping package " << p << 
" in commit" << endl;
 
 2071              INT << 
"Unexpected Error: Skipping package " << p << 
" in commit" << endl;
 
 2077            proto::target::RemoveStep tStep;
 
 2078            tStep.stepId  = stepId;
 
 2079            tStep.name    = p->name();
 
 2080            tStep.version = p->edition().version();
 
 2081            tStep.release = p->edition().release();
 
 2082            tStep.arch    = p->arch().asString();
 
 2083            commit.transactionSteps.push_back(std::move(tStep));
 
 2094            proto::target::InstallStep tStep;
 
 2095            tStep.stepId        = stepId;
 
 2096            tStep.pathname      = locCache.value()[stepId]->asString();
 
 2097            tStep.multiversion  = 
false;
 
 2098            commit.transactionSteps.push_back(std::move(tStep));
 
 2102            INT << 
"Unexpected Error: Skipping package " << p << 
" in commit" << endl;
 
 2109      std::vector<sat::Solvable> successfullyInstalledPackages;
 
 2111      if ( 
commit.transactionSteps.size() ) {
 
 2118        const std::vector<int> interceptedSignals {
 
 2125        auto unixSignals = loop->eventDispatcher()->unixSignalSource();
 
 2126        unixSignals->sigReceived ().connect ([]( 
int signum ){
 
 2128          JobReport::error ( 
str::Format(
_(
"Received signal :\"%1% (%2%)\", to ensure the consistency of the system it is not possible to cancel a running rpm transaction.") ) % strsignal(signum) % signum );
 
 2130        for( 
const auto &sig : interceptedSignals )
 
 2131          unixSignals->addSignal ( sig );
 
 2134          for( 
const auto &sig : interceptedSignals )
 
 2135            unixSignals->removeSignal ( sig );
 
 2142        int currentStepId = -1;
 
 2148        bool gotEndOfScript = 
false;
 
 2151        std::unique_ptr<callback::SendReport <rpm::TransactionReportSA>>        transactionreport;
 
 2152        std::unique_ptr<callback::SendReport <rpm::InstallResolvableReportSA>>  installreport;
 
 2153        std::unique_ptr<callback::SendReport <rpm::RemoveResolvableReportSA>>   uninstallreport;
 
 2154        std::unique_ptr<callback::SendReport <rpm::CommitScriptReportSA>>       scriptreport;
 
 2155        std::unique_ptr<callback::SendReport <rpm::CleanupPackageReportSA>>     cleanupreport;
 
 2158        std::optional<proto::target::TransactionError> transactionError;
 
 2161        std::string currentScriptType;
 
 2162        std::string currentScriptPackage;
 
 2172        unsigned    lineno = 0;
 
 2180        zyppng::StompFrameStreamRef msgStream;
 
 2185        const auto &sendRpmLineToReport = [&]( 
const std::string &line ){
 
 2187          const auto &sendLogRep = [&]( 
auto &report, 
const auto &cType ){
 
 2189            if ( currentStepId >= 0 )
 
 2190              cmdout.
set( 
"solvable", steps.at(currentStepId).satSolvable() );
 
 2191            cmdout.
set( 
"line", line );
 
 2195          if ( installreport ) {
 
 2196            sendLogRep( (*installreport), rpm::InstallResolvableReportSA::contentRpmout );
 
 2197          } 
else if ( uninstallreport ) {
 
 2198            sendLogRep( (*uninstallreport), rpm::RemoveResolvableReportSA::contentRpmout );
 
 2199          } 
else if ( scriptreport ) {
 
 2200            sendLogRep( (*scriptreport), rpm::CommitScriptReportSA::contentRpmout );
 
 2201          } 
else if ( transactionreport ) {
 
 2202            sendLogRep( (*transactionreport), rpm::TransactionReportSA::contentRpmout );
 
 2203          } 
else if ( cleanupreport ) {
 
 2204            sendLogRep( (*cleanupreport), rpm::CleanupPackageReportSA::contentRpmout );
 
 2206            WAR << 
"Got rpm output without active report " << line; 
 
 2211            if ( line.find( 
" scriptlet failed, " ) == std::string::npos )      
 
 2215          if ( line.back() != 
'\n' )
 
 2221        const auto &processDataFromScriptFd = [&](){
 
 2223          while ( scriptSource->canReadLine() ) {
 
 2225            if ( gotEndOfScript )
 
 2228            std::string l = scriptSource->readLine().asString();
 
 2230              gotEndOfScript = 
true;
 
 2231              std::string::size_type rawsize { l.size() - endOfScriptTag.size() };
 
 2234              l = l.substr( 0, rawsize );
 
 2236            L_DBG(
"zypp-rpm") << 
"[rpm> " << l; 
 
 2237            sendRpmLineToReport( l );
 
 2240        scriptSource->sigReadyRead().connect( processDataFromScriptFd );
 
 2243        const auto &waitForScriptEnd = [&]() {
 
 2246          if ( gotEndOfScript )
 
 2250          processDataFromScriptFd();
 
 2253          while ( scriptSource->readFdOpen() && scriptSource->canRead() && !gotEndOfScript ) {
 
 2256            scriptSource->waitForReadyRead( 100 );
 
 2260        const auto &aboutToStartNewReport = [&](){
 
 2262          if ( transactionreport || installreport || uninstallreport || scriptreport || cleanupreport ) {
 
 2263            ERR << 
"There is still a running report, this is a bug" << std::endl;
 
 2267          gotEndOfScript = 
false;
 
 2270        const auto &writeRpmMsgToHistory = [&](){
 
 2271          if ( rpmmsg.size() == 0 )
 
 2275            rpmmsg += 
"[truncated]\n";
 
 2277          std::ostringstream sstr;
 
 2278          sstr << 
"rpm output:" << endl << rpmmsg << endl;
 
 2283        const auto &finalizeCurrentReport = [&]() {
 
 2286          if ( currentStepId >= 0 ) {
 
 2287            step = &steps.at(currentStepId);
 
 2291          if ( installreport ) {
 
 2299              writeRpmMsgToHistory();
 
 2303              ( *installreport)->progress( 100, resObj );
 
 2306              if ( currentStepId >= 0 )
 
 2307                locCache.value().erase( currentStepId );
 
 2308              successfullyInstalledPackages.push_back( step->
satSolvable() );
 
 2314                  auto rebootNeededFile = 
root() / 
"/run/reboot-needed";
 
 2326              writeRpmMsgToHistory();
 
 2329          if ( uninstallreport ) {
 
 2337              writeRpmMsgToHistory();
 
 2341              ( *uninstallreport)->progress( 100, resObj );
 
 2351              writeRpmMsgToHistory();
 
 2354          if ( scriptreport ) {
 
 2356            ( *scriptreport)->progress( 100, resObj );
 
 2359          if ( transactionreport ) {
 
 2361            ( *transactionreport)->progress( 100 );
 
 2364          if ( cleanupreport ) {
 
 2366            ( *cleanupreport)->progress( 100 );
 
 2372          currentScriptType.clear();
 
 2373          currentScriptPackage.clear();
 
 2374          installreport.reset();
 
 2375          uninstallreport.reset();
 
 2376          scriptreport.reset();
 
 2377          transactionreport.reset();
 
 2378          cleanupreport.reset();
 
 2388        constexpr std::string_view zyppRpmBinary(ZYPP_RPM_BINARY);
 
 2390        const char *argv[] = {
 
 2393          zyppRpmBinary.data(),
 
 2410        prog->addFd( messagePipe->writeFd );
 
 2411        prog->addFd( scriptPipe->writeFd );
 
 2414        if ( !scriptSource->openFds( std::vector<int>{ scriptPipe->readFd } ) )
 
 2417        const auto &processMessages = [&] ( ) {
 
 2421          const auto &checkMsgWithStepId = [&steps]( 
auto &p ){
 
 2423              ERR << 
"Failed to parse message from zypp-rpm." << std::endl;
 
 2427            auto id = p->stepId;
 
 2428            if ( id < 0 || id >= steps.size() ) {
 
 2429              ERR << 
"Received invalid stepId: " << 
id << 
" in " << p->typeName << 
" message from zypp-rpm, ignoring." << std::endl;
 
 2435          while ( 
const auto &m = msgStream->nextMessage() ) {
 
 2441            const auto &mName = m->command();
 
 2442            if (  mName == proto::target::RpmLog::typeName )  {
 
 2444              const auto &p = proto::target::RpmLog::fromStompMessage (*m);
 
 2446                ERR << 
"Failed to parse " << proto::target::RpmLog::typeName << 
" message from zypp-rpm." << std::endl;
 
 2449              ( p->level >= RPMLOG_ERR     ? 
L_ERR(
"zypp-rpm")
 
 2450              : p->level >= RPMLOG_WARNING ? 
L_WAR(
"zypp-rpm")
 
 2451              : 
L_DBG(
"zypp-rpm") ) << 
"[rpm " << p->level << 
"> " << p->line; 
 
 2454            } 
else if (  mName == proto::target::PackageBegin::typeName )  {
 
 2455              finalizeCurrentReport();
 
 2457              const auto &p = proto::target::PackageBegin::fromStompMessage(*m);
 
 2458              if ( !checkMsgWithStepId( p ) )
 
 2461              aboutToStartNewReport();
 
 2463              auto & step = steps.at( p->stepId );
 
 2464              currentStepId = p->stepId;
 
 2466                uninstallreport = std::make_unique< callback::SendReport <rpm::RemoveResolvableReportSA> > ();
 
 2467                ( *uninstallreport )->start( 
makeResObject( step.satSolvable() ) );
 
 2469                installreport = std::make_unique< callback::SendReport <rpm::InstallResolvableReportSA> > ();
 
 2470                ( *installreport )->start( 
makeResObject( step.satSolvable() ) );
 
 2473            } 
else if (  mName == proto::target::PackageFinished::typeName )  {
 
 2474              const auto &p = proto::target::PackageFinished::fromStompMessage(*m);
 
 2475              if ( !checkMsgWithStepId( p ) )
 
 2482            } 
else if (  mName == proto::target::PackageProgress::typeName )  {
 
 2483              const auto &p = proto::target::PackageProgress::fromStompMessage(*m);
 
 2484              if ( !checkMsgWithStepId( p ) )
 
 2487              if ( uninstallreport )
 
 2488                (*uninstallreport)->progress( p->amount, 
makeResObject( steps.at( p->stepId ) ));
 
 2489              else if ( installreport )
 
 2490                (*installreport)->progress( p->amount, 
makeResObject( steps.at( p->stepId ) ));
 
 2492                ERR << 
"Received a " << mName << 
" message but there is no corresponding report running." << std::endl;
 
 2494            } 
else if (  mName == proto::target::PackageError::typeName )  {
 
 2495              const auto &p = proto::target::PackageError::fromStompMessage(*m);
 
 2496              if ( !checkMsgWithStepId( p ) )
 
 2499              if ( p->stepId >= 0 && p->stepId < steps.size() )
 
 2502              finalizeCurrentReport();
 
 2504            } 
else if (  mName == proto::target::ScriptBegin::typeName )  {
 
 2505              finalizeCurrentReport();
 
 2507              const auto &p = proto::target::ScriptBegin::fromStompMessage(*m);
 
 2509                ERR << 
"Failed to parse " << proto::target::ScriptBegin::typeName << 
" message from zypp-rpm." << std::endl;
 
 2513              aboutToStartNewReport();
 
 2516              const auto stepId = p->stepId;
 
 2517              if ( stepId >= 0 && 
static_cast<size_t>(stepId) < steps.size() ) {
 
 2521              currentStepId = p->stepId;
 
 2522              scriptreport = std::make_unique< callback::SendReport <rpm::CommitScriptReportSA> > ();
 
 2523              currentScriptType = p->scriptType;
 
 2524              currentScriptPackage = p->scriptPackage;
 
 2525              (*scriptreport)->start( currentScriptType, currentScriptPackage, resPtr );
 
 2527            } 
else if (  mName == proto::target::ScriptFinished::typeName )  {
 
 2531            } 
else if (  mName == proto::target::ScriptError::typeName )  {
 
 2533              const auto &p = proto::target::ScriptError::fromStompMessage(*m);
 
 2535                ERR << 
"Failed to parse " << proto::target::ScriptError::typeName << 
" message from zypp-rpm." << std::endl;
 
 2540              const auto stepId = p->stepId;
 
 2541              if ( stepId >= 0 && 
static_cast<size_t>(stepId) < steps.size() ) {
 
 2551                str::form(
"Failed to execute %s script for %s ", currentScriptType.c_str(), currentScriptPackage.size() ? currentScriptPackage.c_str() : 
"unknown" ),
 
 2554              writeRpmMsgToHistory();
 
 2556              if ( !scriptreport ) {
 
 2557                ERR << 
"Received a ScriptError message, but there is no running report. " << std::endl;
 
 2566              scriptreport.reset();
 
 2569            } 
else if (  mName == proto::target::CleanupBegin::typeName ) {
 
 2570              finalizeCurrentReport();
 
 2572              const auto &beg = proto::target::CleanupBegin::fromStompMessage(*m);
 
 2574                ERR << 
"Failed to parse " << proto::target::CleanupBegin::typeName << 
" message from zypp-rpm." << std::endl;
 
 2578              aboutToStartNewReport();
 
 2579              cleanupreport = std::make_unique< callback::SendReport <rpm::CleanupPackageReportSA> > ();
 
 2580              (*cleanupreport)->start( beg->nvra );
 
 2581            } 
else if (  mName == proto::target::CleanupFinished::typeName )  {
 
 2583              finalizeCurrentReport();
 
 2585            } 
else if (  mName == proto::target::CleanupProgress::typeName )  {
 
 2586              const auto &prog = proto::target::CleanupProgress::fromStompMessage(*m);
 
 2588                ERR << 
"Failed to parse " << proto::target::CleanupProgress::typeName << 
" message from zypp-rpm." << std::endl;
 
 2592              if ( !cleanupreport ) {
 
 2593                ERR << 
"Received a CleanupProgress message, but there is no running report. " << std::endl;
 
 2597              (*cleanupreport)->progress( prog->amount );
 
 2599            } 
else if (  mName == proto::target::TransBegin::typeName ) {
 
 2600              finalizeCurrentReport();
 
 2602              const auto &beg = proto::target::TransBegin::fromStompMessage(*m);
 
 2604                ERR << 
"Failed to parse " << proto::target::TransBegin::typeName << 
" message from zypp-rpm." << std::endl;
 
 2608              aboutToStartNewReport();
 
 2609              transactionreport = std::make_unique< callback::SendReport <rpm::TransactionReportSA> > ();
 
 2610              (*transactionreport)->start( beg->name );
 
 2611            } 
else if (  mName == proto::target::TransFinished::typeName )  {
 
 2613              finalizeCurrentReport();
 
 2615            } 
else if (  mName == proto::target::TransProgress::typeName )  {
 
 2616              const auto &prog = proto::target::TransProgress::fromStompMessage(*m);
 
 2618                ERR << 
"Failed to parse " << proto::target::TransProgress::typeName << 
" message from zypp-rpm." << std::endl;
 
 2622              if ( !transactionreport ) {
 
 2623                ERR << 
"Received a TransactionProgress message, but there is no running report. " << std::endl;
 
 2627              (*transactionreport)->progress( prog->amount );
 
 2628            } 
else if ( mName == proto::target::TransactionError::typeName ) {
 
 2630              const auto &error = proto::target::TransactionError::fromStompMessage(*m);
 
 2632                ERR << 
"Failed to parse " << proto::target::TransactionError::typeName  << 
" message from zypp-rpm." << std::endl;
 
 2637              transactionError = std::move(*error);
 
 2640              ERR << 
"Received unexpected message from zypp-rpm: "<< m->command() << 
", ignoring" << std::endl;
 
 2648        prog->sigStarted().connect( [&](){
 
 2651          messagePipe->unrefWrite();
 
 2652          scriptPipe->unrefWrite();
 
 2656            while( prog->canReadLine( channel ) ) {
 
 2657              L_ERR(
"zypp-rpm") <<  ( channel == 
zyppng::Process::StdOut ? 
"<stdout> " : 
"<stderr> " ) << prog->channelReadLine( channel ).asStringView();  
 
 2663          if ( !msgSource->openFds( std::vector<int>{ messagePipe->readFd }, prog->stdinFd() ) )
 
 2669          const auto &msg = 
commit.toStompMessage();
 
 2671            std::rethrow_exception ( msg.error() );
 
 2673          if ( !msgStream->sendMessage( *msg ) ) {
 
 2674            prog->stop( SIGKILL );
 
 2680        int zyppRpmExitCode = -1;
 
 2682          zyppRpmExitCode = code;
 
 2686        if ( !prog->start( argv ) ) {
 
 2695          msgStream->readAllMessages();
 
 2702        finalizeCurrentReport();
 
 2705        bool readMsgs = 
false;
 
 2715        while ( scriptSource->canReadLine() ) {
 
 2717          MIL << 
"rpm-script-fd: " << scriptSource->readLine().asStringView();
 
 2719        if ( scriptSource->bytesAvailable() > 0 ) {
 
 2721          MIL << 
"rpm-script-fd: " << scriptSource->readAll().asStringView();
 
 2726        switch ( zyppRpmExitCode ) {
 
 2728          case zypprpm::NoError:
 
 2729          case zypprpm::RpmFinishedWithError:
 
 2731          case zypprpm::RpmFinishedWithTransactionError: {
 
 2733            if ( transactionError ) {
 
 2735              std::ostringstream sstr;
 
 2736              sstr << 
_(
"Executing the transaction failed because of the following problems:") << 
"\n";
 
 2737              for ( 
const auto & err : transactionError->problems ) {
 
 2738                sstr << 
"    " << err << 
"\n";
 
 2748          case zypprpm::FailedToOpenDb:
 
 2751          case zypprpm::WrongHeaderSize:
 
 2752          case zypprpm::WrongMessageFormat:
 
 2755          case zypprpm::RpmInitFailed:
 
 2758          case zypprpm::FailedToReadPackage:
 
 2761          case zypprpm::FailedToAddStepToTransaction:
 
 2764          case zypprpm::RpmOrderFailed:
 
 2767          case zypprpm::FailedToCreateLock:
 
 2772        for ( 
int stepId = 0; (ZYppCommitResult::TransactionStepList::size_type)stepId < steps.size() && !abort; ++stepId ) {
 
 2773          auto &step = steps[stepId];
 
 2785                  ERR << 
"Can't install orphan product without release-package! " << citem << endl;
 
 2789                  std::string referenceFilename( p->referenceFilename() );
 
 2791                  if ( referenceFilename.empty() ) {
 
 2792                    ERR << 
"Can't remove orphan product without 'referenceFilename'! " << citem << endl;
 
 2794                    Pathname referencePath { 
Pathname(
"/etc/products.d") / referenceFilename }; 
 
 2796                    if ( ! 
rpm().hasFile( referencePath.asString() ) ) {
 
 2800                        ERR << 
"Delete orphan product failed: " << referencePath << endl;
 
 2802                      WAR << 
"Won't remove orphan product: '/etc/products.d/" << referenceFilename << 
"' is owned by a package." << endl;
 
 2816      if ( ! successfullyInstalledPackages.empty() )
 
 2819               successfullyInstalledPackages, abort ) )
 
 2821          WAR << 
"Commit aborted by the user" << endl;
 
 2827          successfullyInstalledPackages,
 
 2834      logPatchStatusChanges( result_r.
transaction(), *
this );
 
 
 2851      return _rpm.hasFile(path_str, name_str);
 
 
 2862        if ( baseproduct.isFile() )
 
 2875          ERR << 
"baseproduct symlink is dangling or missing: " << baseproduct << endl;
 
 2880      inline Pathname staticGuessRoot( 
const Pathname & root_r )
 
 2882        if ( root_r.empty() )
 
 2887            return Pathname(
"/");
 
 2893      inline std::string firstNonEmptyLineIn( 
const Pathname & file_r )
 
 2895        std::ifstream idfile( file_r.c_str() );
 
 2896        for( iostr::EachLine in( idfile ); in; in.next() )
 
 2899          if ( ! line.empty() )
 
 2902        return std::string();
 
 2913        if ( p->isTargetDistribution() )
 
 
 2921      const Pathname needroot( staticGuessRoot(root_r) );
 
 2924        return target->requestedLocales();
 
 
 2930      MIL << 
"updateAutoInstalled if changed..." << endl;
 
 
 2938    { 
return baseproductdata( 
_root ).registerTarget(); }
 
 
 2941    { 
return baseproductdata( staticGuessRoot(root_r) ).registerTarget(); }
 
 
 2944    { 
return baseproductdata( 
_root ).registerRelease(); }
 
 
 2947    { 
return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
 
 
 2950    { 
return baseproductdata( 
_root ).registerFlavor(); }
 
 
 2953    { 
return baseproductdata( staticGuessRoot(root_r) ).registerFlavor();}
 
 
 2986      const Pathname & needroot = staticGuessRoot(root_r);
 
 
 3004      return firstNonEmptyLineIn( 
home() / 
"LastDistributionFlavor" );
 
 
 3009      return firstNonEmptyLineIn( staticGuessRoot(root_r) / 
"/var/lib/zypp/LastDistributionFlavor" );
 
 
 3015      std::string guessAnonymousUniqueId( 
const Pathname & root_r )
 
 3018        std::string ret( firstNonEmptyLineIn( root_r / 
"/var/lib/zypp/AnonymousUniqueId" ) );
 
 3019        if ( ret.
empty() && root_r != 
"/" )
 
 3022          ret = firstNonEmptyLineIn( 
"/var/lib/zypp/AnonymousUniqueId" );
 
 3030      return guessAnonymousUniqueId( 
root() );
 
 
 3035      return guessAnonymousUniqueId( staticGuessRoot(root_r) );
 
 
 3042      MIL << 
"New VendorAttr: " << vendorAttr_r << endl;
 
 
#define MAXRPMMESSAGELINES
#define SUBST_IF(PAT, VAL)
const std::string & asString() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool compatibleWith(const Arch &targetArch_r) const
Compatibility relation.
bool operator()(const zypp::Arch &lhs, const zypp::Arch &rhs) const
Default order for std::container based Arch::compare.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
reference value() const
Reference to the Tp object.
void resetDispose()
Set no dispose function.
Store and operate on date (time_t).
static Date now()
Return the current time.
Edition represents [epoch:]version[-release]
std::string version() const
Version.
unsigned int epoch_t
Type of an epoch.
std::string release() const
Release.
epoch_t epoch() const
Epoch.
Base class for Exception.
void remember(const Exception &old_r)
Store an other Exception as history.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
int close() override
Wait for the progamm to complete.
const std::string & command() const
The command we're executing.
std::vector< std::string > Arguments
Writing the zypp history file.
void stampCommand()
Log info about the current process.
static void setRoot(const Pathname &root)
Set new root directory to the default history log file path.
void remove(const PoolItem &pi)
Log removal of a package.
static const Pathname & fname()
Get the current log file path.
void install(const PoolItem &pi)
Log installation (or update) of a package.
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
Access to the sat-pools string space.
const char * c_str() const
Conversion to const char *
std::string asString() const
Conversion to std::string
@ REGEX
Regular Expression.
TraitsType::constPtrType constPtr
Class representing a patch.
TraitsType::constPtrType constPtr
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
Parallel execution of stateful PluginScripts.
void load(const Pathname &path_r)
Find and launch plugins sending PLUGINBEGIN.
void send(const PluginFrame &frame_r)
Send PluginFrame to all open plugins.
Command frame for communication with PluginScript.
Combining sat::Solvable and ResStatus.
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
ResStatus & status() const
Returns the current status.
sat::Solvable buddy() const
Return the buddy we share our status object with.
TraitsType::constPtrType constPtr
Track changing files or directories.
static RepoStatus fromCookieFile(const Pathname &path)
Reads the status from a cookie file.
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
bool solvablesEmpty() const
Whether Repository contains solvables.
SolvableIterator solvablesEnd() const
Iterator behind the last Solvable.
SolvableIterator solvablesBegin() const
Iterator to the first Solvable.
size_type solvablesSize() const
Number of solvables in Repository.
void addSolv(const Pathname &file_r)
Load Solvables from a solv-file.
void eraseFromPool()
Remove this Repository from its Pool.
static ResPool instance()
Singleton ctor.
void setHardLockQueries(const HardLockQueries &newLocks_r)
Set a new set of queries.
Resolver & resolver() const
The Resolver.
const LocaleSet & getRequestedLocales() const
Return the requested locales.
ChangedPseudoInstalled changedPseudoInstalled() const
Return all pseudo installed items whose current state differs from their initial one.
EstablishedStates establishedStates() const
Factory for EstablishedStates.
void getHardLockQueries(HardLockQueries &activeLocks_r)
Suggest a new set of queries based on the current selection.
EstablishedStates::ChangedPseudoInstalled ChangedPseudoInstalled
Map holding pseudo installed items where current and established status differ.
bool isToBeInstalled() const
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
TraitsType::constPtrType constPtr
sat::Transaction getTransaction()
Return the Transaction computed by the last solver run.
bool upgradingRepos() const
Whether there is at least one UpgradeRepo request pending.
Attempts to create a lock to prevent the system from going into hibernate/shutdown.
TraitsType::constPtrType constPtr
String matching (STRING|SUBSTRING|GLOB|REGEX).
Definition of vendor equivalence.
Interim helper class to collect global options and settings.
Arch systemArchitecture() const
The system architecture zypp uses.
static ZConfig & instance()
Singleton ctor.
Options and policies for ZYpp::commit.
ZYppCommitPolicy & rpmInstFlags(target::rpm::RpmInstFlags newFlags_r)
The default target::rpm::RpmInstFlags.
bool singleTransModeEnabled() const
ZYppCommitPolicy & rpmExcludeDocs(bool yesNo_r)
Use rpm option –excludedocs (default: false)
ZYppCommitPolicy & dryRun(bool yesNo_r)
Set dry run (default: false).
ZYppCommitPolicy & restrictToMedia(unsigned mediaNr_r)
Restrict commit to media 1.
ZYppCommitPolicy & downloadMode(DownloadMode val_r)
Commit download policy to use.
ZYppCommitPolicy & allMedia()
Process all media (default)
ZYppCommitPolicy & rpmNoSignature(bool yesNo_r)
Use rpm option –nosignature (default: false)
Result returned from ZYpp::commit.
TransactionStepList & rTransactionStepList()
Manipulate transactionStepList.
void setSingleTransactionMode(bool yesno_r)
std::vector< sat::Transaction::Step > TransactionStepList
const sat::Transaction & transaction() const
The full transaction list.
sat::Transaction & rTransaction()
Manipulate transaction.
ZYpp::Ptr getZYpp()
Convenience to get the Pointer to the ZYpp instance.
static zypp::Pathname lockfileDir()
Typesafe passing of user data via callbacks.
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
zypp::ContentType ContentType
std::string receiveLine()
Read one line from the input stream.
Wrapper class for stat/lstat.
bool isExist() const
Return whether valid stat info exists.
Pathname dirname() const
Return all but the last component od this path.
const char * c_str() const
String representation.
const std::string & asString() const
String representation.
bool empty() const
Test for an empty path.
Provide a new empty temporary file and delete it when no longer needed.
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Data returned by ProductFileReader.
bool empty() const
Whether this is an empty object without valid data.
std::string summary() const
std::string shortName() const
static ProductFileData scanFile(const Pathname &file_r)
Parse one file (or symlink) and return the ProductFileData parsed.
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r) const
Provide SrcPackage in a local file.
void setAutoInstalled(const Queue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Pathname rootDir() const
Get rootdir (for file conflicts check)
static Pool instance()
Singleton ctor.
static const std::string & systemRepoAlias()
Reserved system repository alias @System .
void setNeedrebootSpec(sat::SolvableSpec needrebootSpec_r)
Solvables which should trigger the reboot-needed hint if installed/updated.
Repository systemRepo()
Return the system repository, create it if missing.
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
detail::IdType value_type
void push(value_type val_r)
Push a value to the end off the Queue.
A Solvable object within the sat Pool.
A single step within a Transaction.
StepType stepType() const
Type of action to perform in this step.
StepStage stepStage() const
Step action result.
Solvable satSolvable() const
Return the corresponding Solvable.
Libsolv transaction wrapper.
const_iterator end() const
Iterator behind the last TransactionStep.
StringQueue autoInstalled() const
Return the ident strings of all packages that would be auto-installed after the transaction is run.
const_iterator begin() const
Iterator to the first TransactionStep.
bool order()
Order transaction steps for commit.
@ TRANSACTION_MULTIINSTALL
[M] Install(multiversion) item (
@ TRANSACTION_INSTALL
[+] Install(update) item
@ TRANSACTION_IGNORE
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
@ TRANSACTION_ERASE
[-] Delete item
@ STEP_TODO
[__] unprocessed
void multiversionSpecChanged()
Target::commit helper optimizing package provision.
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
bool preloaded() const
Whether preloaded hint is set.
ManagedFile get(const PoolItem &citem_r)
Provide a package.
pool::PoolTraits::HardLockQueries Data
Save and restore locale set from file.
const LocaleSet & locales() const
Return the loacale set.
void tryLevel(target::rpm::InstallResolvableReport::RpmLevel level_r)
Extract and remember posttrans scripts for later execution.
void executeScripts(rpm::RpmDb &rpm_r)
Execute the remembered scripts and/or or dump_posttrans lines.
void discardScripts()
Discard all remembered scripts and/or or dump_posttrans lines.
bool aborted() const
Returns true if removing is aborted during progress.
std::unordered_set< IdString > Data
Base class for concrete Target implementations.
std::string targetDistributionRelease() const
This is register.release attribute of the installed base product.
const VendorAttr & vendorAttr() const
The targets current vendor equivalence settings.
std::string targetDistribution() const
This is register.target attribute of the installed base product.
std::list< PoolItem > PoolItemList
list of pool items
LocaleSet requestedLocales() const
Languages to be supported by the system.
void updateAutoInstalled()
Update the database of autoinstalled packages.
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Provides a source package on the Target.
Pathname _root
Path to the target.
RequestedLocalesFile _requestedLocalesFile
Requested Locales database.
void createLastDistributionFlavorCache() const
generates a cache of the last product flavor
Pathname _tmpSolvfilesPath
std::string _distributionVersion
Cache distributionVersion.
rpm::RpmDb _rpm
RPM database.
~TargetImpl() override
Dtor.
rpm::RpmDb & rpm()
The RPM database.
Pathname solvfilesPath() const
The solv file location actually in use (default or temp).
std::string distributionVersion() const
This is version attribute of the installed base product.
void createAnonymousId() const
generates the unique anonymous id which is called when creating the target
SolvIdentFile _autoInstalledFile
user/auto installed database
Product::constPtr baseProduct() const
returns the target base installed product, also known as the distribution or platform.
Target::DistributionLabel distributionLabel() const
This is shortName and summary attribute of the installed base product.
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::...
HardLocksFile _hardLocksFile
Hard-Locks database.
Pathname root() const
The root set for this target.
void load(bool force=true)
std::string distributionFlavor() const
This is flavor attribute of the installed base product but does not require the target to be loaded a...
void commitInSingleTransaction(const ZYppCommitPolicy &policy_r, CommitPackageCache &packageCache_r, ZYppCommitResult &result_r)
Commit ordered changes (internal helper)
void installSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Install a source package on the Target.
ZYppCommitResult commit(ResPool pool_r, const ZYppCommitPolicy &policy_r)
Commit changes in the pool.
VendorAttr _vendorAttr
vendor equivalence settings.
Pathname home() const
The directory to store things.
void commitFindFileConflicts(const ZYppCommitPolicy &policy_r, ZYppCommitResult &result_r)
Commit helper checking for file conflicts after download.
Pathname defaultSolvfilesPath() const
The systems default solv file location.
std::string anonymousUniqueId() const
anonymous unique id
TargetImpl(const Pathname &root_r="/", bool doRebuild_r=false)
Ctor.
bool solvfilesPathIsTemp() const
Whether we're using a temp.
std::string targetDistributionFlavor() const
This is register.flavor attribute of the installed base product.
Interface to the rpm program.
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
const Pathname & root() const
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
const Pathname & dbPath() const
Subclass to retrieve rpm database content.
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
SignalProxy< void(uint)> sigChannelReadyRead()
SignalProxy< void(int)> sigFinished()
SignalProxy< void()> sigMessageReceived()
static Ptr create(IODevice::Ptr iostr)
Namespace intended to collect all environment variables we use.
bool TRANSACTIONAL_UPDATE()
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
int symlink(const Pathname &oldpath, const Pathname &newpath)
Like 'symlink'.
const StrMatcher & matchNoDots()
Convenience returning StrMatcher( "[^.]*", Match::GLOB )
int assert_file(const Pathname &path, unsigned mode)
Create an empty file if it does not yet exist.
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
int unlink(const Pathname &path)
Like 'unlink'.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like 'readlink'.
std::string md5sum(const Pathname &file)
Compute a files md5sum.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
int touch(const Pathname &path)
Change file's modification and access times.
std::string getline(std::istream &str)
Read one line from stream.
bool empty() const
Whether neither idents nor provides are set.
Queue StringQueue
Queue with String ids.
void updateSolvFileIndex(const Pathname &solvfile_r)
Create solv file content digest for zypper bash completion.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string toLower(const std::string &s)
Return lowercase version of s.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
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.
std::string trim(const std::string &s, const Trim trim_r)
void XRunUpdateMessages(const Pathname &root_r, const Pathname &messagesPath_r, const std::vector< sat::Solvable > &checkPackages_r, ZYppCommitResult &result_r)
std::string rpmDbStateHash(const Pathname &root_r)
void writeUpgradeTestcase()
static bool fileMissing(const Pathname &pathname)
helper functor
void updateFileContent(const Pathname &filename, boost::function< bool()> condition, boost::function< std::string()> value)
updates the content of filename if condition is true, setting the content the the value returned by v...
RepoStatus rpmDbRepoStatus(const Pathname &root_r)
static std::string generateRandomId()
generates a random id using uuidgen
Easy-to use interface to the ZYPP dependency resolver.
std::unordered_set< Locale > LocaleSet
AutoDispose< const Pathname > ManagedFile
A Pathname plus associated cleanup code to be executed when path is no longer needed.
std::list< UpdateNotificationFile > UpdateNotifications
ResTraits< TRes >::PtrType make(const sat::Solvable &solvable_r)
Directly create a certain kind of ResObject from sat::Solvable.
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
std::string asString(const Patch::Category &obj)
ResTraits< TRes >::PtrType asKind(const sat::Solvable &solvable_r)
Directly create a certain kind of ResObject from sat::Solvable.
@ DownloadInHeaps
Similar to DownloadInAdvance, but try to split the transaction into heaps, where at the end of each h...
@ DownloadOnly
Just download all packages to the local cache.
@ DownloadAsNeeded
Alternating download and install.
@ DownloadInAdvance
First download all packages to the local cache.
@ DownloadDefault
libzypp will decide what to do.
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
std::string asJSON() const
JSON representation.
void add(const Value &val_r)
Push JSON Value to Array.
void add(const String &key_r, const Value &val_r)
Add key/value pair.
std::string asJSON() const
JSON representation.
Solvable satSolvable() const
Return the corresponding sat::Solvable.
bool isNeedreboot() const
static PoolImpl & myPool()
Convenience SendReport<rpm::SingleTransReport> wrapper.
void report(const callback::UserData &userData_r)
void sendLoglineRpm(const std::string &line_r, unsigned rpmlevel_r)
Convenience to send a contentLogline translating a rpm loglevel.
void sendLogline(const std::string &line_r, ReportType::loglevel level_r=ReportType::loglevel::msg)
Convenience to send a contentLogline.
@ RPM_NODEPS_FORCE
only this one used
static std::optional< Pipe > create(int flags=0)
#define NON_COPYABLE(CLASS)
Delete copy ctor and copy assign.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define NON_MOVABLE(CLASS)
Delete move ctor and move assign.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
#define IMPL_PTR_TYPE(NAME)