libzypp  17.7.2
TargetImpl.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <fstream>
14 #include <sstream>
15 #include <string>
16 #include <list>
17 #include <set>
18 
19 #include <sys/types.h>
20 #include <dirent.h>
21 
22 #include "zypp/base/LogTools.h"
23 #include "zypp/base/Exception.h"
24 #include "zypp/base/Iterator.h"
25 #include "zypp/base/Gettext.h"
26 #include "zypp/base/IOStream.h"
27 #include "zypp/base/Functional.h"
29 #include "zypp/base/Json.h"
30 
31 #include "zypp/ZConfig.h"
32 #include "zypp/ZYppFactory.h"
33 
34 #include "zypp/PoolItem.h"
35 #include "zypp/ResObjects.h"
36 #include "zypp/Url.h"
37 #include "zypp/TmpPath.h"
38 #include "zypp/RepoStatus.h"
39 #include "zypp/ExternalProgram.h"
40 #include "zypp/Repository.h"
41 #include "zypp/ShutdownLock_p.h"
42 
43 #include "zypp/ResFilters.h"
44 #include "zypp/HistoryLog.h"
45 #include "zypp/target/TargetImpl.h"
50 
53 
54 #include "zypp/sat/Pool.h"
56 #include "zypp/sat/Transaction.h"
57 
58 #include "zypp/PluginExecutor.h"
59 
60 using namespace std;
61 
63 namespace zypp
64 {
66  namespace
67  {
68  // HACK for bnc#906096: let pool re-evaluate multiversion spec
69  // if target root changes. ZConfig returns data sensitive to
70  // current target root.
71  inline void sigMultiversionSpecChanged()
72  {
73  sat::detail::PoolMember::myPool().multiversionSpecChanged();
74  }
75  } //namespace
77 
79  namespace json
80  {
81  // Lazy via template specialisation / should switch to overloading
82 
83  template<>
84  inline std::string toJSON( const ZYppCommitResult::TransactionStepList & steps_r )
85  {
86  using sat::Transaction;
87  json::Array ret;
88 
89  for ( const Transaction::Step & step : steps_r )
90  // ignore implicit deletes due to obsoletes and non-package actions
91  if ( step.stepType() != Transaction::TRANSACTION_IGNORE )
92  ret.add( step );
93 
94  return ret.asJSON();
95  }
96 
98  template<>
99  inline std::string toJSON( const sat::Transaction::Step & step_r )
100  {
101  static const std::string strType( "type" );
102  static const std::string strStage( "stage" );
103  static const std::string strSolvable( "solvable" );
104 
105  static const std::string strTypeDel( "-" );
106  static const std::string strTypeIns( "+" );
107  static const std::string strTypeMul( "M" );
108 
109  static const std::string strStageDone( "ok" );
110  static const std::string strStageFailed( "err" );
111 
112  static const std::string strSolvableN( "n" );
113  static const std::string strSolvableE( "e" );
114  static const std::string strSolvableV( "v" );
115  static const std::string strSolvableR( "r" );
116  static const std::string strSolvableA( "a" );
117 
118  using sat::Transaction;
119  json::Object ret;
120 
121  switch ( step_r.stepType() )
122  {
123  case Transaction::TRANSACTION_IGNORE: /*empty*/ break;
124  case Transaction::TRANSACTION_ERASE: ret.add( strType, strTypeDel ); break;
125  case Transaction::TRANSACTION_INSTALL: ret.add( strType, strTypeIns ); break;
126  case Transaction::TRANSACTION_MULTIINSTALL: ret.add( strType, strTypeMul ); break;
127  }
128 
129  switch ( step_r.stepStage() )
130  {
131  case Transaction::STEP_TODO: /*empty*/ break;
132  case Transaction::STEP_DONE: ret.add( strStage, strStageDone ); break;
133  case Transaction::STEP_ERROR: ret.add( strStage, strStageFailed ); break;
134  }
135 
136  {
137  IdString ident;
138  Edition ed;
139  Arch arch;
140  if ( sat::Solvable solv = step_r.satSolvable() )
141  {
142  ident = solv.ident();
143  ed = solv.edition();
144  arch = solv.arch();
145  }
146  else
147  {
148  // deleted package; post mortem data stored in Transaction::Step
149  ident = step_r.ident();
150  ed = step_r.edition();
151  arch = step_r.arch();
152  }
153 
154  json::Object s {
155  { strSolvableN, ident.asString() },
156  { strSolvableV, ed.version() },
157  { strSolvableR, ed.release() },
158  { strSolvableA, arch.asString() }
159  };
160  if ( Edition::epoch_t epoch = ed.epoch() )
161  s.add( strSolvableE, epoch );
162 
163  ret.add( strSolvable, s );
164  }
165 
166  return ret.asJSON();
167  }
168  } // namespace json
170 
172  namespace target
173  {
175  namespace
176  {
177  SolvIdentFile::Data getUserInstalledFromHistory( const Pathname & historyFile_r )
178  {
179  SolvIdentFile::Data onSystemByUserList;
180  // go and parse it: 'who' must constain an '@', then it was installed by user request.
181  // 2009-09-29 07:25:19|install|lirc-remotes|0.8.5-3.2|x86_64|root@opensuse|InstallationImage|a204211eb0...
182  std::ifstream infile( historyFile_r.c_str() );
183  for( iostr::EachLine in( infile ); in; in.next() )
184  {
185  const char * ch( (*in).c_str() );
186  // start with year
187  if ( *ch < '1' || '9' < *ch )
188  continue;
189  const char * sep1 = ::strchr( ch, '|' ); // | after date
190  if ( !sep1 )
191  continue;
192  ++sep1;
193  // if logs an install or delete
194  bool installs = true;
195  if ( ::strncmp( sep1, "install|", 8 ) )
196  {
197  if ( ::strncmp( sep1, "remove |", 8 ) )
198  continue; // no install and no remove
199  else
200  installs = false; // remove
201  }
202  sep1 += 8; // | after what
203  // get the package name
204  const char * sep2 = ::strchr( sep1, '|' ); // | after name
205  if ( !sep2 || sep1 == sep2 )
206  continue;
207  (*in)[sep2-ch] = '\0';
208  IdString pkg( sep1 );
209  // we're done, if a delete
210  if ( !installs )
211  {
212  onSystemByUserList.erase( pkg );
213  continue;
214  }
215  // now guess whether user installed or not (3rd next field contains 'user@host')
216  if ( (sep1 = ::strchr( sep2+1, '|' )) // | after version
217  && (sep1 = ::strchr( sep1+1, '|' )) // | after arch
218  && (sep2 = ::strchr( sep1+1, '|' )) ) // | after who
219  {
220  (*in)[sep2-ch] = '\0';
221  if ( ::strchr( sep1+1, '@' ) )
222  {
223  // by user
224  onSystemByUserList.insert( pkg );
225  continue;
226  }
227  }
228  }
229  MIL << "onSystemByUserList found: " << onSystemByUserList.size() << endl;
230  return onSystemByUserList;
231  }
232  } // namespace
234 
236  namespace
237  {
238  inline PluginFrame transactionPluginFrame( const std::string & command_r, ZYppCommitResult::TransactionStepList & steps_r )
239  {
240  return PluginFrame( command_r, json::Object {
241  { "TransactionStepList", steps_r }
242  }.asJSON() );
243  }
244  } // namespace
246 
249  {
250  unsigned toKeep( ZConfig::instance().solver_upgradeTestcasesToKeep() );
251  MIL << "Testcases to keep: " << toKeep << endl;
252  if ( !toKeep )
253  return;
254  Target_Ptr target( getZYpp()->getTarget() );
255  if ( ! target )
256  {
257  WAR << "No Target no Testcase!" << endl;
258  return;
259  }
260 
261  std::string stem( "updateTestcase" );
262  Pathname dir( target->assertRootPrefix("/var/log/") );
263  Pathname next( dir / Date::now().form( stem+"-%Y-%m-%d-%H-%M-%S" ) );
264 
265  {
266  std::list<std::string> content;
267  filesystem::readdir( content, dir, /*dots*/false );
268  std::set<std::string> cases;
269  for_( c, content.begin(), content.end() )
270  {
271  if ( str::startsWith( *c, stem ) )
272  cases.insert( *c );
273  }
274  if ( cases.size() >= toKeep )
275  {
276  unsigned toDel = cases.size() - toKeep + 1; // +1 for the new one
277  for_( c, cases.begin(), cases.end() )
278  {
279  filesystem::recursive_rmdir( dir/(*c) );
280  if ( ! --toDel )
281  break;
282  }
283  }
284  }
285 
286  MIL << "Write new testcase " << next << endl;
287  getZYpp()->resolver()->createSolverTestcase( next.asString(), false/*no solving*/ );
288  }
289 
291  namespace
292  {
293 
304  std::pair<bool,PatchScriptReport::Action> doExecuteScript( const Pathname & root_r,
305  const Pathname & script_r,
307  {
308  MIL << "Execute script " << PathInfo(Pathname::assertprefix( root_r,script_r)) << endl;
309 
310  HistoryLog historylog;
311  historylog.comment(script_r.asString() + _(" executed"), /*timestamp*/true);
312  ExternalProgram prog( script_r.asString(), ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
313 
314  for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
315  {
316  historylog.comment(output);
317  if ( ! report_r->progress( PatchScriptReport::OUTPUT, output ) )
318  {
319  WAR << "User request to abort script " << script_r << endl;
320  prog.kill();
321  // the rest is handled by exit code evaluation
322  // in case the script has meanwhile finished.
323  }
324  }
325 
326  std::pair<bool,PatchScriptReport::Action> ret( std::make_pair( false, PatchScriptReport::ABORT ) );
327 
328  if ( prog.close() != 0 )
329  {
330  ret.second = report_r->problem( prog.execError() );
331  WAR << "ACTION" << ret.second << "(" << prog.execError() << ")" << endl;
332  std::ostringstream sstr;
333  sstr << script_r << _(" execution failed") << " (" << prog.execError() << ")" << endl;
334  historylog.comment(sstr.str(), /*timestamp*/true);
335  return ret;
336  }
337 
338  report_r->finish();
339  ret.first = true;
340  return ret;
341  }
342 
346  bool executeScript( const Pathname & root_r,
347  const Pathname & script_r,
348  callback::SendReport<PatchScriptReport> & report_r )
349  {
350  std::pair<bool,PatchScriptReport::Action> action( std::make_pair( false, PatchScriptReport::ABORT ) );
351 
352  do {
353  action = doExecuteScript( root_r, script_r, report_r );
354  if ( action.first )
355  return true; // success
356 
357  switch ( action.second )
358  {
359  case PatchScriptReport::ABORT:
360  WAR << "User request to abort at script " << script_r << endl;
361  return false; // requested abort.
362  break;
363 
364  case PatchScriptReport::IGNORE:
365  WAR << "User request to skip script " << script_r << endl;
366  return true; // requested skip.
367  break;
368 
369  case PatchScriptReport::RETRY:
370  break; // again
371  }
372  } while ( action.second == PatchScriptReport::RETRY );
373 
374  // THIS is not intended to be reached:
375  INT << "Abort on unknown ACTION request " << action.second << " returned" << endl;
376  return false; // abort.
377  }
378 
384  bool RunUpdateScripts( const Pathname & root_r,
385  const Pathname & scriptsPath_r,
386  const std::vector<sat::Solvable> & checkPackages_r,
387  bool aborting_r )
388  {
389  if ( checkPackages_r.empty() )
390  return true; // no installed packages to check
391 
392  MIL << "Looking for new update scripts in (" << root_r << ")" << scriptsPath_r << endl;
393  Pathname scriptsDir( Pathname::assertprefix( root_r, scriptsPath_r ) );
394  if ( ! PathInfo( scriptsDir ).isDir() )
395  return true; // no script dir
396 
397  std::list<std::string> scripts;
398  filesystem::readdir( scripts, scriptsDir, /*dots*/false );
399  if ( scripts.empty() )
400  return true; // no scripts in script dir
401 
402  // Now collect and execute all matching scripts.
403  // On ABORT: at least log all outstanding scripts.
404  // - "name-version-release"
405  // - "name-version-release-*"
406  bool abort = false;
407  std::map<std::string, Pathname> unify; // scripts <md5,path>
408  for_( it, checkPackages_r.begin(), checkPackages_r.end() )
409  {
410  std::string prefix( str::form( "%s-%s", it->name().c_str(), it->edition().c_str() ) );
411  for_( sit, scripts.begin(), scripts.end() )
412  {
413  if ( ! str::hasPrefix( *sit, prefix ) )
414  continue;
415 
416  if ( (*sit)[prefix.size()] != '\0' && (*sit)[prefix.size()] != '-' )
417  continue; // if not exact match it had to continue with '-'
418 
419  PathInfo script( scriptsDir / *sit );
420  Pathname localPath( scriptsPath_r/(*sit) ); // without root prefix
421  std::string unifytag; // must not stay empty
422 
423  if ( script.isFile() )
424  {
425  // Assert it's set executable, unify by md5sum.
426  filesystem::addmod( script.path(), 0500 );
427  unifytag = filesystem::md5sum( script.path() );
428  }
429  else if ( ! script.isExist() )
430  {
431  // Might be a dangling symlink, might be ok if we are in
432  // instsys (absolute symlink within the system below /mnt).
433  // readlink will tell....
434  unifytag = filesystem::readlink( script.path() ).asString();
435  }
436 
437  if ( unifytag.empty() )
438  continue;
439 
440  // Unify scripts
441  if ( unify[unifytag].empty() )
442  {
443  unify[unifytag] = localPath;
444  }
445  else
446  {
447  // translators: We may find the same script content in files with different names.
448  // Only the first occurence is executed, subsequent ones are skipped. It's a one-line
449  // message for a log file. Preferably start translation with "%s"
450  std::string msg( str::form(_("%s already executed as %s)"), localPath.asString().c_str(), unify[unifytag].c_str() ) );
451  MIL << "Skip update script: " << msg << endl;
452  HistoryLog().comment( msg, /*timestamp*/true );
453  continue;
454  }
455 
456  if ( abort || aborting_r )
457  {
458  WAR << "Aborting: Skip update script " << *sit << endl;
459  HistoryLog().comment(
460  localPath.asString() + _(" execution skipped while aborting"),
461  /*timestamp*/true);
462  }
463  else
464  {
465  MIL << "Found update script " << *sit << endl;
466  callback::SendReport<PatchScriptReport> report;
467  report->start( make<Package>( *it ), script.path() );
468 
469  if ( ! executeScript( root_r, localPath, report ) ) // script path without root prefix!
470  abort = true; // requested abort.
471  }
472  }
473  }
474  return !abort;
475  }
476 
478  //
480 
481  inline void copyTo( std::ostream & out_r, const Pathname & file_r )
482  {
483  std::ifstream infile( file_r.c_str() );
484  for( iostr::EachLine in( infile ); in; in.next() )
485  {
486  out_r << *in << endl;
487  }
488  }
489 
490  inline std::string notificationCmdSubst( const std::string & cmd_r, const UpdateNotificationFile & notification_r )
491  {
492  std::string ret( cmd_r );
493 #define SUBST_IF(PAT,VAL) if ( ret.find( PAT ) != std::string::npos ) ret = str::gsub( ret, PAT, VAL )
494  SUBST_IF( "%p", notification_r.solvable().asString() );
495  SUBST_IF( "%P", notification_r.file().asString() );
496 #undef SUBST_IF
497  return ret;
498  }
499 
500  void sendNotification( const Pathname & root_r,
501  const UpdateNotifications & notifications_r )
502  {
503  if ( notifications_r.empty() )
504  return;
505 
506  std::string cmdspec( ZConfig::instance().updateMessagesNotify() );
507  MIL << "Notification command is '" << cmdspec << "'" << endl;
508  if ( cmdspec.empty() )
509  return;
510 
511  std::string::size_type pos( cmdspec.find( '|' ) );
512  if ( pos == std::string::npos )
513  {
514  ERR << "Can't send Notification: Missing 'format |' in command spec." << endl;
515  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
516  return;
517  }
518 
519  std::string formatStr( str::toLower( str::trim( cmdspec.substr( 0, pos ) ) ) );
520  std::string commandStr( str::trim( cmdspec.substr( pos + 1 ) ) );
521 
522  enum Format { UNKNOWN, NONE, SINGLE, DIGEST, BULK };
523  Format format = UNKNOWN;
524  if ( formatStr == "none" )
525  format = NONE;
526  else if ( formatStr == "single" )
527  format = SINGLE;
528  else if ( formatStr == "digest" )
529  format = DIGEST;
530  else if ( formatStr == "bulk" )
531  format = BULK;
532  else
533  {
534  ERR << "Can't send Notification: Unknown format '" << formatStr << " |' in command spec." << endl;
535  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
536  return;
537  }
538 
539  // Take care: commands are ececuted chroot(root_r). The message file
540  // pathnames in notifications_r are local to root_r. For physical access
541  // to the file they need to be prefixed.
542 
543  if ( format == NONE || format == SINGLE )
544  {
545  for_( it, notifications_r.begin(), notifications_r.end() )
546  {
547  std::vector<std::string> command;
548  if ( format == SINGLE )
549  command.push_back( "<"+Pathname::assertprefix( root_r, it->file() ).asString() );
550  str::splitEscaped( notificationCmdSubst( commandStr, *it ), std::back_inserter( command ) );
551 
552  ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
553  if ( true ) // Wait for feedback
554  {
555  for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
556  {
557  DBG << line;
558  }
559  int ret = prog.close();
560  if ( ret != 0 )
561  {
562  ERR << "Notification command returned with error (" << ret << ")." << endl;
563  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
564  return;
565  }
566  }
567  }
568  }
569  else if ( format == DIGEST || format == BULK )
570  {
571  filesystem::TmpFile tmpfile;
572  ofstream out( tmpfile.path().c_str() );
573  for_( it, notifications_r.begin(), notifications_r.end() )
574  {
575  if ( format == DIGEST )
576  {
577  out << it->file() << endl;
578  }
579  else if ( format == BULK )
580  {
581  copyTo( out << '\f', Pathname::assertprefix( root_r, it->file() ) );
582  }
583  }
584 
585  std::vector<std::string> command;
586  command.push_back( "<"+tmpfile.path().asString() ); // redirect input
587  str::splitEscaped( notificationCmdSubst( commandStr, *notifications_r.begin() ), std::back_inserter( command ) );
588 
589  ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
590  if ( true ) // Wait for feedback otherwise the TmpFile goes out of scope.
591  {
592  for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
593  {
594  DBG << line;
595  }
596  int ret = prog.close();
597  if ( ret != 0 )
598  {
599  ERR << "Notification command returned with error (" << ret << ")." << endl;
600  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
601  return;
602  }
603  }
604  }
605  else
606  {
607  INT << "Can't send Notification: Missing handler for 'format |' in command spec." << endl;
608  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
609  return;
610  }
611  }
612 
613 
619  void RunUpdateMessages( const Pathname & root_r,
620  const Pathname & messagesPath_r,
621  const std::vector<sat::Solvable> & checkPackages_r,
622  ZYppCommitResult & result_r )
623  {
624  if ( checkPackages_r.empty() )
625  return; // no installed packages to check
626 
627  MIL << "Looking for new update messages in (" << root_r << ")" << messagesPath_r << endl;
628  Pathname messagesDir( Pathname::assertprefix( root_r, messagesPath_r ) );
629  if ( ! PathInfo( messagesDir ).isDir() )
630  return; // no messages dir
631 
632  std::list<std::string> messages;
633  filesystem::readdir( messages, messagesDir, /*dots*/false );
634  if ( messages.empty() )
635  return; // no messages in message dir
636 
637  // Now collect all matching messages in result and send them
638  // - "name-version-release"
639  // - "name-version-release-*"
640  HistoryLog historylog;
641  for_( it, checkPackages_r.begin(), checkPackages_r.end() )
642  {
643  std::string prefix( str::form( "%s-%s", it->name().c_str(), it->edition().c_str() ) );
644  for_( sit, messages.begin(), messages.end() )
645  {
646  if ( ! str::hasPrefix( *sit, prefix ) )
647  continue;
648 
649  if ( (*sit)[prefix.size()] != '\0' && (*sit)[prefix.size()] != '-' )
650  continue; // if not exact match it had to continue with '-'
651 
652  PathInfo message( messagesDir / *sit );
653  if ( ! message.isFile() || message.size() == 0 )
654  continue;
655 
656  MIL << "Found update message " << *sit << endl;
657  Pathname localPath( messagesPath_r/(*sit) ); // without root prefix
658  result_r.rUpdateMessages().push_back( UpdateNotificationFile( *it, localPath ) );
659  historylog.comment( str::Str() << _("New update message") << " " << localPath, /*timestamp*/true );
660  }
661  }
662  sendNotification( root_r, result_r.updateMessages() );
663  }
664 
666  } // namespace
668 
669  void XRunUpdateMessages( const Pathname & root_r,
670  const Pathname & messagesPath_r,
671  const std::vector<sat::Solvable> & checkPackages_r,
672  ZYppCommitResult & result_r )
673  { RunUpdateMessages( root_r, messagesPath_r, checkPackages_r, result_r ); }
674 
676 
677  IMPL_PTR_TYPE(TargetImpl);
678 
680  //
681  // METHOD NAME : TargetImpl::TargetImpl
682  // METHOD TYPE : Ctor
683  //
684  TargetImpl::TargetImpl( const Pathname & root_r, bool doRebuild_r )
685  : _root( root_r )
686  , _requestedLocalesFile( home() / "RequestedLocales" )
687  , _autoInstalledFile( home() / "AutoInstalled" )
688  , _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) )
689  {
690  _rpm.initDatabase( root_r, Pathname(), doRebuild_r );
691 
693 
695  sigMultiversionSpecChanged(); // HACK: see sigMultiversionSpecChanged
696  MIL << "Initialized target on " << _root << endl;
697  }
698 
702  static std::string generateRandomId()
703  {
704  std::ifstream uuidprovider( "/proc/sys/kernel/random/uuid" );
705  return iostr::getline( uuidprovider );
706  }
707 
713  void updateFileContent( const Pathname &filename,
714  boost::function<bool ()> condition,
715  boost::function<string ()> value )
716  {
717  string val = value();
718  // if the value is empty, then just dont
719  // do anything, regardless of the condition
720  if ( val.empty() )
721  return;
722 
723  if ( condition() )
724  {
725  MIL << "updating '" << filename << "' content." << endl;
726 
727  // if the file does not exist we need to generate the uuid file
728 
729  std::ofstream filestr;
730  // make sure the path exists
731  filesystem::assert_dir( filename.dirname() );
732  filestr.open( filename.c_str() );
733 
734  if ( filestr.good() )
735  {
736  filestr << val;
737  filestr.close();
738  }
739  else
740  {
741  // FIXME, should we ignore the error?
742  ZYPP_THROW(Exception("Can't openfile '" + filename.asString() + "' for writing"));
743  }
744  }
745  }
746 
748  static bool fileMissing( const Pathname &pathname )
749  {
750  return ! PathInfo(pathname).isExist();
751  }
752 
754  {
755  // bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
756  if ( root() != "/" )
757  return;
758 
759  // Create the anonymous unique id, used for download statistics
760  Pathname idpath( home() / "AnonymousUniqueId");
761 
762  try
763  {
764  updateFileContent( idpath,
765  boost::bind(fileMissing, idpath),
767  }
768  catch ( const Exception &e )
769  {
770  WAR << "Can't create anonymous id file" << endl;
771  }
772 
773  }
774 
776  {
777  // create the anonymous unique id
778  // this value is used for statistics
779  Pathname flavorpath( home() / "LastDistributionFlavor");
780 
781  // is there a product
783  if ( ! p )
784  {
785  WAR << "No base product, I won't create flavor cache" << endl;
786  return;
787  }
788 
789  string flavor = p->flavor();
790 
791  try
792  {
793 
794  updateFileContent( flavorpath,
795  // only if flavor is not empty
796  functor::Constant<bool>( ! flavor.empty() ),
797  functor::Constant<string>(flavor) );
798  }
799  catch ( const Exception &e )
800  {
801  WAR << "Can't create flavor cache" << endl;
802  return;
803  }
804  }
805 
807  //
808  // METHOD NAME : TargetImpl::~TargetImpl
809  // METHOD TYPE : Dtor
810  //
812  {
814  sigMultiversionSpecChanged(); // HACK: see sigMultiversionSpecChanged
815  MIL << "Targets closed" << endl;
816  }
817 
819  //
820  // solv file handling
821  //
823 
825  {
826  return Pathname::assertprefix( _root, ZConfig::instance().repoSolvfilesPath() / sat::Pool::instance().systemRepoAlias() );
827  }
828 
830  {
831  Pathname base = solvfilesPath();
833  }
834 
836  {
837  Pathname base = solvfilesPath();
838  Pathname rpmsolv = base/"solv";
839  Pathname rpmsolvcookie = base/"cookie";
840 
841  bool build_rpm_solv = true;
842  // lets see if the rpm solv cache exists
843 
844  RepoStatus rpmstatus( RepoStatus(_root/"var/lib/rpm/Name") && RepoStatus(_root/"etc/products.d") );
845 
846  bool solvexisted = PathInfo(rpmsolv).isExist();
847  if ( solvexisted )
848  {
849  // see the status of the cache
850  PathInfo cookie( rpmsolvcookie );
851  MIL << "Read cookie: " << cookie << endl;
852  if ( cookie.isExist() )
853  {
854  RepoStatus status = RepoStatus::fromCookieFile(rpmsolvcookie);
855  // now compare it with the rpm database
856  if ( status == rpmstatus )
857  build_rpm_solv = false;
858  MIL << "Read cookie: " << rpmsolvcookie << " says: "
859  << (build_rpm_solv ? "outdated" : "uptodate") << endl;
860  }
861  }
862 
863  if ( build_rpm_solv )
864  {
865  // if the solvfile dir does not exist yet, we better create it
866  filesystem::assert_dir( base );
867 
868  Pathname oldSolvFile( solvexisted ? rpmsolv : Pathname() ); // to speedup rpmdb2solv
869 
871  if ( !tmpsolv )
872  {
873  // Can't create temporary solv file, usually due to insufficient permission
874  // (user query while @System solv needs refresh). If so, try switching
875  // to a location within zypps temp. space (will be cleaned at application end).
876 
877  bool switchingToTmpSolvfile = false;
878  Exception ex("Failed to cache rpm database.");
879  ex.remember(str::form("Cannot create temporary file under %s.", base.c_str()));
880 
881  if ( ! solvfilesPathIsTemp() )
882  {
883  base = getZYpp()->tmpPath() / sat::Pool::instance().systemRepoAlias();
884  rpmsolv = base/"solv";
885  rpmsolvcookie = base/"cookie";
886 
887  filesystem::assert_dir( base );
888  tmpsolv = filesystem::TmpFile::makeSibling( rpmsolv );
889 
890  if ( tmpsolv )
891  {
892  WAR << "Using a temporary solv file at " << base << endl;
893  switchingToTmpSolvfile = true;
894  _tmpSolvfilesPath = base;
895  }
896  else
897  {
898  ex.remember(str::form("Cannot create temporary file under %s.", base.c_str()));
899  }
900  }
901 
902  if ( ! switchingToTmpSolvfile )
903  {
904  ZYPP_THROW(ex);
905  }
906  }
907 
908  // Take care we unlink the solvfile on exception
910 
912  cmd.push_back( "rpmdb2solv" );
913  if ( ! _root.empty() ) {
914  cmd.push_back( "-r" );
915  cmd.push_back( _root.asString() );
916  }
917  cmd.push_back( "-X" ); // autogenerate pattern/product/... from -package
918  // bsc#1104415: no more application support // cmd.push_back( "-A" ); // autogenerate application pseudo packages
919  cmd.push_back( "-p" );
920  cmd.push_back( Pathname::assertprefix( _root, "/etc/products.d" ).asString() );
921 
922  if ( ! oldSolvFile.empty() )
923  cmd.push_back( oldSolvFile.asString() );
924 
925  cmd.push_back( "-o" );
926  cmd.push_back( tmpsolv.path().asString() );
927 
929  std::string errdetail;
930 
931  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
932  WAR << " " << output;
933  if ( errdetail.empty() ) {
934  errdetail = prog.command();
935  errdetail += '\n';
936  }
937  errdetail += output;
938  }
939 
940  int ret = prog.close();
941  if ( ret != 0 )
942  {
943  Exception ex(str::form("Failed to cache rpm database (%d).", ret));
944  ex.remember( errdetail );
945  ZYPP_THROW(ex);
946  }
947 
948  ret = filesystem::rename( tmpsolv, rpmsolv );
949  if ( ret != 0 )
950  ZYPP_THROW(Exception("Failed to move cache to final destination"));
951  // if this fails, don't bother throwing exceptions
952  filesystem::chmod( rpmsolv, 0644 );
953 
954  rpmstatus.saveToCookieFile(rpmsolvcookie);
955 
956  // We keep it.
957  guard.resetDispose();
958  sat::updateSolvFileIndex( rpmsolv ); // content digest for zypper bash completion
959 
960  // system-hook: Finally send notification to plugins
961  if ( root() == "/" )
962  {
963  PluginExecutor plugins;
964  plugins.load( ZConfig::instance().pluginsPath()/"system" );
965  if ( plugins )
966  plugins.send( PluginFrame( "PACKAGESETCHANGED" ) );
967  }
968  }
969  else
970  {
971  // On the fly add missing solv.idx files for bash completion.
972  if ( ! PathInfo(base/"solv.idx").isExist() )
973  sat::updateSolvFileIndex( rpmsolv );
974  }
975  return build_rpm_solv;
976  }
977 
979  {
980  load( false );
981  }
982 
984  {
985  Repository system( sat::Pool::instance().findSystemRepo() );
986  if ( system )
987  system.eraseFromPool();
988  }
989 
990  void TargetImpl::load( bool force )
991  {
992  bool newCache = buildCache();
993  MIL << "New cache built: " << (newCache?"true":"false") <<
994  ", force loading: " << (force?"true":"false") << endl;
995 
996  // now add the repos to the pool
997  sat::Pool satpool( sat::Pool::instance() );
998  Pathname rpmsolv( solvfilesPath() / "solv" );
999  MIL << "adding " << rpmsolv << " to pool(" << satpool.systemRepoAlias() << ")" << endl;
1000 
1001  // Providing an empty system repo, unload any old content
1002  Repository system( sat::Pool::instance().findSystemRepo() );
1003 
1004  if ( system && ! system.solvablesEmpty() )
1005  {
1006  if ( newCache || force )
1007  {
1008  system.eraseFromPool(); // invalidates system
1009  }
1010  else
1011  {
1012  return; // nothing to do
1013  }
1014  }
1015 
1016  if ( ! system )
1017  {
1018  system = satpool.systemRepo();
1019  }
1020 
1021  try
1022  {
1023  MIL << "adding " << rpmsolv << " to system" << endl;
1024  system.addSolv( rpmsolv );
1025  }
1026  catch ( const Exception & exp )
1027  {
1028  ZYPP_CAUGHT( exp );
1029  MIL << "Try to handle exception by rebuilding the solv-file" << endl;
1030  clearCache();
1031  buildCache();
1032 
1033  system.addSolv( rpmsolv );
1034  }
1035  satpool.rootDir( _root );
1036 
1037  // (Re)Load the requested locales et al.
1038  // If the requested locales are empty, we leave the pool untouched
1039  // to avoid undoing changes the application applied. We expect this
1040  // to happen on a bare metal installation only. An already existing
1041  // target should be loaded before its settings are changed.
1042  {
1044  if ( ! requestedLocales.empty() )
1045  {
1047  }
1048  }
1049  {
1050  if ( ! PathInfo( _autoInstalledFile.file() ).isExist() )
1051  {
1052  // Initialize from history, if it does not exist
1053  Pathname historyFile( Pathname::assertprefix( _root, ZConfig::instance().historyLogFile() ) );
1054  if ( PathInfo( historyFile ).isExist() )
1055  {
1056  SolvIdentFile::Data onSystemByUser( getUserInstalledFromHistory( historyFile ) );
1057  SolvIdentFile::Data onSystemByAuto;
1058  for_( it, system.solvablesBegin(), system.solvablesEnd() )
1059  {
1060  IdString ident( (*it).ident() );
1061  if ( onSystemByUser.find( ident ) == onSystemByUser.end() )
1062  onSystemByAuto.insert( ident );
1063  }
1064  _autoInstalledFile.setData( onSystemByAuto );
1065  }
1066  // on the fly removed any obsolete SoftLocks file
1067  filesystem::unlink( home() / "SoftLocks" );
1068  }
1069  // read from AutoInstalled file
1070  sat::StringQueue q;
1071  for ( const auto & idstr : _autoInstalledFile.data() )
1072  q.push( idstr.id() );
1073  satpool.setAutoInstalled( q );
1074  }
1075  if ( ZConfig::instance().apply_locks_file() )
1076  {
1077  const HardLocksFile::Data & hardLocks( _hardLocksFile.data() );
1078  if ( ! hardLocks.empty() )
1079  {
1080  ResPool::instance().setHardLockQueries( hardLocks );
1081  }
1082  }
1083 
1084  // now that the target is loaded, we can cache the flavor
1086 
1087  MIL << "Target loaded: " << system.solvablesSize() << " resolvables" << endl;
1088  }
1089 
1091  //
1092  // COMMIT
1093  //
1096  {
1097  // ----------------------------------------------------------------- //
1098  ZYppCommitPolicy policy_r( policy_rX );
1099  ShutdownLock lck("Zypp commit running.");
1100 
1101  // Fake outstanding YCP fix: Honour restriction to media 1
1102  // at installation, but install all remaining packages if post-boot.
1103  if ( policy_r.restrictToMedia() > 1 )
1104  policy_r.allMedia();
1105 
1106  if ( policy_r.downloadMode() == DownloadDefault ) {
1107  if ( root() == "/" )
1108  policy_r.downloadMode(DownloadInHeaps);
1109  else
1110  policy_r.downloadMode(DownloadAsNeeded);
1111  }
1112  // DownloadOnly implies dry-run.
1113  else if ( policy_r.downloadMode() == DownloadOnly )
1114  policy_r.dryRun( true );
1115  // ----------------------------------------------------------------- //
1116 
1117  MIL << "TargetImpl::commit(<pool>, " << policy_r << ")" << endl;
1118 
1120  // Compute transaction:
1122  ZYppCommitResult result( root() );
1123  result.rTransaction() = pool_r.resolver().getTransaction();
1124  result.rTransaction().order();
1125  // steps: this is our todo-list
1127  if ( policy_r.restrictToMedia() )
1128  {
1129  // Collect until the 1st package from an unwanted media occurs.
1130  // Further collection could violate install order.
1131  MIL << "Restrict to media number " << policy_r.restrictToMedia() << endl;
1132  for_( it, result.transaction().begin(), result.transaction().end() )
1133  {
1134  if ( makeResObject( *it )->mediaNr() > 1 )
1135  break;
1136  steps.push_back( *it );
1137  }
1138  }
1139  else
1140  {
1141  result.rTransactionStepList().insert( steps.end(), result.transaction().begin(), result.transaction().end() );
1142  }
1143  MIL << "Todo: " << result << endl;
1144 
1146  // Prepare execution of commit plugins:
1148  PluginExecutor commitPlugins;
1149  if ( root() == "/" && ! policy_r.dryRun() )
1150  {
1151  commitPlugins.load( ZConfig::instance().pluginsPath()/"commit" );
1152  }
1153  if ( commitPlugins )
1154  commitPlugins.send( transactionPluginFrame( "COMMITBEGIN", steps ) );
1155 
1157  // Write out a testcase if we're in dist upgrade mode.
1159  if ( pool_r.resolver().upgradeMode() || pool_r.resolver().upgradingRepos() )
1160  {
1161  if ( ! policy_r.dryRun() )
1162  {
1164  }
1165  else
1166  {
1167  DBG << "dryRun: Not writing upgrade testcase." << endl;
1168  }
1169  }
1170 
1172  // Store non-package data:
1174  if ( ! policy_r.dryRun() )
1175  {
1177  // requested locales
1179  // autoinstalled
1180  {
1181  SolvIdentFile::Data newdata;
1182  for ( sat::Queue::value_type id : result.rTransaction().autoInstalled() )
1183  newdata.insert( IdString(id) );
1184  _autoInstalledFile.setData( newdata );
1185  }
1186  // hard locks
1187  if ( ZConfig::instance().apply_locks_file() )
1188  {
1189  HardLocksFile::Data newdata;
1190  pool_r.getHardLockQueries( newdata );
1191  _hardLocksFile.setData( newdata );
1192  }
1193  }
1194  else
1195  {
1196  DBG << "dryRun: Not stroring non-package data." << endl;
1197  }
1198 
1200  // First collect and display all messages
1201  // associated with patches to be installed.
1203  if ( ! policy_r.dryRun() )
1204  {
1205  for_( it, steps.begin(), steps.end() )
1206  {
1207  if ( ! it->satSolvable().isKind<Patch>() )
1208  continue;
1209 
1210  PoolItem pi( *it );
1211  if ( ! pi.status().isToBeInstalled() )
1212  continue;
1213 
1214  Patch::constPtr patch( asKind<Patch>(pi.resolvable()) );
1215  if ( ! patch ||patch->message().empty() )
1216  continue;
1217 
1218  MIL << "Show message for " << patch << endl;
1220  if ( ! report->show( patch ) )
1221  {
1222  WAR << "commit aborted by the user" << endl;
1223  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1224  }
1225  }
1226  }
1227  else
1228  {
1229  DBG << "dryRun: Not checking patch messages." << endl;
1230  }
1231 
1233  // Remove/install packages.
1235  DBG << "commit log file is set to: " << HistoryLog::fname() << endl;
1236  if ( ! policy_r.dryRun() || policy_r.downloadMode() == DownloadOnly )
1237  {
1238  // Prepare the package cache. Pass all items requiring download.
1239  CommitPackageCache packageCache;
1240  packageCache.setCommitList( steps.begin(), steps.end() );
1241 
1242  bool miss = false;
1243  if ( policy_r.downloadMode() != DownloadAsNeeded )
1244  {
1245  // Preload the cache. Until now this means pre-loading all packages.
1246  // Once DownloadInHeaps is fully implemented, this will change and
1247  // we may actually have more than one heap.
1248  for_( it, steps.begin(), steps.end() )
1249  {
1250  switch ( it->stepType() )
1251  {
1254  // proceed: only install actionas may require download.
1255  break;
1256 
1257  default:
1258  // next: no download for or non-packages and delete actions.
1259  continue;
1260  break;
1261  }
1262 
1263  PoolItem pi( *it );
1264  if ( pi->isKind<Package>() || pi->isKind<SrcPackage>() )
1265  {
1266  ManagedFile localfile;
1267  try
1268  {
1269  localfile = packageCache.get( pi );
1270  localfile.resetDispose(); // keep the package file in the cache
1271  }
1272  catch ( const AbortRequestException & exp )
1273  {
1274  it->stepStage( sat::Transaction::STEP_ERROR );
1275  miss = true;
1276  WAR << "commit cache preload aborted by the user" << endl;
1277  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1278  break;
1279  }
1280  catch ( const SkipRequestException & exp )
1281  {
1282  ZYPP_CAUGHT( exp );
1283  it->stepStage( sat::Transaction::STEP_ERROR );
1284  miss = true;
1285  WAR << "Skipping cache preload package " << pi->asKind<Package>() << " in commit" << endl;
1286  continue;
1287  }
1288  catch ( const Exception & exp )
1289  {
1290  // bnc #395704: missing catch causes abort.
1291  // TODO see if packageCache fails to handle errors correctly.
1292  ZYPP_CAUGHT( exp );
1293  it->stepStage( sat::Transaction::STEP_ERROR );
1294  miss = true;
1295  INT << "Unexpected Error: Skipping cache preload package " << pi->asKind<Package>() << " in commit" << endl;
1296  continue;
1297  }
1298  }
1299  }
1300  packageCache.preloaded( true ); // try to avoid duplicate infoInCache CBs in commit
1301  }
1302 
1303  if ( miss )
1304  {
1305  ERR << "Some packages could not be provided. Aborting commit."<< endl;
1306  }
1307  else
1308  {
1309  if ( ! policy_r.dryRun() )
1310  {
1311  // if cache is preloaded, check for file conflicts
1312  commitFindFileConflicts( policy_r, result );
1313  commit( policy_r, packageCache, result );
1314  }
1315  else
1316  {
1317  DBG << "dryRun/downloadOnly: Not installing/deleting anything." << endl;
1318  }
1319  }
1320  }
1321  else
1322  {
1323  DBG << "dryRun: Not downloading/installing/deleting anything." << endl;
1324  }
1325 
1327  // Send result to commit plugins:
1329  if ( commitPlugins )
1330  commitPlugins.send( transactionPluginFrame( "COMMITEND", steps ) );
1331 
1333  // Try to rebuild solv file while rpm database is still in cache
1335  if ( ! policy_r.dryRun() )
1336  {
1337  buildCache();
1338  }
1339 
1340  MIL << "TargetImpl::commit(<pool>, " << policy_r << ") returns: " << result << endl;
1341  return result;
1342  }
1343 
1345  //
1346  // COMMIT internal
1347  //
1349  namespace
1350  {
1351  struct NotifyAttemptToModify
1352  {
1353  NotifyAttemptToModify( ZYppCommitResult & result_r ) : _result( result_r ) {}
1354 
1355  void operator()()
1356  { if ( _guard ) { _result.attemptToModify( true ); _guard = false; } }
1357 
1358  TrueBool _guard;
1359  ZYppCommitResult & _result;
1360  };
1361  } // namespace
1362 
1363  void TargetImpl::commit( const ZYppCommitPolicy & policy_r,
1364  CommitPackageCache & packageCache_r,
1365  ZYppCommitResult & result_r )
1366  {
1367  // steps: this is our todo-list
1369  MIL << "TargetImpl::commit(<list>" << policy_r << ")" << steps.size() << endl;
1370 
1372 
1373  // Send notification once upon 1st call to rpm
1374  NotifyAttemptToModify attemptToModify( result_r );
1375 
1376  bool abort = false;
1377 
1378  RpmPostTransCollector postTransCollector( _root );
1379  std::vector<sat::Solvable> successfullyInstalledPackages;
1380  TargetImpl::PoolItemList remaining;
1381 
1382  for_( step, steps.begin(), steps.end() )
1383  {
1384  PoolItem citem( *step );
1385  if ( step->stepType() == sat::Transaction::TRANSACTION_IGNORE )
1386  {
1387  if ( citem->isKind<Package>() )
1388  {
1389  // for packages this means being obsoleted (by rpm)
1390  // thius no additional action is needed.
1391  step->stepStage( sat::Transaction::STEP_DONE );
1392  continue;
1393  }
1394  }
1395 
1396  if ( citem->isKind<Package>() )
1397  {
1398  Package::constPtr p = citem->asKind<Package>();
1399  if ( citem.status().isToBeInstalled() )
1400  {
1401  ManagedFile localfile;
1402  try
1403  {
1404  localfile = packageCache_r.get( citem );
1405  }
1406  catch ( const AbortRequestException &e )
1407  {
1408  WAR << "commit aborted by the user" << endl;
1409  abort = true;
1410  step->stepStage( sat::Transaction::STEP_ERROR );
1411  break;
1412  }
1413  catch ( const SkipRequestException &e )
1414  {
1415  ZYPP_CAUGHT( e );
1416  WAR << "Skipping package " << p << " in commit" << endl;
1417  step->stepStage( sat::Transaction::STEP_ERROR );
1418  continue;
1419  }
1420  catch ( const Exception &e )
1421  {
1422  // bnc #395704: missing catch causes abort.
1423  // TODO see if packageCache fails to handle errors correctly.
1424  ZYPP_CAUGHT( e );
1425  INT << "Unexpected Error: Skipping package " << p << " in commit" << endl;
1426  step->stepStage( sat::Transaction::STEP_ERROR );
1427  continue;
1428  }
1429 
1430 #warning Exception handling
1431  // create a installation progress report proxy
1432  RpmInstallPackageReceiver progress( citem.resolvable() );
1433  progress.connect(); // disconnected on destruction.
1434 
1435  bool success = false;
1436  rpm::RpmInstFlags flags( policy_r.rpmInstFlags() & rpm::RPMINST_JUSTDB );
1437  // Why force and nodeps?
1438  //
1439  // Because zypp builds the transaction and the resolver asserts that
1440  // everything is fine.
1441  // We use rpm just to unpack and register the package in the database.
1442  // We do this step by step, so rpm is not aware of the bigger context.
1443  // So we turn off rpms internal checks, because we do it inside zypp.
1444  flags |= rpm::RPMINST_NODEPS;
1445  flags |= rpm::RPMINST_FORCE;
1446  //
1447  if (p->multiversionInstall()) flags |= rpm::RPMINST_NOUPGRADE;
1448  if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
1449  if (policy_r.rpmExcludeDocs()) flags |= rpm::RPMINST_EXCLUDEDOCS;
1450  if (policy_r.rpmNoSignature()) flags |= rpm::RPMINST_NOSIGNATURE;
1451 
1452  attemptToModify();
1453  try
1454  {
1456  if ( postTransCollector.collectScriptFromPackage( localfile ) )
1457  flags |= rpm::RPMINST_NOPOSTTRANS;
1458  rpm().installPackage( localfile, flags );
1459  HistoryLog().install(citem);
1460 
1461  if ( progress.aborted() )
1462  {
1463  WAR << "commit aborted by the user" << endl;
1464  localfile.resetDispose(); // keep the package file in the cache
1465  abort = true;
1466  step->stepStage( sat::Transaction::STEP_ERROR );
1467  break;
1468  }
1469  else
1470  {
1471  success = true;
1472  step->stepStage( sat::Transaction::STEP_DONE );
1473  }
1474  }
1475  catch ( Exception & excpt_r )
1476  {
1477  ZYPP_CAUGHT(excpt_r);
1478  localfile.resetDispose(); // keep the package file in the cache
1479 
1480  if ( policy_r.dryRun() )
1481  {
1482  WAR << "dry run failed" << endl;
1483  step->stepStage( sat::Transaction::STEP_ERROR );
1484  break;
1485  }
1486  // else
1487  if ( progress.aborted() )
1488  {
1489  WAR << "commit aborted by the user" << endl;
1490  abort = true;
1491  }
1492  else
1493  {
1494  WAR << "Install failed" << endl;
1495  }
1496  step->stepStage( sat::Transaction::STEP_ERROR );
1497  break; // stop
1498  }
1499 
1500  if ( success && !policy_r.dryRun() )
1501  {
1503  successfullyInstalledPackages.push_back( citem.satSolvable() );
1504  step->stepStage( sat::Transaction::STEP_DONE );
1505  }
1506  }
1507  else
1508  {
1509  RpmRemovePackageReceiver progress( citem.resolvable() );
1510  progress.connect(); // disconnected on destruction.
1511 
1512  bool success = false;
1513  rpm::RpmInstFlags flags( policy_r.rpmInstFlags() & rpm::RPMINST_JUSTDB );
1514  flags |= rpm::RPMINST_NODEPS;
1515  if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
1516 
1517  attemptToModify();
1518  try
1519  {
1520  rpm().removePackage( p, flags );
1521  HistoryLog().remove(citem);
1522 
1523  if ( progress.aborted() )
1524  {
1525  WAR << "commit aborted by the user" << endl;
1526  abort = true;
1527  step->stepStage( sat::Transaction::STEP_ERROR );
1528  break;
1529  }
1530  else
1531  {
1532  success = true;
1533  step->stepStage( sat::Transaction::STEP_DONE );
1534  }
1535  }
1536  catch (Exception & excpt_r)
1537  {
1538  ZYPP_CAUGHT( excpt_r );
1539  if ( progress.aborted() )
1540  {
1541  WAR << "commit aborted by the user" << endl;
1542  abort = true;
1543  step->stepStage( sat::Transaction::STEP_ERROR );
1544  break;
1545  }
1546  // else
1547  WAR << "removal of " << p << " failed";
1548  step->stepStage( sat::Transaction::STEP_ERROR );
1549  }
1550  if ( success && !policy_r.dryRun() )
1551  {
1553  step->stepStage( sat::Transaction::STEP_DONE );
1554  }
1555  }
1556  }
1557  else if ( ! policy_r.dryRun() ) // other resolvables (non-Package)
1558  {
1559  // Status is changed as the buddy package buddy
1560  // gets installed/deleted. Handle non-buddies only.
1561  if ( ! citem.buddy() )
1562  {
1563  if ( citem->isKind<Product>() )
1564  {
1565  Product::constPtr p = citem->asKind<Product>();
1566  if ( citem.status().isToBeInstalled() )
1567  {
1568  ERR << "Can't install orphan product without release-package! " << citem << endl;
1569  }
1570  else
1571  {
1572  // Deleting the corresponding product entry is all we con do.
1573  // So the product will no longer be visible as installed.
1574  std::string referenceFilename( p->referenceFilename() );
1575  if ( referenceFilename.empty() )
1576  {
1577  ERR << "Can't remove orphan product without 'referenceFilename'! " << citem << endl;
1578  }
1579  else
1580  {
1581  PathInfo referenceFile( Pathname::assertprefix( _root, Pathname( "/etc/products.d" ) ) / referenceFilename );
1582  if ( ! referenceFile.isFile() || filesystem::unlink( referenceFile.path() ) != 0 )
1583  {
1584  ERR << "Delete orphan product failed: " << referenceFile << endl;
1585  }
1586  }
1587  }
1588  }
1589  else if ( citem->isKind<SrcPackage>() && citem.status().isToBeInstalled() )
1590  {
1591  // SrcPackage is install-only
1592  SrcPackage::constPtr p = citem->asKind<SrcPackage>();
1593  installSrcPackage( p );
1594  }
1595 
1597  step->stepStage( sat::Transaction::STEP_DONE );
1598  }
1599 
1600  } // other resolvables
1601 
1602  } // for
1603 
1604  // process all remembered posttrans scripts. If aborting,
1605  // at least log omitted scripts.
1606  if ( abort || (abort = !postTransCollector.executeScripts()) )
1607  postTransCollector.discardScripts();
1608 
1609  // Check presence of update scripts/messages. If aborting,
1610  // at least log omitted scripts.
1611  if ( ! successfullyInstalledPackages.empty() )
1612  {
1613  if ( ! RunUpdateScripts( _root, ZConfig::instance().update_scriptsPath(),
1614  successfullyInstalledPackages, abort ) )
1615  {
1616  WAR << "Commit aborted by the user" << endl;
1617  abort = true;
1618  }
1619  // send messages after scripts in case some script generates output,
1620  // that should be kept in t %ghost message file.
1621  RunUpdateMessages( _root, ZConfig::instance().update_messagesPath(),
1622  successfullyInstalledPackages,
1623  result_r );
1624  }
1625 
1626  if ( abort )
1627  {
1628  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1629  }
1630  }
1631 
1633 
1635  {
1636  return _rpm;
1637  }
1638 
1639  bool TargetImpl::providesFile (const std::string & path_str, const std::string & name_str) const
1640  {
1641  return _rpm.hasFile(path_str, name_str);
1642  }
1643 
1644 
1646  {
1647  return _rpm.timestamp();
1648  }
1649 
1651  namespace
1652  {
1653  parser::ProductFileData baseproductdata( const Pathname & root_r )
1654  {
1656  PathInfo baseproduct( Pathname::assertprefix( root_r, "/etc/products.d/baseproduct" ) );
1657 
1658  if ( baseproduct.isFile() )
1659  {
1660  try
1661  {
1662  ret = parser::ProductFileReader::scanFile( baseproduct.path() );
1663  }
1664  catch ( const Exception & excpt )
1665  {
1666  ZYPP_CAUGHT( excpt );
1667  }
1668  }
1669  else if ( PathInfo( Pathname::assertprefix( root_r, "/etc/products.d" ) ).isDir() )
1670  {
1671  ERR << "baseproduct symlink is dangling or missing: " << baseproduct << endl;
1672  }
1673  return ret;
1674  }
1675 
1676  inline Pathname staticGuessRoot( const Pathname & root_r )
1677  {
1678  if ( root_r.empty() )
1679  {
1680  // empty root: use existing Target or assume "/"
1681  Pathname ret ( ZConfig::instance().systemRoot() );
1682  if ( ret.empty() )
1683  return Pathname("/");
1684  return ret;
1685  }
1686  return root_r;
1687  }
1688 
1689  inline std::string firstNonEmptyLineIn( const Pathname & file_r )
1690  {
1691  std::ifstream idfile( file_r.c_str() );
1692  for( iostr::EachLine in( idfile ); in; in.next() )
1693  {
1694  std::string line( str::trim( *in ) );
1695  if ( ! line.empty() )
1696  return line;
1697  }
1698  return std::string();
1699  }
1700  } // namespace
1702 
1704  {
1705  ResPool pool(ResPool::instance());
1706  for_( it, pool.byKindBegin<Product>(), pool.byKindEnd<Product>() )
1707  {
1708  Product::constPtr p = (*it)->asKind<Product>();
1709  if ( p->isTargetDistribution() )
1710  return p;
1711  }
1712  return nullptr;
1713  }
1714 
1716  {
1717  const Pathname needroot( staticGuessRoot(root_r) );
1718  const Target_constPtr target( getZYpp()->getTarget() );
1719  if ( target && target->root() == needroot )
1720  return target->requestedLocales();
1721  return RequestedLocalesFile( home(needroot) / "RequestedLocales" ).locales();
1722  }
1723 
1725  {
1726  MIL << "updateAutoInstalled if changed..." << endl;
1727  SolvIdentFile::Data newdata;
1728  for ( auto id : sat::Pool::instance().autoInstalled() )
1729  newdata.insert( IdString(id) ); // explicit ctor!
1730  _autoInstalledFile.setData( std::move(newdata) );
1731  }
1732 
1734  { return baseproductdata( _root ).registerTarget(); }
1735  // static version:
1736  std::string TargetImpl::targetDistribution( const Pathname & root_r )
1737  { return baseproductdata( staticGuessRoot(root_r) ).registerTarget(); }
1738 
1740  { return baseproductdata( _root ).registerRelease(); }
1741  // static version:
1742  std::string TargetImpl::targetDistributionRelease( const Pathname & root_r )
1743  { return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
1744 
1746  { return baseproductdata( _root ).registerFlavor(); }
1747  // static version:
1748  std::string TargetImpl::targetDistributionFlavor( const Pathname & root_r )
1749  { return baseproductdata( staticGuessRoot(root_r) ).registerFlavor();}
1750 
1752  {
1754  parser::ProductFileData pdata( baseproductdata( _root ) );
1755  ret.shortName = pdata.shortName();
1756  ret.summary = pdata.summary();
1757  return ret;
1758  }
1759  // static version:
1761  {
1763  parser::ProductFileData pdata( baseproductdata( staticGuessRoot(root_r) ) );
1764  ret.shortName = pdata.shortName();
1765  ret.summary = pdata.summary();
1766  return ret;
1767  }
1768 
1770  {
1771  if ( _distributionVersion.empty() )
1772  {
1774  if ( !_distributionVersion.empty() )
1775  MIL << "Remember distributionVersion = '" << _distributionVersion << "'" << endl;
1776  }
1777  return _distributionVersion;
1778  }
1779  // static version
1780  std::string TargetImpl::distributionVersion( const Pathname & root_r )
1781  {
1782  std::string distributionVersion = baseproductdata( staticGuessRoot(root_r) ).edition().version();
1783  if ( distributionVersion.empty() )
1784  {
1785  // ...But the baseproduct method is not expected to work on RedHat derivatives.
1786  // On RHEL, Fedora and others the "product version" is determined by the first package
1787  // providing 'system-release'. This value is not hardcoded in YUM and can be configured
1788  // with the $distroverpkg variable.
1789  scoped_ptr<rpm::RpmDb> tmprpmdb;
1790  if ( ZConfig::instance().systemRoot() == Pathname() )
1791  {
1792  try
1793  {
1794  tmprpmdb.reset( new rpm::RpmDb );
1795  tmprpmdb->initDatabase( /*default ctor uses / but no additional keyring exports */ );
1796  }
1797  catch( ... )
1798  {
1799  return "";
1800  }
1801  }
1804  distributionVersion = it->tag_version();
1805  }
1806  return distributionVersion;
1807  }
1808 
1809 
1811  {
1812  return firstNonEmptyLineIn( home() / "LastDistributionFlavor" );
1813  }
1814  // static version:
1815  std::string TargetImpl::distributionFlavor( const Pathname & root_r )
1816  {
1817  return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/LastDistributionFlavor" );
1818  }
1819 
1821  namespace
1822  {
1823  std::string guessAnonymousUniqueId( const Pathname & root_r )
1824  {
1825  // bsc#1024741: Omit creating a new uid for chrooted systems (if it already has one, fine)
1826  std::string ret( firstNonEmptyLineIn( root_r / "/var/lib/zypp/AnonymousUniqueId" ) );
1827  if ( ret.empty() && root_r != "/" )
1828  {
1829  // if it has nonoe, use the outer systems one
1830  ret = firstNonEmptyLineIn( "/var/lib/zypp/AnonymousUniqueId" );
1831  }
1832  return ret;
1833  }
1834  }
1835 
1836  std::string TargetImpl::anonymousUniqueId() const
1837  {
1838  return guessAnonymousUniqueId( root() );
1839  }
1840  // static version:
1841  std::string TargetImpl::anonymousUniqueId( const Pathname & root_r )
1842  {
1843  return guessAnonymousUniqueId( staticGuessRoot(root_r) );
1844  }
1845 
1847 
1848  void TargetImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
1849  {
1850  // provide on local disk
1851  ManagedFile localfile = provideSrcPackage(srcPackage_r);
1852  // create a installation progress report proxy
1853  RpmInstallPackageReceiver progress( srcPackage_r );
1854  progress.connect(); // disconnected on destruction.
1855  // install it
1856  rpm().installPackage ( localfile );
1857  }
1858 
1859  ManagedFile TargetImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
1860  {
1861  // provide on local disk
1862  repo::RepoMediaAccess access_r;
1863  repo::SrcPackageProvider prov( access_r );
1864  return prov.provideSrcPackage( srcPackage_r );
1865  }
1867  } // namespace target
1870 } // namespace zypp
static bool fileMissing(const Pathname &pathname)
helper functor
Definition: TargetImpl.cc:748
std::string asJSON() const
JSON representation.
Definition: Json.h:344
ZYppCommitResult commit(ResPool pool_r, const ZYppCommitPolicy &policy_r)
Commit changes in the pool.
Definition: TargetImpl.cc:1095
int assert_dir(const Pathname &path, unsigned mode)
Like &#39;mkdir -p&#39;.
Definition: PathInfo.cc:320
Interface to gettext.
Interface to the rpm program.
Definition: RpmDb.h:47
Product interface.
Definition: Product.h:32
#define MIL
Definition: Logger.h:64
sat::Transaction getTransaction()
Return the Transaction computed by the last solver run.
Definition: Resolver.cc:74
bool upgradingRepos() const
Whether there is at least one UpgradeRepo request pending.
Definition: Resolver.cc:133
A Solvable object within the sat Pool.
Definition: Solvable.h:53
const std::string & command() const
The command we&#39;re executing.
std::vector< sat::Transaction::Step > TransactionStepList
Save and restore locale set from file.
Alternating download and install.
Definition: DownloadMode.h:32
ZYppCommitPolicy & rpmNoSignature(bool yesNo_r)
Use rpm option –nosignature (default: false)
const LocaleSet & getRequestedLocales() const
Return the requested locales.
Definition: ResPool.cc:125
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r) const
Provide SrcPackage in a local file.
[M] Install(multiversion) item (
Definition: Transaction.h:67
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \, bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Definition: String.h:561
bool solvfilesPathIsTemp() const
Whether we&#39;re using a temp.
Definition: TargetImpl.h:96
const Pathname & path() const
Return current Pathname.
Definition: PathInfo.h:246
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
Solvable satSolvable() const
Return the corresponding Solvable.
Definition: Transaction.h:241
Result returned from ZYpp::commit.
static ZConfig & instance()
Singleton ctor.
Definition: Resolver.cc:125
bool isToBeInstalled() const
Definition: ResStatus.h:244
void addSolv(const Pathname &file_r)
Load Solvables from a solv-file.
Definition: Repository.cc:320
std::string md5sum(const Pathname &file)
Compute a files md5sum.
Definition: PathInfo.cc:977
Command frame for communication with PluginScript.
Definition: PluginFrame.h:40
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:826
int readlink(const Pathname &symlink_r, Pathname &target_r)
Like &#39;readlink&#39;.
Definition: PathInfo.cc:877
void setData(const Data &data_r)
Store new Data.
Definition: SolvIdentFile.h:69
SolvIdentFile _autoInstalledFile
user/auto installed database
Definition: TargetImpl.h:219
detail::IdType value_type
Definition: Queue.h:38
Architecture.
Definition: Arch.h:36
static ProductFileData scanFile(const Pathname &file_r)
Parse one file (or symlink) and return the ProductFileData parsed.
void updateFileContent(const Pathname &filename, boost::function< bool()> condition, boost::function< string()> value)
updates the content of filename if condition is true, setting the content the the value returned by v...
Definition: TargetImpl.cc:713
void stampCommand()
Log info about the current process.
Definition: HistoryLog.cc:220
Target::commit helper optimizing package provision.
ZYppCommitPolicy & rpmInstFlags(target::rpm::RpmInstFlags newFlags_r)
The default target::rpm::RpmInstFlags.
TransactionStepList & rTransactionStepList()
Manipulate transactionStepList.
const sat::Transaction & transaction() const
The full transaction list.
void discardScripts()
Discard all remembered scrips.
StepStage stepStage() const
Step action result.
Definition: Transaction.cc:389
const Pathname & file() const
Return the file path.
Definition: SolvIdentFile.h:46
#define INT
Definition: Logger.h:68
int chmod(const Pathname &path, mode_t mode)
Like &#39;chmod&#39;.
Definition: PathInfo.cc:1045
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:204
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1957
ZYppCommitPolicy & dryRun(bool yesNo_r)
Set dry run (default: false).
byKind_iterator byKindBegin(const ResKind &kind_r) const
Definition: ResPool.h:261
void updateAutoInstalled()
Update the database of autoinstalled packages.
Definition: TargetImpl.cc:1724
#define N_(MSG)
Just tag text for translation.
Definition: Gettext.h:18
ZYppCommitPolicy & rpmExcludeDocs(bool yesNo_r)
Use rpm option –excludedocs (default: false)
const char * c_str() const
String representation.
Definition: Pathname.h:109
Date timestamp() const
timestamp of the rpm database (last modification)
Definition: RpmDb.cc:261
std::string _distributionVersion
Cache distributionVersion.
Definition: TargetImpl.h:223
void commitFindFileConflicts(const ZYppCommitPolicy &policy_r, ZYppCommitResult &result_r)
Commit helper checking for file conflicts after download.
Parallel execution of stateful PluginScripts.
void setData(const Data &data_r)
Store new Data.
Definition: HardLocksFile.h:73
void setAutoInstalled(const Queue &autoInstalled_r)
Set ident list of all autoinstalled solvables.
Definition: Pool.cc:244
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:206
Definition: Arch.h:344
Access to the sat-pools string space.
Definition: IdString.h:41
Libsolv transaction wrapper.
Definition: Transaction.h:51
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
Pathname path() const
Definition: TmpPath.cc:146
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
Attempts to create a lock to prevent the system from going into hibernate/shutdown.
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition: ResStatus.h:476
Similar to DownloadInAdvance, but try to split the transaction into heaps, where at the end of each h...
Definition: DownloadMode.h:29
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::...
Definition: TargetImpl.cc:1639
TraitsType::constPtrType constPtr
Definition: Product.h:38
const_iterator end() const
Iterator behind the last TransactionStep.
Definition: Transaction.cc:341
Provide a new empty temporary file and delete it when no longer needed.
Definition: TmpPath.h:127
unsigned epoch_t
Type of an epoch.
Definition: Edition.h:64
void writeUpgradeTestcase()
Definition: TargetImpl.cc:248
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
Definition: String.cc:36
static RepoStatus fromCookieFile(const Pathname &path)
Reads the status from a cookie file.
Definition: RepoStatus.cc:108
Class representing a patch.
Definition: Patch.h:36
void installSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Install a source package on the Target.
Definition: TargetImpl.cc:1848
std::string targetDistributionFlavor() const
This is register.flavor attribute of the installed base product.
Definition: TargetImpl.cc:1745
void install(const PoolItem &pi)
Log installation (or update) of a package.
Definition: HistoryLog.cc:232
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition: PoolItem.cc:217
#define ERR
Definition: Logger.h:66
JSON object.
Definition: Json.h:321
std::vector< std::string > Arguments
std::string targetDistributionRelease() const
This is register.release attribute of the installed base product.
Definition: TargetImpl.cc:1739
Extract and remember posttrans scripts for later execution.
Subclass to retrieve database content.
Definition: librpmDb.h:490
void remember(const Exception &old_r)
Store an other Exception as history.
Definition: Exception.cc:105
rpm::RpmDb _rpm
RPM database.
Definition: TargetImpl.h:215
Repository systemRepo()
Return the system repository, create it if missing.
Definition: Pool.cc:157
std::string distributionVersion() const
This is version attribute of the installed base product.
Definition: TargetImpl.cc:1769
const LocaleSet & locales() const
Return the loacale set.
void createLastDistributionFlavorCache() const
generates a cache of the last product flavor
Definition: TargetImpl.cc:775
void initRequestedLocales(const LocaleSet &locales_r)
Start tracking changes based on this locales_r.
Definition: Pool.cc:230
void saveToCookieFile(const Pathname &path_r) const
Save the status information to a cookie file.
Definition: RepoStatus.cc:126
StringQueue autoInstalled() const
Return the ident strings of all packages that would be auto-installed after the transaction is run...
Definition: Transaction.cc:356
LocaleSet requestedLocales() const
Languages to be supported by the system.
Definition: TargetImpl.h:160
[ ] Nothing (includes implicit deletes due to obsoletes and non-package actions)
Definition: Transaction.h:64
bool empty() const
Test for an empty path.
Definition: Pathname.h:113
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
Definition: PathInfo.cc:1054
void push(value_type val_r)
Push a value to the end off the Queue.
Definition: Queue.cc:103
std::string getline(std::istream &str)
Read one line from stream.
Definition: IOStream.cc:33
Store and operate on date (time_t).
Definition: Date.h:32
SolvableIterator solvablesEnd() const
Iterator behind the last Solvable.
Definition: Repository.cc:241
static Pool instance()
Singleton ctor.
Definition: Pool.h:53
const Data & data() const
Return the data.
Definition: SolvIdentFile.h:53
std::string version() const
Version.
Definition: Edition.cc:94
Pathname _root
Path to the target.
Definition: TargetImpl.h:213
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
std::string trim(const std::string &s, const Trim trim_r)
Definition: String.cc:221
int unlink(const Pathname &path)
Like &#39;unlink&#39;.
Definition: PathInfo.cc:653
static const std::string & systemRepoAlias()
Reserved system repository alias .
Definition: Pool.cc:46
bool collectScriptFromPackage(ManagedFile rpmPackage_r)
Extract and remember a packages posttrans script for later execution.
static const Pathname & fname()
Get the current log file path.
Definition: HistoryLog.cc:179
bool executeScripts()
Execute the remembered scripts.
const std::string & asString() const
String representation.
Definition: Pathname.h:90
void send(const PluginFrame &frame_r)
Send PluginFrame to all open plugins.
int rename(const Pathname &oldpath, const Pathname &newpath)
Like &#39;rename&#39;.
Definition: PathInfo.cc:695
Just download all packages to the local cache.
Definition: DownloadMode.h:25
Options and policies for ZYpp::commit.
bool isExist() const
Return whether valid stat info exists.
Definition: PathInfo.h:281
libzypp will decide what to do.
Definition: DownloadMode.h:24
A single step within a Transaction.
Definition: Transaction.h:216
Package interface.
Definition: Package.h:32
ZYppCommitPolicy & downloadMode(DownloadMode val_r)
Commit download policy to use.
RequestedLocalesFile _requestedLocalesFile
Requested Locales database.
Definition: TargetImpl.h:217
void setLocales(const LocaleSet &locales_r)
Store a new locale set.
Pathname rootDir() const
Get rootdir (for file conflicts check)
Definition: Pool.cc:64
void getHardLockQueries(HardLockQueries &activeLocks_r)
Suggest a new set of queries based on the current selection.
Definition: ResPool.cc:101
Pathname dirname() const
Return all but the last component od this path.
Definition: Pathname.h:123
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
Definition: Pathname.cc:235
int recursive_rmdir(const Pathname &path)
Like &#39;rm -r DIR&#39;.
Definition: PathInfo.cc:413
std::string release() const
Release.
Definition: Edition.cc:110
Interim helper class to collect global options and settings.
Definition: ZConfig.h:59
#define WAR
Definition: Logger.h:65
SolvableIterator solvablesBegin() const
Iterator to the first Solvable.
Definition: Repository.cc:231
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1078
bool order()
Order transaction steps for commit.
Definition: Transaction.cc:326
Pathname solvfilesPath() const
The solv file location actually in use (default or temp).
Definition: TargetImpl.h:92
void updateSolvFileIndex(const Pathname &solvfile_r)
Create solv file content digest for zypper bash completion.
Definition: Pool.cc:263
std::string targetDistribution() const
This is register.target attribute of the installed base product.
Definition: TargetImpl.cc:1733
Resolver & resolver() const
The Resolver.
Definition: ResPool.cc:57
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
Definition: HistoryLog.h:55
TraitsType::constPtrType constPtr
Definition: Patch.h:42
JSON array.
Definition: Json.h:256
#define _(MSG)
Definition: Gettext.h:29
std::string receiveLine()
Read one line from the input stream.
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:713
Date timestamp() const
return the last modification date of the target
Definition: TargetImpl.cc:1645
ZYppCommitPolicy & restrictToMedia(unsigned mediaNr_r)
Restrict commit to media 1.
std::list< PoolItem > PoolItemList
list of pool items
Definition: TargetImpl.h:59
std::string anonymousUniqueId() const
anonymous unique id
Definition: TargetImpl.cc:1836
const Pathname & _root
Definition: RepoManager.cc:145
std::string toLower(const std::string &s)
Return lowercase version of s.
Definition: String.cc:175
Pathname home() const
The directory to store things.
Definition: TargetImpl.h:120
static std::string generateRandomId()
generates a random id using uuidgen
Definition: TargetImpl.cc:702
void resetDispose()
Set no dispose function.
Definition: AutoDispose.h:162
Provides files from different repos.
ManagedFile get(const PoolItem &citem_r)
Provide a package.
HardLocksFile _hardLocksFile
Hard-Locks database.
Definition: TargetImpl.h:221
SolvableIdType size_type
Definition: PoolMember.h:126
static void setRoot(const Pathname &root)
Set new root directory to the default history log file path.
Definition: HistoryLog.cc:163
int close()
Wait for the progamm to complete.
byKind_iterator byKindEnd(const ResKind &kind_r) const
Definition: ResPool.h:268
void setHardLockQueries(const HardLockQueries &newLocks_r)
Set a new set of queries.
Definition: ResPool.cc:98
#define SUBST_IF(PAT, VAL)
std::list< UpdateNotificationFile > UpdateNotifications
Libsolv Id queue wrapper.
Definition: Queue.h:34
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition: PathInfo.cc:589
SrcPackage interface.
Definition: SrcPackage.h:29
bool upgradeMode() const
Definition: Resolver.cc:94
Global ResObject pool.
Definition: ResPool.h:60
Product::constPtr baseProduct() const
returns the target base installed product, also known as the distribution or platform.
Definition: TargetImpl.cc:1703
void createAnonymousId() const
generates the unique anonymous id which is called when creating the target
Definition: TargetImpl.cc:753
ZYppCommitPolicy & allMedia()
Process all media (default)
const_iterator begin() const
Iterator to the first TransactionStep.
Definition: Transaction.cc:335
pool::PoolTraits::HardLockQueries Data
Definition: HardLocksFile.h:41
void add(const Value &val_r)
Push JSON Value to Array.
Definition: Json.h:271
StepType stepType() const
Type of action to perform in this step.
Definition: Transaction.cc:386
const Data & data() const
Return the data.
Definition: HardLocksFile.h:57
Base class for Exception.
Definition: Exception.h:145
bool preloaded() const
Whether preloaded hint is set.
void load(const Pathname &path_r)
Find and launch plugins sending PLUGINBEGIN.
Data returned by ProductFileReader.
std::string asJSON() const
JSON representation.
Definition: Json.h:279
void remove(const PoolItem &pi)
Log removal of a package.
Definition: HistoryLog.cc:261
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:203
void initDatabase(Pathname root_r=Pathname(), Pathname dbPath_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database.
Definition: RpmDb.cc:315
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:2144
epoch_t epoch() const
Epoch.
Definition: Edition.cc:82
std::string distroverpkg() const
Package telling the "product version" on systems not using /etc/product.d/baseproduct.
Definition: ZConfig.cc:1164
Pathname root() const
The root set for this target.
Definition: TargetImpl.h:116
virtual ~TargetImpl()
Dtor.
Definition: TargetImpl.cc:811
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:92
void eraseFromPool()
Remove this Repository from it&#39;s Pool.
Definition: Repository.cc:297
Global sat-pool.
Definition: Pool.h:44
bool hasFile(const std::string &file_r, const std::string &name_r="") const
Return true if at least one package owns a certain file (name_r empty) Return true if package name_r ...
Definition: RpmDb.cc:1339
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
Definition: HistoryLog.cc:188
TraitsType::constPtrType constPtr
Definition: SrcPackage.h:36
Wrapper class for ::stat/::lstat.
Definition: PathInfo.h:220
bool solvablesEmpty() const
Whether Repository contains solvables.
Definition: Repository.cc:219
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:44
sat::Transaction & rTransaction()
Manipulate transaction.
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
Pathname systemRoot() const
The target root directory.
Definition: ZConfig.cc:819
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Provides a source package on the Target.
Definition: TargetImpl.cc:1859
static TmpFile makeSibling(const Pathname &sibling_r)
Provide a new empty temporary directory as sibling.
Definition: TmpPath.cc:218
Target::DistributionLabel distributionLabel() const
This is shortName and summary attribute of the installed base product.
Definition: TargetImpl.cc:1751
Track changing files or directories.
Definition: RepoStatus.h:38
std::string asString() const
Conversion to std::string
Definition: IdString.h:91
bool isKind(const ResKind &kind_r) const
Definition: SolvableType.h:64
std::string toJSON(const sat::Transaction::Step &step_r)
See COMMITBEGIN (added in v1) on page Commit plugin for the specs.
Definition: TargetImpl.cc:99
const std::string & asString() const
Definition: Arch.cc:481
void XRunUpdateMessages(const Pathname &root_r, const Pathname &messagesPath_r, const std::vector< sat::Solvable > &checkPackages_r, ZYppCommitResult &result_r)
Definition: TargetImpl.cc:669
std::string distributionFlavor() const
This is flavor attribute of the installed base product but does not require the target to be loaded a...
Definition: TargetImpl.cc:1810
size_type solvablesSize() const
Number of solvables in Repository.
Definition: Repository.cc:225
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::unordered_set< IdString > Data
Definition: SolvIdentFile.h:37
Pathname defaultSolvfilesPath() const
The systems default solv file location.
Definition: TargetImpl.cc:824
#define idstr(V)
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
void add(const String &key_r, const Value &val_r)
Add key/value pair.
Definition: Json.h:336
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Definition: String.h:1020
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
bool empty() const
Whether this is an empty object without valid data.
std::unordered_set< Locale > LocaleSet
Definition: Locale.h:27
TrueBool _guard
Definition: TargetImpl.cc:1358
rpm::RpmDb & rpm()
The RPM database.
Definition: TargetImpl.cc:1634
TraitsType::constPtrType constPtr
Definition: Package.h:38
#define IMPL_PTR_TYPE(NAME)
#define DBG
Definition: Logger.h:63
ZYppCommitResult & _result
Definition: TargetImpl.cc:1359
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33
void load(bool force=true)
Definition: TargetImpl.cc:990