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