Imported Upstream version 17.0.0
[platform/upstream/libzypp.git] / zypp / target / TargetImpl.cc
index d698c0e..b894100 100644 (file)
 #include "zypp/target/TargetCallbackReceiver.h"
 #include "zypp/target/rpm/librpmDb.h"
 #include "zypp/target/CommitPackageCache.h"
+#include "zypp/target/RpmPostTransCollector.h"
 
 #include "zypp/parser/ProductFileReader.h"
-
-#include "zypp/solver/detail/Testcase.h"
-
-#include "zypp/repo/DeltaCandidates.h"
-#include "zypp/repo/PackageProvider.h"
 #include "zypp/repo/SrcPackageProvider.h"
 
 #include "zypp/sat/Pool.h"
+#include "zypp/sat/detail/PoolImpl.h"
 #include "zypp/sat/Transaction.h"
 
-#include "zypp/PluginScript.h"
+#include "zypp/PluginExecutor.h"
 
 using namespace std;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
-{ /////////////////////////////////////////////////////////////////
+{
+  /////////////////////////////////////////////////////////////////
+  namespace
+  {
+    // HACK for bnc#906096: let pool re-evaluate multiversion spec
+    // if target root changes. ZConfig returns data sensitive to
+    // current target root.
+    inline void sigMultiversionSpecChanged()
+    {
+      sat::detail::PoolMember::myPool().multiversionSpecChanged();
+    }
+  } //namespace
+  /////////////////////////////////////////////////////////////////
+
   ///////////////////////////////////////////////////////////////////
   namespace json
   {
@@ -156,152 +166,70 @@ namespace zypp
     }
   } // namespace json
   ///////////////////////////////////////////////////////////////////
+
   ///////////////////////////////////////////////////////////////////
   namespace target
-  { /////////////////////////////////////////////////////////////////
-
-    /** Helper for commit plugin execution.
-     * \ingroup g_RAII
-     */
-    class CommitPlugins : private base::NonCopyable
+  {
+    ///////////////////////////////////////////////////////////////////
+    namespace
     {
-      public:
-       /** Default ctor: Empty plugin list */
-       CommitPlugins()
-       {}
-
-       /** Dtor: Send PLUGINEND message and close plugins. */
-       ~CommitPlugins()
-       {
-         if ( ! _scripts.empty() )
-           send( PluginFrame( "PLUGINEND" ) );
-         // ~PluginScript will disconnect all remaining plugins!
-       }
-
-       /** Whether no plugins are waiting */
-       bool empty() const
-       { return _scripts.empty(); }
-
-
-       /** Send \ref PluginFrame to all open plugins.
-        * Failed plugins are removed from the execution list.
-        */
-       void send( const PluginFrame & frame_r )
-       {
-         DBG << "+++++++++++++++ send " << frame_r << endl;
-         for ( auto it = _scripts.begin(); it != _scripts.end(); )
-         {
-           doSend( *it, frame_r );
-           if ( it->isOpen() )
-             ++it;
-           else
-             it = _scripts.erase( it );
-         }
-         DBG << "--------------- send " << frame_r << endl;
-       }
-
-       /** Find and launch plugins sending PLUGINSTART message.
-        *
-        * If \a path_r is a directory all executable files whithin are
-        * expected to be plugins. Otherwise \a path_r must point to an
-        * executable plugin.
-        */
-       void load( const Pathname & path_r )
+      SolvIdentFile::Data getUserInstalledFromHistory( const Pathname & historyFile_r )
+      {
+       SolvIdentFile::Data onSystemByUserList;
+       // go and parse it: 'who' must constain an '@', then it was installed by user request.
+       // 2009-09-29 07:25:19|install|lirc-remotes|0.8.5-3.2|x86_64|root@opensuse|InstallationImage|a204211eb0...
+       std::ifstream infile( historyFile_r.c_str() );
+       for( iostr::EachLine in( infile ); in; in.next() )
        {
-         PathInfo pi( path_r );
-         DBG << "+++++++++++++++ load " << pi << endl;
-         if ( pi.isDir() )
-         {
-           std::list<Pathname> entries;
-           if ( filesystem::readdir( entries, pi.path(), false ) != 0 )
-           {
-             WAR << "Plugin dir is not readable: " << pi << endl;
-             return;
-           }
-           for_( it, entries.begin(), entries.end() )
-           {
-             PathInfo pii( *it );
-             if ( pii.isFile() && pii.userMayRX() )
-               doLoad( pii );
-           }
-         }
-         else if ( pi.isFile() )
-         {
-           if ( pi.userMayRX() )
-             doLoad( pi );
-           else
-             WAR << "Plugin file is not executable: " << pi << endl;
-         }
-         else
+         const char * ch( (*in).c_str() );
+         // start with year
+         if ( *ch < '1' || '9' < *ch )
+           continue;
+         const char * sep1 = ::strchr( ch, '|' );      // | after date
+         if ( !sep1 )
+           continue;
+         ++sep1;
+         // if logs an install or delete
+         bool installs = true;
+         if ( ::strncmp( sep1, "install|", 8 ) )
          {
-           WAR << "Plugin path is neither dir nor file: " << pi << endl;
-         }
-         DBG << "--------------- load " << pi << endl;
-       }
-
-      private:
-       /** Send \ref PluginFrame and expect valid answer (ACK|_ENOMETHOD).
-        * Upon invalid answer or error, close the plugin. and remove it from the
-        * execution list.
-        * \returns the received \ref PluginFrame (empty Frame upon Exception)
-        */
-       PluginFrame doSend( PluginScript & script_r, const PluginFrame & frame_r )
-       {
-         PluginFrame ret;
-
-         try {
-           script_r.send( frame_r );
-           ret = script_r.receive();
+           if ( ::strncmp( sep1, "remove |", 8 ) )
+             continue; // no install and no remove
+             else
+               installs = false; // remove
          }
-         catch( const zypp::Exception & e )
-         { ZYPP_CAUGHT(e); }
-
-         if ( ! ( ret.isAckCommand() || ret.isEnomethodCommand() ) )
+         sep1 += 8;                                    // | after what
+         // get the package name
+         const char * sep2 = ::strchr( sep1, '|' );    // | after name
+         if ( !sep2 || sep1 == sep2 )
+           continue;
+         (*in)[sep2-ch] = '\0';
+         IdString pkg( sep1 );
+         // we're done, if a delete
+         if ( !installs )
          {
-           WAR << "Bad plugin response from " << script_r << endl;
-           WAR << dump(ret) << endl;
-           script_r.close();
-         }
-
-         return ret;
-       }
-
-       /** Launch a plugin sending PLUGINSTART message. */
-       void doLoad( const PathInfo & pi_r )
-       {
-         MIL << "Load plugin: " << pi_r << endl;
-         try {
-           PluginScript plugin( pi_r.path() );
-           plugin.open();
-
-           PluginFrame frame( "PLUGINBEGIN" );
-           if ( ZConfig::instance().hasUserData() )
-             frame.setHeader( "userdata", ZConfig::instance().userData() );
-
-           doSend( plugin, frame );    // closes on error
-           if ( plugin.isOpen() )
-             _scripts.push_back( plugin );
+           onSystemByUserList.erase( pkg );
+           continue;
          }
-         catch( const zypp::Exception & e )
+         // now guess whether user installed or not (3rd next field contains 'user@host')
+         if ( (sep1 = ::strchr( sep2+1, '|' ))         // | after version
+           && (sep1 = ::strchr( sep1+1, '|' ))         // | after arch
+           && (sep2 = ::strchr( sep1+1, '|' )) )       // | after who
          {
-            WAR << "Failed to load plugin " << pi_r << endl;
+           (*in)[sep2-ch] = '\0';
+           if ( ::strchr( sep1+1, '@' ) )
+           {
+             // by user
+             onSystemByUserList.insert( pkg );
+             continue;
+           }
          }
        }
-
-      private:
-       std::list<PluginScript> _scripts;
-    };
-
-    void testCommitPlugins( const Pathname & path_r ) // for testing only
-    {
-      USR << "+++++" << endl;
-      {
-       CommitPlugins pl;
-       pl.load( path_r );
-       USR << "=====" << endl;
+       MIL << "onSystemByUserList found: " << onSystemByUserList.size() << endl;
+       return onSystemByUserList;
       }
-      USR << "-----" << endl;
-    }
+    } // namespace
+    ///////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
     namespace
@@ -743,73 +671,10 @@ namespace zypp
                              ZYppCommitResult & result_r )
     { RunUpdateMessages( root_r, messagesPath_r, checkPackages_r, result_r ); }
 
-    /** Helper for PackageProvider queries during commit. */
-    struct QueryInstalledEditionHelper
-    {
-      bool operator()( const std::string & name_r,
-                       const Edition &     ed_r,
-                       const Arch &        arch_r ) const
-      {
-        rpm::librpmDb::db_const_iterator it;
-        for ( it.findByName( name_r ); *it; ++it )
-          {
-            if ( arch_r == it->tag_arch()
-                 && ( ed_r == Edition::noedition || ed_r == it->tag_edition() ) )
-              {
-                return true;
-              }
-          }
-        return false;
-      }
-    };
-
-    /**
-     * \short Let the Source provide the package.
-     * \p pool_r \ref ResPool used to get candidates
-     * \p pi item to be commited
-    */
-    struct RepoProvidePackage
-    {
-      repo::RepoMediaAccess &_access;
-      std::list<Repository> _repos;
-      repo::PackageProviderPolicy _packageProviderPolicy;
-
-      RepoProvidePackage( repo::RepoMediaAccess &access, ResPool pool_r )
-      : _access(access), _repos( pool_r.knownRepositoriesBegin(), pool_r.knownRepositoriesEnd() )
-      {
-       _packageProviderPolicy.queryInstalledCB( QueryInstalledEditionHelper() );
-      }
-
-      ManagedFile operator()( const PoolItem & pi, bool fromCache_r )
-      {
-        Package::constPtr p = asKind<Package>(pi.resolvable());
-       if ( fromCache_r )
-       {
-         repo::PackageProvider pkgProvider( _access, p, repo::DeltaCandidates(), _packageProviderPolicy );
-         return pkgProvider.providePackageFromCache();
-       }
-       else
-       {
-         repo::DeltaCandidates deltas( _repos, p->name() );
-         repo::PackageProvider pkgProvider( _access, p, deltas, _packageProviderPolicy );
-         return pkgProvider.providePackage();
-       }
-      }
-    };
     ///////////////////////////////////////////////////////////////////
 
     IMPL_PTR_TYPE(TargetImpl);
 
-    TargetImpl_Ptr TargetImpl::_nullimpl;
-
-    /** Null implementation */
-    TargetImpl_Ptr TargetImpl::nullimpl()
-    {
-      if (_nullimpl == 0)
-        _nullimpl = new TargetImpl;
-      return _nullimpl;
-    }
-
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : TargetImpl::TargetImpl
@@ -818,7 +683,7 @@ namespace zypp
     TargetImpl::TargetImpl( const Pathname & root_r, bool doRebuild_r )
     : _root( root_r )
     , _requestedLocalesFile( home() / "RequestedLocales" )
-    , _softLocksFile( home() / "SoftLocks" )
+    , _autoInstalledFile( home() / "AutoInstalled" )
     , _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) )
     {
       _rpm.initDatabase( root_r, Pathname(), doRebuild_r );
@@ -826,7 +691,7 @@ namespace zypp
       HistoryLog::setRoot(_root);
 
       createAnonymousId();
-
+      sigMultiversionSpecChanged();    // HACK: see sigMultiversionSpecChanged
       MIL << "Initialized target on " << _root << endl;
     }
 
@@ -886,9 +751,11 @@ namespace zypp
 
     void TargetImpl::createAnonymousId() const
     {
+      // bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
+      if ( root() != "/" )
+       return;
 
-      // create the anonymous unique id
-      // this value is used for statistics
+      // Create the anonymous unique id, used for download statistics
       Pathname idpath( home() / "AnonymousUniqueId");
 
       try
@@ -943,6 +810,7 @@ namespace zypp
     TargetImpl::~TargetImpl()
     {
       _rpm.closeDatabase();
+      sigMultiversionSpecChanged();    // HACK: see sigMultiversionSpecChanged
       MIL << "Targets closed" << endl;
     }
 
@@ -972,8 +840,7 @@ namespace zypp
       bool build_rpm_solv = true;
       // lets see if the rpm solv cache exists
 
-      RepoStatus rpmstatus( RepoStatus( _root/"/var/lib/rpm/Name" )
-                            && (_root/"/etc/products.d") );
+      RepoStatus rpmstatus( RepoStatus(_root/"var/lib/rpm/Name") && RepoStatus(_root/"etc/products.d") );
 
       bool solvexisted = PathInfo(rpmsolv).isExist();
       if ( solvexisted )
@@ -985,10 +852,10 @@ namespace zypp
         {
           RepoStatus status = RepoStatus::fromCookieFile(rpmsolvcookie);
           // now compare it with the rpm database
-          if ( status.checksum() == rpmstatus.checksum() )
-            build_rpm_solv = false;
-          MIL << "Read cookie: " << rpmsolvcookie << " says: "
-              << (build_rpm_solv ? "outdated" : "uptodate") << endl;
+          if ( status == rpmstatus )
+           build_rpm_solv = false;
+         MIL << "Read cookie: " << rpmsolvcookie << " says: "
+         << (build_rpm_solv ? "outdated" : "uptodate") << endl;
         }
       }
 
@@ -1040,32 +907,40 @@ namespace zypp
         // Take care we unlink the solvfile on exception
         ManagedFile guard( base, filesystem::recursive_rmdir );
 
-        std::ostringstream cmd;
-        cmd << "rpmdb2solv";
-        if ( ! _root.empty() )
-          cmd << " -r '" << _root << "'";
-       cmd << " -X";   // autogenerate pattern from pattern-package
-        cmd << " -p '" << Pathname::assertprefix( _root, "/etc/products.d" ) << "'";
+        ExternalProgram::Arguments cmd;
+        cmd.push_back( "rpmdb2solv" );
+        if ( ! _root.empty() ) {
+          cmd.push_back( "-r" );
+          cmd.push_back( _root.asString() );
+        }
+        cmd.push_back( "-X" ); // autogenerate pattern/product/... from -package
+        cmd.push_back( "-A" ); // autogenerate application pseudo packages
+        cmd.push_back( "-p" );
+        cmd.push_back( Pathname::assertprefix( _root, "/etc/products.d" ).asString() );
 
         if ( ! oldSolvFile.empty() )
-          cmd << " '" << oldSolvFile << "'";
+          cmd.push_back( oldSolvFile.asString() );
 
-        cmd << "  > '" << tmpsolv.path() << "'";
+        cmd.push_back( "-o" );
+        cmd.push_back( tmpsolv.path().asString() );
 
-        MIL << "Executing: " << cmd << endl;
-        ExternalProgram prog( cmd.str(), ExternalProgram::Stderr_To_Stdout );
+        ExternalProgram prog( cmd, ExternalProgram::Stderr_To_Stdout );
+       std::string errdetail;
 
-        cmd << endl;
         for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
           WAR << "  " << output;
-          cmd << "     " << output;
+          if ( errdetail.empty() ) {
+            errdetail = prog.command();
+            errdetail += '\n';
+          }
+          errdetail += output;
         }
 
         int ret = prog.close();
         if ( ret != 0 )
         {
           Exception ex(str::form("Failed to cache rpm database (%d).", ret));
-          ex.remember( cmd.str() );
+          ex.remember( errdetail );
           ZYPP_THROW(ex);
         }
 
@@ -1079,30 +954,23 @@ namespace zypp
 
         // We keep it.
         guard.resetDispose();
+       sat::updateSolvFileIndex( rpmsolv );    // content digest for zypper bash completion
 
-       // Finally send notification to plugins
-       // NOTE: quick hack looking for spacewalk plugin only
+       // system-hook: Finally send notification to plugins
+       if ( root() == "/" )
        {
-         Pathname script( Pathname::assertprefix( _root, ZConfig::instance().pluginsPath()/"system/spacewalk" ) );
-         if ( PathInfo( script ).isX() )
-           try {
-             PluginScript spacewalk( script );
-             spacewalk.open();
-
-             PluginFrame notify( "PACKAGESETCHANGED" );
-             spacewalk.send( notify );
-
-             PluginFrame ret( spacewalk.receive() );
-             MIL << ret << endl;
-             if ( ret.command() == "ERROR" )
-               ret.writeTo( WAR ) << endl;
-           }
-           catch ( const Exception & excpt )
-           {
-             WAR << excpt.asUserHistory() << endl;
-           }
+         PluginExecutor plugins;
+         plugins.load( ZConfig::instance().pluginsPath()/"system" );
+         if ( plugins )
+           plugins.send( PluginFrame( "PACKAGESETCHANGED" ) );
        }
       }
+      else
+      {
+       // On the fly add missing solv.idx files for bash completion.
+       if ( ! PathInfo(base/"solv.idx").isExist() )
+         sat::updateSolvFileIndex( rpmsolv );
+      }
       return build_rpm_solv;
     }
 
@@ -1163,6 +1031,7 @@ namespace zypp
 
         system.addSolv( rpmsolv );
       }
+      satpool.rootDir( _root );
 
       // (Re)Load the requested locales et al.
       // If the requested locales are empty, we leave the pool untouched
@@ -1173,20 +1042,34 @@ namespace zypp
         const LocaleSet & requestedLocales( _requestedLocalesFile.locales() );
         if ( ! requestedLocales.empty() )
         {
-          satpool.setRequestedLocales( requestedLocales );
+          satpool.initRequestedLocales( requestedLocales );
         }
       }
       {
-        SoftLocksFile::Data softLocks( _softLocksFile.data() );
-        if ( ! softLocks.empty() )
-        {
-          // Don't soft lock any installed item.
-          for_( it, system.solvablesBegin(), system.solvablesEnd() )
-          {
-            softLocks.erase( it->ident() );
-          }
-          ResPool::instance().setAutoSoftLocks( softLocks );
-        }
+       if ( ! PathInfo( _autoInstalledFile.file() ).isExist() )
+       {
+         // Initialize from history, if it does not exist
+         Pathname historyFile( Pathname::assertprefix( _root, ZConfig::instance().historyLogFile() ) );
+         if ( PathInfo( historyFile ).isExist() )
+         {
+           SolvIdentFile::Data onSystemByUser( getUserInstalledFromHistory( historyFile ) );
+           SolvIdentFile::Data onSystemByAuto;
+           for_( it, system.solvablesBegin(), system.solvablesEnd() )
+           {
+             IdString ident( (*it).ident() );
+             if ( onSystemByUser.find( ident ) == onSystemByUser.end() )
+               onSystemByAuto.insert( ident );
+           }
+           _autoInstalledFile.setData( onSystemByAuto );
+         }
+         // on the fly removed any obsolete SoftLocks file
+         filesystem::unlink( home() / "SoftLocks" );
+       }
+       // read from AutoInstalled file
+       sat::StringQueue q;
+       for ( const auto & idstr : _autoInstalledFile.data() )
+         q.push( idstr.id() );
+       satpool.setAutoInstalled( q );
       }
       if ( ZConfig::instance().apply_locks_file() )
       {
@@ -1260,19 +1143,18 @@ namespace zypp
       ///////////////////////////////////////////////////////////////////
       // Prepare execution of commit plugins:
       ///////////////////////////////////////////////////////////////////
-      CommitPlugins commitPlugins;
+      PluginExecutor commitPlugins;
       if ( root() == "/" && ! policy_r.dryRun() )
       {
-       Pathname plugindir( Pathname::assertprefix( _root, ZConfig::instance().pluginsPath()/"commit" ) );
-       commitPlugins.load( plugindir );
+       commitPlugins.load( ZConfig::instance().pluginsPath()/"commit" );
       }
-      if ( ! commitPlugins.empty() )
+      if ( commitPlugins )
        commitPlugins.send( transactionPluginFrame( "COMMITBEGIN", steps ) );
 
       ///////////////////////////////////////////////////////////////////
       // Write out a testcase if we're in dist upgrade mode.
       ///////////////////////////////////////////////////////////////////
-      if ( getZYpp()->resolver()->upgradeMode() )
+      if ( pool_r.resolver().upgradeMode() || pool_r.resolver().upgradingRepos() )
       {
         if ( ! policy_r.dryRun() )
         {
@@ -1292,11 +1174,12 @@ namespace zypp
         filesystem::assert_dir( home() );
         // requested locales
         _requestedLocalesFile.setLocales( pool_r.getRequestedLocales() );
-        // weak locks
+       // autoinstalled
         {
-          SoftLocksFile::Data newdata;
-          pool_r.getActiveSoftLocks( newdata );
-          _softLocksFile.setData( newdata );
+         SolvIdentFile::Data newdata;
+         for ( sat::Queue::value_type id : result.rTransaction().autoInstalled() )
+           newdata.insert( IdString(id) );
+         _autoInstalledFile.setData( newdata );
         }
         // hard locks
         if ( ZConfig::instance().apply_locks_file() )
@@ -1351,9 +1234,7 @@ namespace zypp
       if ( ! policy_r.dryRun() || policy_r.downloadMode() == DownloadOnly )
       {
        // Prepare the package cache. Pass all items requiring download.
-        repo::RepoMediaAccess access;
-        RepoProvidePackage repoProvidePackage( access, pool_r );
-        CommitPackageCache packageCache( root(), repoProvidePackage );
+        CommitPackageCache packageCache;
        packageCache.setCommitList( steps.begin(), steps.end() );
 
         bool miss = false;
@@ -1383,22 +1264,7 @@ namespace zypp
               ManagedFile localfile;
               try
               {
-               // TODO: unify packageCache.get for Package and SrcPackage
-               if ( pi->isKind<Package>() )
-               {
-                 localfile = packageCache.get( pi );
-               }
-               else if ( pi->isKind<SrcPackage>() )
-               {
-                 repo::RepoMediaAccess access;
-                 repo::SrcPackageProvider prov( access );
-                 localfile = prov.provideSrcPackage( pi->asKind<SrcPackage>() );
-               }
-               else
-               {
-                 INT << "Don't know howto cache: Neither Package nor SrcPackage: " << pi << endl;
-                 continue;
-               }
+               localfile = packageCache.get( pi );
                 localfile.resetDispose(); // keep the package file in the cache
               }
               catch ( const AbortRequestException & exp )
@@ -1429,6 +1295,7 @@ namespace zypp
               }
             }
           }
+          packageCache.preloaded( true ); // try to avoid duplicate infoInCache CBs in commit
         }
 
         if ( miss )
@@ -1437,16 +1304,15 @@ namespace zypp
         }
         else
        {
-         // if cache is preloaded, check for file conflicts
-         commitFindFileConflicts( policy_r, result );
-
          if ( ! policy_r.dryRun() )
          {
+           // if cache is preloaded, check for file conflicts
+           commitFindFileConflicts( policy_r, result );
            commit( policy_r, packageCache, result );
          }
          else
          {
-           DBG << "dryRun: Not installing/deleting anything." << endl;
+           DBG << "dryRun/downloadOnly: Not installing/deleting anything." << endl;
          }
        }
       }
@@ -1458,7 +1324,7 @@ namespace zypp
       ///////////////////////////////////////////////////////////////////
       // Send result to commit plugins:
       ///////////////////////////////////////////////////////////////////
-      if ( ! commitPlugins.empty() )
+      if ( commitPlugins )
        commitPlugins.send( transactionPluginFrame( "COMMITEND", steps ) );
 
       ///////////////////////////////////////////////////////////////////
@@ -1478,6 +1344,20 @@ namespace zypp
     // COMMIT internal
     //
     ///////////////////////////////////////////////////////////////////
+    namespace
+    {
+      struct NotifyAttemptToModify
+      {
+       NotifyAttemptToModify( ZYppCommitResult & result_r ) : _result( result_r ) {}
+
+       void operator()()
+       { if ( _guard ) { _result.attemptToModify( true ); _guard = false; } }
+
+       TrueBool           _guard;
+       ZYppCommitResult & _result;
+      };
+    } // namespace
+
     void TargetImpl::commit( const ZYppCommitPolicy & policy_r,
                             CommitPackageCache & packageCache_r,
                             ZYppCommitResult & result_r )
@@ -1486,7 +1366,14 @@ namespace zypp
       ZYppCommitResult::TransactionStepList & steps( result_r.rTransactionStepList() );
       MIL << "TargetImpl::commit(<list>" << policy_r << ")" << steps.size() << endl;
 
+      HistoryLog().stampCommand();
+
+      // Send notification once upon 1st call to rpm
+      NotifyAttemptToModify attemptToModify( result_r );
+
       bool abort = false;
+
+      RpmPostTransCollector postTransCollector( _root );
       std::vector<sat::Solvable> successfullyInstalledPackages;
       TargetImpl::PoolItemList remaining;
 
@@ -1560,9 +1447,12 @@ namespace zypp
             if (policy_r.rpmExcludeDocs()) flags |= rpm::RPMINST_EXCLUDEDOCS;
             if (policy_r.rpmNoSignature()) flags |= rpm::RPMINST_NOSIGNATURE;
 
+           attemptToModify();
             try
             {
               progress.tryLevel( target::rpm::InstallResolvableReport::RPM_NODEPS_FORCE );
+             if ( postTransCollector.collectScriptFromPackage( localfile ) )
+               flags |= rpm::RPMINST_NOPOSTTRANS;
              rpm().installPackage( localfile, flags );
               HistoryLog().install(citem);
 
@@ -1621,6 +1511,8 @@ namespace zypp
             rpm::RpmInstFlags flags( policy_r.rpmInstFlags() & rpm::RPMINST_JUSTDB );
             flags |= rpm::RPMINST_NODEPS;
             if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
+
+           attemptToModify();
             try
             {
              rpm().removePackage( p, flags );
@@ -1707,6 +1599,12 @@ namespace zypp
 
       } // for
 
+      // process all remembered posttrans scripts.
+      if ( !abort )
+       postTransCollector.executeScripts();
+      else
+       postTransCollector.discardScripts();
+
       // Check presence of update scripts/messages. If aborting,
       // at least log omitted scripts.
       if ( ! successfullyInstalledPackages.empty() )
@@ -1753,19 +1651,25 @@ namespace zypp
     {
       parser::ProductFileData baseproductdata( const Pathname & root_r )
       {
+       parser::ProductFileData ret;
         PathInfo baseproduct( Pathname::assertprefix( root_r, "/etc/products.d/baseproduct" ) );
+
         if ( baseproduct.isFile() )
         {
           try
           {
-            return parser::ProductFileReader::scanFile( baseproduct.path() );
+            ret = parser::ProductFileReader::scanFile( baseproduct.path() );
           }
           catch ( const Exception & excpt )
           {
             ZYPP_CAUGHT( excpt );
           }
         }
-        return parser::ProductFileData();
+       else if ( PathInfo( Pathname::assertprefix( root_r, "/etc/products.d" ) ).isDir() )
+       {
+         ERR << "baseproduct symlink is dangling or missing: " << baseproduct << endl;
+       }
+        return ret;
       }
 
       inline Pathname staticGuessRoot( const Pathname & root_r )
@@ -1792,7 +1696,7 @@ namespace zypp
         }
         return std::string();
       }
-    } // namescpace
+    } // namespace
     ///////////////////////////////////////////////////////////////////
 
     Product::constPtr TargetImpl::baseProduct() const
@@ -1816,6 +1720,15 @@ namespace zypp
       return RequestedLocalesFile( home(needroot) / "RequestedLocales" ).locales();
     }
 
+    void TargetImpl::updateAutoInstalled()
+    {
+      MIL << "updateAutoInstalled if changed..." << endl;
+      SolvIdentFile::Data newdata;
+      for ( auto id : sat::Pool::instance().autoInstalled() )
+       newdata.insert( IdString(id) ); // explicit ctor!
+      _autoInstalledFile.setData( std::move(newdata) );
+    }
+
     std::string TargetImpl::targetDistribution() const
     { return baseproductdata( _root ).registerTarget(); }
     // static version:
@@ -1828,6 +1741,12 @@ namespace zypp
     std::string TargetImpl::targetDistributionRelease( const Pathname & root_r )
     { return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
 
+    std::string TargetImpl::targetDistributionFlavor() const
+    { return baseproductdata( _root ).registerFlavor(); }
+    // static version:
+    std::string TargetImpl::targetDistributionFlavor( const Pathname & root_r )
+    { return baseproductdata( staticGuessRoot(root_r) ).registerFlavor();}
+
     Target::DistributionLabel TargetImpl::distributionLabel() const
     {
       Target::DistributionLabel ret;
@@ -1898,15 +1817,29 @@ namespace zypp
     }
 
     ///////////////////////////////////////////////////////////////////
+    namespace
+    {
+      std::string guessAnonymousUniqueId( const Pathname & root_r )
+      {
+       // bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
+       std::string ret( firstNonEmptyLineIn( root_r / "/var/lib/zypp/AnonymousUniqueId" ) );
+       if ( ret.empty() && root_r != "/" )
+       {
+         // if it has nonoe, use the outer systems one
+         ret = firstNonEmptyLineIn( "/var/lib/zypp/AnonymousUniqueId" );
+       }
+       return ret;
+      }
+    }
 
     std::string TargetImpl::anonymousUniqueId() const
     {
-      return firstNonEmptyLineIn( home() / "AnonymousUniqueId" );
+      return guessAnonymousUniqueId( root() );
     }
     // static version:
     std::string TargetImpl::anonymousUniqueId( const Pathname & root_r )
     {
-      return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/AnonymousUniqueId" );
+      return guessAnonymousUniqueId( staticGuessRoot(root_r) );
     }
 
     ///////////////////////////////////////////////////////////////////
@@ -1915,6 +1848,9 @@ namespace zypp
     {
       // provide on local disk
       ManagedFile localfile = provideSrcPackage(srcPackage_r);
+      // create a installation progress report proxy
+      RpmInstallPackageReceiver progress( srcPackage_r );
+      progress.connect(); // disconnected on destruction.
       // install it
       rpm().installPackage ( localfile );
     }