libzypp  15.3.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/PluginScript.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 
227  {
228  public:
231  {}
232 
235  {
236  if ( ! _scripts.empty() )
237  send( PluginFrame( "PLUGINEND" ) );
238  // ~PluginScript will disconnect all remaining plugins!
239  }
240 
242  bool empty() const
243  { return _scripts.empty(); }
244 
245 
249  void send( const PluginFrame & frame_r )
250  {
251  DBG << "+++++++++++++++ send " << frame_r << endl;
252  for ( auto it = _scripts.begin(); it != _scripts.end(); )
253  {
254  doSend( *it, frame_r );
255  if ( it->isOpen() )
256  ++it;
257  else
258  it = _scripts.erase( it );
259  }
260  DBG << "--------------- send " << frame_r << endl;
261  }
262 
269  void load( const Pathname & path_r )
270  {
271  PathInfo pi( path_r );
272  DBG << "+++++++++++++++ load " << pi << endl;
273  if ( pi.isDir() )
274  {
275  std::list<Pathname> entries;
276  if ( filesystem::readdir( entries, pi.path(), false ) != 0 )
277  {
278  WAR << "Plugin dir is not readable: " << pi << endl;
279  return;
280  }
281  for_( it, entries.begin(), entries.end() )
282  {
283  PathInfo pii( *it );
284  if ( pii.isFile() && pii.userMayRX() )
285  doLoad( pii );
286  }
287  }
288  else if ( pi.isFile() )
289  {
290  if ( pi.userMayRX() )
291  doLoad( pi );
292  else
293  WAR << "Plugin file is not executable: " << pi << endl;
294  }
295  else
296  {
297  WAR << "Plugin path is neither dir nor file: " << pi << endl;
298  }
299  DBG << "--------------- load " << pi << endl;
300  }
301 
302  private:
308  PluginFrame doSend( PluginScript & script_r, const PluginFrame & frame_r )
309  {
310  PluginFrame ret;
311 
312  try {
313  script_r.send( frame_r );
314  ret = script_r.receive();
315  }
316  catch( const zypp::Exception & e )
317  { ZYPP_CAUGHT(e); }
318 
319  if ( ! ( ret.isAckCommand() || ret.isEnomethodCommand() ) )
320  {
321  WAR << "Bad plugin response from " << script_r << endl;
322  WAR << dump(ret) << endl;
323  script_r.close();
324  }
325 
326  return ret;
327  }
328 
330  void doLoad( const PathInfo & pi_r )
331  {
332  MIL << "Load plugin: " << pi_r << endl;
333  try {
334  PluginScript plugin( pi_r.path() );
335  plugin.open();
336 
337  PluginFrame frame( "PLUGINBEGIN" );
338  if ( ZConfig::instance().hasUserData() )
339  frame.setHeader( "userdata", ZConfig::instance().userData() );
340 
341  doSend( plugin, frame ); // closes on error
342  if ( plugin.isOpen() )
343  _scripts.push_back( plugin );
344  }
345  catch( const zypp::Exception & e )
346  {
347  WAR << "Failed to load plugin " << pi_r << endl;
348  }
349  }
350 
351  private:
352  std::list<PluginScript> _scripts;
353  };
354 
355  void testCommitPlugins( const Pathname & path_r ) // for testing only
356  {
357  USR << "+++++" << endl;
358  {
359  CommitPlugins pl;
360  pl.load( path_r );
361  USR << "=====" << endl;
362  }
363  USR << "-----" << endl;
364  }
365 
367  namespace
368  {
369  inline PluginFrame transactionPluginFrame( const std::string & command_r, ZYppCommitResult::TransactionStepList & steps_r )
370  {
371  return PluginFrame( command_r, json::Object {
372  { "TransactionStepList", steps_r }
373  }.asJSON() );
374  }
375  } // namespace
377 
380  {
381  unsigned toKeep( ZConfig::instance().solver_upgradeTestcasesToKeep() );
382  MIL << "Testcases to keep: " << toKeep << endl;
383  if ( !toKeep )
384  return;
385  Target_Ptr target( getZYpp()->getTarget() );
386  if ( ! target )
387  {
388  WAR << "No Target no Testcase!" << endl;
389  return;
390  }
391 
392  std::string stem( "updateTestcase" );
393  Pathname dir( target->assertRootPrefix("/var/log/") );
394  Pathname next( dir / Date::now().form( stem+"-%Y-%m-%d-%H-%M-%S" ) );
395 
396  {
397  std::list<std::string> content;
398  filesystem::readdir( content, dir, /*dots*/false );
399  std::set<std::string> cases;
400  for_( c, content.begin(), content.end() )
401  {
402  if ( str::startsWith( *c, stem ) )
403  cases.insert( *c );
404  }
405  if ( cases.size() >= toKeep )
406  {
407  unsigned toDel = cases.size() - toKeep + 1; // +1 for the new one
408  for_( c, cases.begin(), cases.end() )
409  {
410  filesystem::recursive_rmdir( dir/(*c) );
411  if ( ! --toDel )
412  break;
413  }
414  }
415  }
416 
417  MIL << "Write new testcase " << next << endl;
418  getZYpp()->resolver()->createSolverTestcase( next.asString(), false/*no solving*/ );
419  }
420 
422  namespace
423  {
424 
435  std::pair<bool,PatchScriptReport::Action> doExecuteScript( const Pathname & root_r,
436  const Pathname & script_r,
438  {
439  MIL << "Execute script " << PathInfo(Pathname::assertprefix( root_r,script_r)) << endl;
440 
441  HistoryLog historylog;
442  historylog.comment(script_r.asString() + _(" executed"), /*timestamp*/true);
443  ExternalProgram prog( script_r.asString(), ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
444 
445  for ( std::string output = prog.receiveLine(); output.length(); output = prog.receiveLine() )
446  {
447  historylog.comment(output);
448  if ( ! report_r->progress( PatchScriptReport::OUTPUT, output ) )
449  {
450  WAR << "User request to abort script " << script_r << endl;
451  prog.kill();
452  // the rest is handled by exit code evaluation
453  // in case the script has meanwhile finished.
454  }
455  }
456 
457  std::pair<bool,PatchScriptReport::Action> ret( std::make_pair( false, PatchScriptReport::ABORT ) );
458 
459  if ( prog.close() != 0 )
460  {
461  ret.second = report_r->problem( prog.execError() );
462  WAR << "ACTION" << ret.second << "(" << prog.execError() << ")" << endl;
463  std::ostringstream sstr;
464  sstr << script_r << _(" execution failed") << " (" << prog.execError() << ")" << endl;
465  historylog.comment(sstr.str(), /*timestamp*/true);
466  return ret;
467  }
468 
469  report_r->finish();
470  ret.first = true;
471  return ret;
472  }
473 
477  bool executeScript( const Pathname & root_r,
478  const Pathname & script_r,
479  callback::SendReport<PatchScriptReport> & report_r )
480  {
481  std::pair<bool,PatchScriptReport::Action> action( std::make_pair( false, PatchScriptReport::ABORT ) );
482 
483  do {
484  action = doExecuteScript( root_r, script_r, report_r );
485  if ( action.first )
486  return true; // success
487 
488  switch ( action.second )
489  {
490  case PatchScriptReport::ABORT:
491  WAR << "User request to abort at script " << script_r << endl;
492  return false; // requested abort.
493  break;
494 
495  case PatchScriptReport::IGNORE:
496  WAR << "User request to skip script " << script_r << endl;
497  return true; // requested skip.
498  break;
499 
500  case PatchScriptReport::RETRY:
501  break; // again
502  }
503  } while ( action.second == PatchScriptReport::RETRY );
504 
505  // THIS is not intended to be reached:
506  INT << "Abort on unknown ACTION request " << action.second << " returned" << endl;
507  return false; // abort.
508  }
509 
515  bool RunUpdateScripts( const Pathname & root_r,
516  const Pathname & scriptsPath_r,
517  const std::vector<sat::Solvable> & checkPackages_r,
518  bool aborting_r )
519  {
520  if ( checkPackages_r.empty() )
521  return true; // no installed packages to check
522 
523  MIL << "Looking for new update scripts in (" << root_r << ")" << scriptsPath_r << endl;
524  Pathname scriptsDir( Pathname::assertprefix( root_r, scriptsPath_r ) );
525  if ( ! PathInfo( scriptsDir ).isDir() )
526  return true; // no script dir
527 
528  std::list<std::string> scripts;
529  filesystem::readdir( scripts, scriptsDir, /*dots*/false );
530  if ( scripts.empty() )
531  return true; // no scripts in script dir
532 
533  // Now collect and execute all matching scripts.
534  // On ABORT: at least log all outstanding scripts.
535  // - "name-version-release"
536  // - "name-version-release-*"
537  bool abort = false;
538  std::map<std::string, Pathname> unify; // scripts <md5,path>
539  for_( it, checkPackages_r.begin(), checkPackages_r.end() )
540  {
541  std::string prefix( str::form( "%s-%s", it->name().c_str(), it->edition().c_str() ) );
542  for_( sit, scripts.begin(), scripts.end() )
543  {
544  if ( ! str::hasPrefix( *sit, prefix ) )
545  continue;
546 
547  if ( (*sit)[prefix.size()] != '\0' && (*sit)[prefix.size()] != '-' )
548  continue; // if not exact match it had to continue with '-'
549 
550  PathInfo script( scriptsDir / *sit );
551  Pathname localPath( scriptsPath_r/(*sit) ); // without root prefix
552  std::string unifytag; // must not stay empty
553 
554  if ( script.isFile() )
555  {
556  // Assert it's set executable, unify by md5sum.
557  filesystem::addmod( script.path(), 0500 );
558  unifytag = filesystem::md5sum( script.path() );
559  }
560  else if ( ! script.isExist() )
561  {
562  // Might be a dangling symlink, might be ok if we are in
563  // instsys (absolute symlink within the system below /mnt).
564  // readlink will tell....
565  unifytag = filesystem::readlink( script.path() ).asString();
566  }
567 
568  if ( unifytag.empty() )
569  continue;
570 
571  // Unify scripts
572  if ( unify[unifytag].empty() )
573  {
574  unify[unifytag] = localPath;
575  }
576  else
577  {
578  // translators: We may find the same script content in files with different names.
579  // Only the first occurence is executed, subsequent ones are skipped. It's a one-line
580  // message for a log file. Preferably start translation with "%s"
581  std::string msg( str::form(_("%s already executed as %s)"), localPath.asString().c_str(), unify[unifytag].c_str() ) );
582  MIL << "Skip update script: " << msg << endl;
583  HistoryLog().comment( msg, /*timestamp*/true );
584  continue;
585  }
586 
587  if ( abort || aborting_r )
588  {
589  WAR << "Aborting: Skip update script " << *sit << endl;
590  HistoryLog().comment(
591  localPath.asString() + _(" execution skipped while aborting"),
592  /*timestamp*/true);
593  }
594  else
595  {
596  MIL << "Found update script " << *sit << endl;
597  callback::SendReport<PatchScriptReport> report;
598  report->start( make<Package>( *it ), script.path() );
599 
600  if ( ! executeScript( root_r, localPath, report ) ) // script path without root prefix!
601  abort = true; // requested abort.
602  }
603  }
604  }
605  return !abort;
606  }
607 
609  //
611 
612  inline void copyTo( std::ostream & out_r, const Pathname & file_r )
613  {
614  std::ifstream infile( file_r.c_str() );
615  for( iostr::EachLine in( infile ); in; in.next() )
616  {
617  out_r << *in << endl;
618  }
619  }
620 
621  inline std::string notificationCmdSubst( const std::string & cmd_r, const UpdateNotificationFile & notification_r )
622  {
623  std::string ret( cmd_r );
624 #define SUBST_IF(PAT,VAL) if ( ret.find( PAT ) != std::string::npos ) ret = str::gsub( ret, PAT, VAL )
625  SUBST_IF( "%p", notification_r.solvable().asString() );
626  SUBST_IF( "%P", notification_r.file().asString() );
627 #undef SUBST_IF
628  return ret;
629  }
630 
631  void sendNotification( const Pathname & root_r,
632  const UpdateNotifications & notifications_r )
633  {
634  if ( notifications_r.empty() )
635  return;
636 
637  std::string cmdspec( ZConfig::instance().updateMessagesNotify() );
638  MIL << "Notification command is '" << cmdspec << "'" << endl;
639  if ( cmdspec.empty() )
640  return;
641 
642  std::string::size_type pos( cmdspec.find( '|' ) );
643  if ( pos == std::string::npos )
644  {
645  ERR << "Can't send Notification: Missing 'format |' in command spec." << endl;
646  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
647  return;
648  }
649 
650  std::string formatStr( str::toLower( str::trim( cmdspec.substr( 0, pos ) ) ) );
651  std::string commandStr( str::trim( cmdspec.substr( pos + 1 ) ) );
652 
653  enum Format { UNKNOWN, NONE, SINGLE, DIGEST, BULK };
654  Format format = UNKNOWN;
655  if ( formatStr == "none" )
656  format = NONE;
657  else if ( formatStr == "single" )
658  format = SINGLE;
659  else if ( formatStr == "digest" )
660  format = DIGEST;
661  else if ( formatStr == "bulk" )
662  format = BULK;
663  else
664  {
665  ERR << "Can't send Notification: Unknown format '" << formatStr << " |' in command spec." << endl;
666  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
667  return;
668  }
669 
670  // Take care: commands are ececuted chroot(root_r). The message file
671  // pathnames in notifications_r are local to root_r. For physical access
672  // to the file they need to be prefixed.
673 
674  if ( format == NONE || format == SINGLE )
675  {
676  for_( it, notifications_r.begin(), notifications_r.end() )
677  {
678  std::vector<std::string> command;
679  if ( format == SINGLE )
680  command.push_back( "<"+Pathname::assertprefix( root_r, it->file() ).asString() );
681  str::splitEscaped( notificationCmdSubst( commandStr, *it ), std::back_inserter( command ) );
682 
683  ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
684  if ( true ) // Wait for feedback
685  {
686  for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
687  {
688  DBG << line;
689  }
690  int ret = prog.close();
691  if ( ret != 0 )
692  {
693  ERR << "Notification command returned with error (" << ret << ")." << endl;
694  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
695  return;
696  }
697  }
698  }
699  }
700  else if ( format == DIGEST || format == BULK )
701  {
702  filesystem::TmpFile tmpfile;
703  ofstream out( tmpfile.path().c_str() );
704  for_( it, notifications_r.begin(), notifications_r.end() )
705  {
706  if ( format == DIGEST )
707  {
708  out << it->file() << endl;
709  }
710  else if ( format == BULK )
711  {
712  copyTo( out << '\f', Pathname::assertprefix( root_r, it->file() ) );
713  }
714  }
715 
716  std::vector<std::string> command;
717  command.push_back( "<"+tmpfile.path().asString() ); // redirect input
718  str::splitEscaped( notificationCmdSubst( commandStr, *notifications_r.begin() ), std::back_inserter( command ) );
719 
720  ExternalProgram prog( command, ExternalProgram::Stderr_To_Stdout, false, -1, true, root_r );
721  if ( true ) // Wait for feedback otherwise the TmpFile goes out of scope.
722  {
723  for( std::string line = prog.receiveLine(); ! line.empty(); line = prog.receiveLine() )
724  {
725  DBG << line;
726  }
727  int ret = prog.close();
728  if ( ret != 0 )
729  {
730  ERR << "Notification command returned with error (" << ret << ")." << endl;
731  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
732  return;
733  }
734  }
735  }
736  else
737  {
738  INT << "Can't send Notification: Missing handler for 'format |' in command spec." << endl;
739  HistoryLog().comment( str::Str() << _("Error sending update message notification."), /*timestamp*/true );
740  return;
741  }
742  }
743 
744 
750  void RunUpdateMessages( const Pathname & root_r,
751  const Pathname & messagesPath_r,
752  const std::vector<sat::Solvable> & checkPackages_r,
753  ZYppCommitResult & result_r )
754  {
755  if ( checkPackages_r.empty() )
756  return; // no installed packages to check
757 
758  MIL << "Looking for new update messages in (" << root_r << ")" << messagesPath_r << endl;
759  Pathname messagesDir( Pathname::assertprefix( root_r, messagesPath_r ) );
760  if ( ! PathInfo( messagesDir ).isDir() )
761  return; // no messages dir
762 
763  std::list<std::string> messages;
764  filesystem::readdir( messages, messagesDir, /*dots*/false );
765  if ( messages.empty() )
766  return; // no messages in message dir
767 
768  // Now collect all matching messages in result and send them
769  // - "name-version-release"
770  // - "name-version-release-*"
771  HistoryLog historylog;
772  for_( it, checkPackages_r.begin(), checkPackages_r.end() )
773  {
774  std::string prefix( str::form( "%s-%s", it->name().c_str(), it->edition().c_str() ) );
775  for_( sit, messages.begin(), messages.end() )
776  {
777  if ( ! str::hasPrefix( *sit, prefix ) )
778  continue;
779 
780  if ( (*sit)[prefix.size()] != '\0' && (*sit)[prefix.size()] != '-' )
781  continue; // if not exact match it had to continue with '-'
782 
783  PathInfo message( messagesDir / *sit );
784  if ( ! message.isFile() || message.size() == 0 )
785  continue;
786 
787  MIL << "Found update message " << *sit << endl;
788  Pathname localPath( messagesPath_r/(*sit) ); // without root prefix
789  result_r.rUpdateMessages().push_back( UpdateNotificationFile( *it, localPath ) );
790  historylog.comment( str::Str() << _("New update message") << " " << localPath, /*timestamp*/true );
791  }
792  }
793  sendNotification( root_r, result_r.updateMessages() );
794  }
795 
797  } // namespace
799 
800  void XRunUpdateMessages( const Pathname & root_r,
801  const Pathname & messagesPath_r,
802  const std::vector<sat::Solvable> & checkPackages_r,
803  ZYppCommitResult & result_r )
804  { RunUpdateMessages( root_r, messagesPath_r, checkPackages_r, result_r ); }
805 
807 
808  IMPL_PTR_TYPE(TargetImpl);
809 
810  TargetImpl_Ptr TargetImpl::_nullimpl;
811 
813  TargetImpl_Ptr TargetImpl::nullimpl()
814  {
815  if (_nullimpl == 0)
816  _nullimpl = new TargetImpl;
817  return _nullimpl;
818  }
819 
821  //
822  // METHOD NAME : TargetImpl::TargetImpl
823  // METHOD TYPE : Ctor
824  //
825  TargetImpl::TargetImpl( const Pathname & root_r, bool doRebuild_r )
826  : _root( root_r )
827  , _requestedLocalesFile( home() / "RequestedLocales" )
828  , _autoInstalledFile( home() / "AutoInstalled" )
829  , _hardLocksFile( Pathname::assertprefix( _root, ZConfig::instance().locksFile() ) )
830  {
831  _rpm.initDatabase( root_r, Pathname(), doRebuild_r );
832 
834 
836 
837  MIL << "Initialized target on " << _root << endl;
838  }
839 
843  static std::string generateRandomId()
844  {
845  std::ifstream uuidprovider( "/proc/sys/kernel/random/uuid" );
846  return iostr::getline( uuidprovider );
847  }
848 
854  void updateFileContent( const Pathname &filename,
855  boost::function<bool ()> condition,
856  boost::function<string ()> value )
857  {
858  string val = value();
859  // if the value is empty, then just dont
860  // do anything, regardless of the condition
861  if ( val.empty() )
862  return;
863 
864  if ( condition() )
865  {
866  MIL << "updating '" << filename << "' content." << endl;
867 
868  // if the file does not exist we need to generate the uuid file
869 
870  std::ofstream filestr;
871  // make sure the path exists
872  filesystem::assert_dir( filename.dirname() );
873  filestr.open( filename.c_str() );
874 
875  if ( filestr.good() )
876  {
877  filestr << val;
878  filestr.close();
879  }
880  else
881  {
882  // FIXME, should we ignore the error?
883  ZYPP_THROW(Exception("Can't openfile '" + filename.asString() + "' for writing"));
884  }
885  }
886  }
887 
889  static bool fileMissing( const Pathname &pathname )
890  {
891  return ! PathInfo(pathname).isExist();
892  }
893 
895  {
896 
897  // create the anonymous unique id
898  // this value is used for statistics
899  Pathname idpath( home() / "AnonymousUniqueId");
900 
901  try
902  {
903  updateFileContent( idpath,
904  boost::bind(fileMissing, idpath),
906  }
907  catch ( const Exception &e )
908  {
909  WAR << "Can't create anonymous id file" << endl;
910  }
911 
912  }
913 
915  {
916  // create the anonymous unique id
917  // this value is used for statistics
918  Pathname flavorpath( home() / "LastDistributionFlavor");
919 
920  // is there a product
922  if ( ! p )
923  {
924  WAR << "No base product, I won't create flavor cache" << endl;
925  return;
926  }
927 
928  string flavor = p->flavor();
929 
930  try
931  {
932 
933  updateFileContent( flavorpath,
934  // only if flavor is not empty
935  functor::Constant<bool>( ! flavor.empty() ),
936  functor::Constant<string>(flavor) );
937  }
938  catch ( const Exception &e )
939  {
940  WAR << "Can't create flavor cache" << endl;
941  return;
942  }
943  }
944 
946  //
947  // METHOD NAME : TargetImpl::~TargetImpl
948  // METHOD TYPE : Dtor
949  //
951  {
953  MIL << "Targets closed" << endl;
954  }
955 
957  //
958  // solv file handling
959  //
961 
963  {
964  return Pathname::assertprefix( _root, ZConfig::instance().repoSolvfilesPath() / sat::Pool::instance().systemRepoAlias() );
965  }
966 
968  {
969  Pathname base = solvfilesPath();
971  }
972 
974  {
975  Pathname base = solvfilesPath();
976  Pathname rpmsolv = base/"solv";
977  Pathname rpmsolvcookie = base/"cookie";
978 
979  bool build_rpm_solv = true;
980  // lets see if the rpm solv cache exists
981 
982  RepoStatus rpmstatus( RepoStatus(_root/"var/lib/rpm/Name") && RepoStatus(_root/"etc/products.d") );
983 
984  bool solvexisted = PathInfo(rpmsolv).isExist();
985  if ( solvexisted )
986  {
987  // see the status of the cache
988  PathInfo cookie( rpmsolvcookie );
989  MIL << "Read cookie: " << cookie << endl;
990  if ( cookie.isExist() )
991  {
992  RepoStatus status = RepoStatus::fromCookieFile(rpmsolvcookie);
993  // now compare it with the rpm database
994  if ( status == rpmstatus )
995  build_rpm_solv = false;
996  MIL << "Read cookie: " << rpmsolvcookie << " says: "
997  << (build_rpm_solv ? "outdated" : "uptodate") << endl;
998  }
999  }
1000 
1001  if ( build_rpm_solv )
1002  {
1003  // if the solvfile dir does not exist yet, we better create it
1004  filesystem::assert_dir( base );
1005 
1006  Pathname oldSolvFile( solvexisted ? rpmsolv : Pathname() ); // to speedup rpmdb2solv
1007 
1009  if ( !tmpsolv )
1010  {
1011  // Can't create temporary solv file, usually due to insufficient permission
1012  // (user query while @System solv needs refresh). If so, try switching
1013  // to a location within zypps temp. space (will be cleaned at application end).
1014 
1015  bool switchingToTmpSolvfile = false;
1016  Exception ex("Failed to cache rpm database.");
1017  ex.remember(str::form("Cannot create temporary file under %s.", base.c_str()));
1018 
1019  if ( ! solvfilesPathIsTemp() )
1020  {
1021  base = getZYpp()->tmpPath() / sat::Pool::instance().systemRepoAlias();
1022  rpmsolv = base/"solv";
1023  rpmsolvcookie = base/"cookie";
1024 
1025  filesystem::assert_dir( base );
1026  tmpsolv = filesystem::TmpFile::makeSibling( rpmsolv );
1027 
1028  if ( tmpsolv )
1029  {
1030  WAR << "Using a temporary solv file at " << base << endl;
1031  switchingToTmpSolvfile = true;
1032  _tmpSolvfilesPath = base;
1033  }
1034  else
1035  {
1036  ex.remember(str::form("Cannot create temporary file under %s.", base.c_str()));
1037  }
1038  }
1039 
1040  if ( ! switchingToTmpSolvfile )
1041  {
1042  ZYPP_THROW(ex);
1043  }
1044  }
1045 
1046  // Take care we unlink the solvfile on exception
1048 
1049  std::ostringstream cmd;
1050  cmd << "rpmdb2solv";
1051  if ( ! _root.empty() )
1052  cmd << " -r '" << _root << "'";
1053  cmd << " -X"; // autogenerate pattern/product/... from -package
1054  cmd << " -A"; // autogenerate application pseudo packages
1055  cmd << " -p '" << Pathname::assertprefix( _root, "/etc/products.d" ) << "'";
1056 
1057  if ( ! oldSolvFile.empty() )
1058  cmd << " '" << oldSolvFile << "'";
1059 
1060  cmd << " > '" << tmpsolv.path() << "'";
1061 
1062  MIL << "Executing: " << cmd.str() << endl;
1064 
1065  cmd << endl;
1066  for ( std::string output( prog.receiveLine() ); output.length(); output = prog.receiveLine() ) {
1067  WAR << " " << output;
1068  cmd << " " << output;
1069  }
1070 
1071  int ret = prog.close();
1072  if ( ret != 0 )
1073  {
1074  Exception ex(str::form("Failed to cache rpm database (%d).", ret));
1075  ex.remember( cmd.str() );
1076  ZYPP_THROW(ex);
1077  }
1078 
1079  ret = filesystem::rename( tmpsolv, rpmsolv );
1080  if ( ret != 0 )
1081  ZYPP_THROW(Exception("Failed to move cache to final destination"));
1082  // if this fails, don't bother throwing exceptions
1083  filesystem::chmod( rpmsolv, 0644 );
1084 
1085  rpmstatus.saveToCookieFile(rpmsolvcookie);
1086 
1087  // We keep it.
1088  guard.resetDispose();
1089  sat::updateSolvFileIndex( rpmsolv ); // content digest for zypper bash completion
1090 
1091  // Finally send notification to plugins
1092  // NOTE: quick hack looking for spacewalk plugin only
1093  {
1094  Pathname script( Pathname::assertprefix( _root, ZConfig::instance().pluginsPath()/"system/spacewalk" ) );
1095  if ( PathInfo( script ).isX() )
1096  try {
1097  PluginScript spacewalk( script );
1098  spacewalk.open();
1099 
1100  PluginFrame notify( "PACKAGESETCHANGED" );
1101  spacewalk.send( notify );
1102 
1103  PluginFrame ret( spacewalk.receive() );
1104  MIL << ret << endl;
1105  if ( ret.command() == "ERROR" )
1106  ret.writeTo( WAR ) << endl;
1107  }
1108  catch ( const Exception & excpt )
1109  {
1110  WAR << excpt.asUserHistory() << endl;
1111  }
1112  }
1113  }
1114  return build_rpm_solv;
1115  }
1116 
1118  {
1119  load( false );
1120  }
1121 
1123  {
1124  Repository system( sat::Pool::instance().findSystemRepo() );
1125  if ( system )
1126  system.eraseFromPool();
1127  }
1128 
1129  void TargetImpl::load( bool force )
1130  {
1131  bool newCache = buildCache();
1132  MIL << "New cache built: " << (newCache?"true":"false") <<
1133  ", force loading: " << (force?"true":"false") << endl;
1134 
1135  // now add the repos to the pool
1136  sat::Pool satpool( sat::Pool::instance() );
1137  Pathname rpmsolv( solvfilesPath() / "solv" );
1138  MIL << "adding " << rpmsolv << " to pool(" << satpool.systemRepoAlias() << ")" << endl;
1139 
1140  // Providing an empty system repo, unload any old content
1141  Repository system( sat::Pool::instance().findSystemRepo() );
1142 
1143  if ( system && ! system.solvablesEmpty() )
1144  {
1145  if ( newCache || force )
1146  {
1147  system.eraseFromPool(); // invalidates system
1148  }
1149  else
1150  {
1151  return; // nothing to do
1152  }
1153  }
1154 
1155  if ( ! system )
1156  {
1157  system = satpool.systemRepo();
1158  }
1159 
1160  try
1161  {
1162  MIL << "adding " << rpmsolv << " to system" << endl;
1163  system.addSolv( rpmsolv );
1164  }
1165  catch ( const Exception & exp )
1166  {
1167  ZYPP_CAUGHT( exp );
1168  MIL << "Try to handle exception by rebuilding the solv-file" << endl;
1169  clearCache();
1170  buildCache();
1171 
1172  system.addSolv( rpmsolv );
1173  }
1175 
1176  // (Re)Load the requested locales et al.
1177  // If the requested locales are empty, we leave the pool untouched
1178  // to avoid undoing changes the application applied. We expect this
1179  // to happen on a bare metal installation only. An already existing
1180  // target should be loaded before its settings are changed.
1181  {
1183  if ( ! requestedLocales.empty() )
1184  {
1186  }
1187  }
1188  {
1189  if ( ! PathInfo( _autoInstalledFile.file() ).isExist() )
1190  {
1191  // Initialize from history, if it does not exist
1192  Pathname historyFile( Pathname::assertprefix( _root, ZConfig::instance().historyLogFile() ) );
1193  if ( PathInfo( historyFile ).isExist() )
1194  {
1195  SolvIdentFile::Data onSystemByUser( getUserInstalledFromHistory( historyFile ) );
1196  SolvIdentFile::Data onSystemByAuto;
1197  for_( it, system.solvablesBegin(), system.solvablesEnd() )
1198  {
1199  IdString ident( (*it).ident() );
1200  if ( onSystemByUser.find( ident ) == onSystemByUser.end() )
1201  onSystemByAuto.insert( ident );
1202  }
1203  _autoInstalledFile.setData( onSystemByAuto );
1204  }
1205  // on the fly removed any obsolete SoftLocks file
1206  filesystem::unlink( home() / "SoftLocks" );
1207  }
1208  // read from AutoInstalled file
1209  sat::StringQueue q;
1210  for ( const auto & idstr : _autoInstalledFile.data() )
1211  q.push( idstr.id() );
1212  satpool.setAutoInstalled( q );
1213  }
1214  if ( ZConfig::instance().apply_locks_file() )
1215  {
1216  const HardLocksFile::Data & hardLocks( _hardLocksFile.data() );
1217  if ( ! hardLocks.empty() )
1218  {
1219  ResPool::instance().setHardLockQueries( hardLocks );
1220  }
1221  }
1222 
1223  // now that the target is loaded, we can cache the flavor
1225 
1226  MIL << "Target loaded: " << system.solvablesSize() << " resolvables" << endl;
1227  }
1228 
1230  //
1231  // COMMIT
1232  //
1235  {
1236  // ----------------------------------------------------------------- //
1237  ZYppCommitPolicy policy_r( policy_rX );
1238 
1239  // Fake outstanding YCP fix: Honour restriction to media 1
1240  // at installation, but install all remaining packages if post-boot.
1241  if ( policy_r.restrictToMedia() > 1 )
1242  policy_r.allMedia();
1243 
1244  if ( policy_r.downloadMode() == DownloadDefault ) {
1245  if ( root() == "/" )
1246  policy_r.downloadMode(DownloadInHeaps);
1247  else
1248  policy_r.downloadMode(DownloadAsNeeded);
1249  }
1250  // DownloadOnly implies dry-run.
1251  else if ( policy_r.downloadMode() == DownloadOnly )
1252  policy_r.dryRun( true );
1253  // ----------------------------------------------------------------- //
1254 
1255  MIL << "TargetImpl::commit(<pool>, " << policy_r << ")" << endl;
1256 
1258  // Compute transaction:
1260  ZYppCommitResult result( root() );
1261  result.rTransaction() = pool_r.resolver().getTransaction();
1262  result.rTransaction().order();
1263  // steps: this is our todo-list
1265  if ( policy_r.restrictToMedia() )
1266  {
1267  // Collect until the 1st package from an unwanted media occurs.
1268  // Further collection could violate install order.
1269  MIL << "Restrict to media number " << policy_r.restrictToMedia() << endl;
1270  for_( it, result.transaction().begin(), result.transaction().end() )
1271  {
1272  if ( makeResObject( *it )->mediaNr() > 1 )
1273  break;
1274  steps.push_back( *it );
1275  }
1276  }
1277  else
1278  {
1279  result.rTransactionStepList().insert( steps.end(), result.transaction().begin(), result.transaction().end() );
1280  }
1281  MIL << "Todo: " << result << endl;
1282 
1284  // Prepare execution of commit plugins:
1286  CommitPlugins commitPlugins;
1287  if ( root() == "/" && ! policy_r.dryRun() )
1288  {
1289  Pathname plugindir( Pathname::assertprefix( _root, ZConfig::instance().pluginsPath()/"commit" ) );
1290  commitPlugins.load( plugindir );
1291  }
1292  if ( ! commitPlugins.empty() )
1293  commitPlugins.send( transactionPluginFrame( "COMMITBEGIN", steps ) );
1294 
1296  // Write out a testcase if we're in dist upgrade mode.
1298  if ( getZYpp()->resolver()->upgradeMode() )
1299  {
1300  if ( ! policy_r.dryRun() )
1301  {
1303  }
1304  else
1305  {
1306  DBG << "dryRun: Not writing upgrade testcase." << endl;
1307  }
1308  }
1309 
1311  // Store non-package data:
1313  if ( ! policy_r.dryRun() )
1314  {
1316  // requested locales
1318  // autoinstalled
1319  {
1320  SolvIdentFile::Data newdata;
1321  for ( sat::Queue::value_type id : result.rTransaction().autoInstalled() )
1322  newdata.insert( IdString(id) );
1323  _autoInstalledFile.setData( newdata );
1324  }
1325  // hard locks
1326  if ( ZConfig::instance().apply_locks_file() )
1327  {
1328  HardLocksFile::Data newdata;
1329  pool_r.getHardLockQueries( newdata );
1330  _hardLocksFile.setData( newdata );
1331  }
1332  }
1333  else
1334  {
1335  DBG << "dryRun: Not stroring non-package data." << endl;
1336  }
1337 
1339  // First collect and display all messages
1340  // associated with patches to be installed.
1342  if ( ! policy_r.dryRun() )
1343  {
1344  for_( it, steps.begin(), steps.end() )
1345  {
1346  if ( ! it->satSolvable().isKind<Patch>() )
1347  continue;
1348 
1349  PoolItem pi( *it );
1350  if ( ! pi.status().isToBeInstalled() )
1351  continue;
1352 
1353  Patch::constPtr patch( asKind<Patch>(pi.resolvable()) );
1354  if ( ! patch ||patch->message().empty() )
1355  continue;
1356 
1357  MIL << "Show message for " << patch << endl;
1359  if ( ! report->show( patch ) )
1360  {
1361  WAR << "commit aborted by the user" << endl;
1362  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1363  }
1364  }
1365  }
1366  else
1367  {
1368  DBG << "dryRun: Not checking patch messages." << endl;
1369  }
1370 
1372  // Remove/install packages.
1374  DBG << "commit log file is set to: " << HistoryLog::fname() << endl;
1375  if ( ! policy_r.dryRun() || policy_r.downloadMode() == DownloadOnly )
1376  {
1377  // Prepare the package cache. Pass all items requiring download.
1378  CommitPackageCache packageCache( root() );
1379  packageCache.setCommitList( steps.begin(), steps.end() );
1380 
1381  bool miss = false;
1382  if ( policy_r.downloadMode() != DownloadAsNeeded )
1383  {
1384  // Preload the cache. Until now this means pre-loading all packages.
1385  // Once DownloadInHeaps is fully implemented, this will change and
1386  // we may actually have more than one heap.
1387  for_( it, steps.begin(), steps.end() )
1388  {
1389  switch ( it->stepType() )
1390  {
1393  // proceed: only install actionas may require download.
1394  break;
1395 
1396  default:
1397  // next: no download for or non-packages and delete actions.
1398  continue;
1399  break;
1400  }
1401 
1402  PoolItem pi( *it );
1403  if ( pi->isKind<Package>() || pi->isKind<SrcPackage>() )
1404  {
1405  ManagedFile localfile;
1406  try
1407  {
1408  // TODO: unify packageCache.get for Package and SrcPackage
1409  if ( pi->isKind<Package>() )
1410  {
1411  localfile = packageCache.get( pi );
1412  }
1413  else if ( pi->isKind<SrcPackage>() )
1414  {
1415  repo::RepoMediaAccess access;
1416  repo::SrcPackageProvider prov( access );
1417  localfile = prov.provideSrcPackage( pi->asKind<SrcPackage>() );
1418  }
1419  else
1420  {
1421  INT << "Don't know howto cache: Neither Package nor SrcPackage: " << pi << endl;
1422  continue;
1423  }
1424  localfile.resetDispose(); // keep the package file in the cache
1425  }
1426  catch ( const AbortRequestException & exp )
1427  {
1428  it->stepStage( sat::Transaction::STEP_ERROR );
1429  miss = true;
1430  WAR << "commit cache preload aborted by the user" << endl;
1431  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1432  break;
1433  }
1434  catch ( const SkipRequestException & exp )
1435  {
1436  ZYPP_CAUGHT( exp );
1437  it->stepStage( sat::Transaction::STEP_ERROR );
1438  miss = true;
1439  WAR << "Skipping cache preload package " << pi->asKind<Package>() << " in commit" << endl;
1440  continue;
1441  }
1442  catch ( const Exception & exp )
1443  {
1444  // bnc #395704: missing catch causes abort.
1445  // TODO see if packageCache fails to handle errors correctly.
1446  ZYPP_CAUGHT( exp );
1447  it->stepStage( sat::Transaction::STEP_ERROR );
1448  miss = true;
1449  INT << "Unexpected Error: Skipping cache preload package " << pi->asKind<Package>() << " in commit" << endl;
1450  continue;
1451  }
1452  }
1453  }
1454  packageCache.preloaded( true ); // try to avoid duplicate infoInCache CBs in commit
1455  }
1456 
1457  if ( miss )
1458  {
1459  ERR << "Some packages could not be provided. Aborting commit."<< endl;
1460  }
1461  else
1462  {
1463  if ( ! policy_r.dryRun() )
1464  {
1465  // if cache is preloaded, check for file conflicts
1466  commitFindFileConflicts( policy_r, result );
1467  commit( policy_r, packageCache, result );
1468  }
1469  else
1470  {
1471  DBG << "dryRun/downloadOnly: Not installing/deleting anything." << endl;
1472  }
1473  }
1474  }
1475  else
1476  {
1477  DBG << "dryRun: Not downloading/installing/deleting anything." << endl;
1478  }
1479 
1481  // Send result to commit plugins:
1483  if ( ! commitPlugins.empty() )
1484  commitPlugins.send( transactionPluginFrame( "COMMITEND", steps ) );
1485 
1487  // Try to rebuild solv file while rpm database is still in cache
1489  if ( ! policy_r.dryRun() )
1490  {
1491  buildCache();
1492  }
1493 
1494  MIL << "TargetImpl::commit(<pool>, " << policy_r << ") returns: " << result << endl;
1495  return result;
1496  }
1497 
1499  //
1500  // COMMIT internal
1501  //
1503  void TargetImpl::commit( const ZYppCommitPolicy & policy_r,
1504  CommitPackageCache & packageCache_r,
1505  ZYppCommitResult & result_r )
1506  {
1507  // steps: this is our todo-list
1509  MIL << "TargetImpl::commit(<list>" << policy_r << ")" << steps.size() << endl;
1510 
1511  bool abort = false;
1512  RpmPostTransCollector postTransCollector( _root );
1513  std::vector<sat::Solvable> successfullyInstalledPackages;
1514  TargetImpl::PoolItemList remaining;
1515 
1516  for_( step, steps.begin(), steps.end() )
1517  {
1518  PoolItem citem( *step );
1519  if ( step->stepType() == sat::Transaction::TRANSACTION_IGNORE )
1520  {
1521  if ( citem->isKind<Package>() )
1522  {
1523  // for packages this means being obsoleted (by rpm)
1524  // thius no additional action is needed.
1525  step->stepStage( sat::Transaction::STEP_DONE );
1526  continue;
1527  }
1528  }
1529 
1530  if ( citem->isKind<Package>() )
1531  {
1532  Package::constPtr p = citem->asKind<Package>();
1533  if ( citem.status().isToBeInstalled() )
1534  {
1535  ManagedFile localfile;
1536  try
1537  {
1538  localfile = packageCache_r.get( citem );
1539  }
1540  catch ( const AbortRequestException &e )
1541  {
1542  WAR << "commit aborted by the user" << endl;
1543  abort = true;
1544  step->stepStage( sat::Transaction::STEP_ERROR );
1545  break;
1546  }
1547  catch ( const SkipRequestException &e )
1548  {
1549  ZYPP_CAUGHT( e );
1550  WAR << "Skipping package " << p << " in commit" << endl;
1551  step->stepStage( sat::Transaction::STEP_ERROR );
1552  continue;
1553  }
1554  catch ( const Exception &e )
1555  {
1556  // bnc #395704: missing catch causes abort.
1557  // TODO see if packageCache fails to handle errors correctly.
1558  ZYPP_CAUGHT( e );
1559  INT << "Unexpected Error: Skipping package " << p << " in commit" << endl;
1560  step->stepStage( sat::Transaction::STEP_ERROR );
1561  continue;
1562  }
1563 
1564 #warning Exception handling
1565  // create a installation progress report proxy
1566  RpmInstallPackageReceiver progress( citem.resolvable() );
1567  progress.connect(); // disconnected on destruction.
1568 
1569  bool success = false;
1570  rpm::RpmInstFlags flags( policy_r.rpmInstFlags() & rpm::RPMINST_JUSTDB );
1571  // Why force and nodeps?
1572  //
1573  // Because zypp builds the transaction and the resolver asserts that
1574  // everything is fine.
1575  // We use rpm just to unpack and register the package in the database.
1576  // We do this step by step, so rpm is not aware of the bigger context.
1577  // So we turn off rpms internal checks, because we do it inside zypp.
1578  flags |= rpm::RPMINST_NODEPS;
1579  flags |= rpm::RPMINST_FORCE;
1580  //
1581  if (p->multiversionInstall()) flags |= rpm::RPMINST_NOUPGRADE;
1582  if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
1583  if (policy_r.rpmExcludeDocs()) flags |= rpm::RPMINST_EXCLUDEDOCS;
1584  if (policy_r.rpmNoSignature()) flags |= rpm::RPMINST_NOSIGNATURE;
1585 
1586  try
1587  {
1589  if ( postTransCollector.collectScriptFromPackage( localfile ) )
1590  flags |= rpm::RPMINST_NOPOSTTRANS;
1591  rpm().installPackage( localfile, flags );
1592  HistoryLog().install(citem);
1593 
1594  if ( progress.aborted() )
1595  {
1596  WAR << "commit aborted by the user" << endl;
1597  localfile.resetDispose(); // keep the package file in the cache
1598  abort = true;
1599  step->stepStage( sat::Transaction::STEP_ERROR );
1600  break;
1601  }
1602  else
1603  {
1604  success = true;
1605  step->stepStage( sat::Transaction::STEP_DONE );
1606  }
1607  }
1608  catch ( Exception & excpt_r )
1609  {
1610  ZYPP_CAUGHT(excpt_r);
1611  localfile.resetDispose(); // keep the package file in the cache
1612 
1613  if ( policy_r.dryRun() )
1614  {
1615  WAR << "dry run failed" << endl;
1616  step->stepStage( sat::Transaction::STEP_ERROR );
1617  break;
1618  }
1619  // else
1620  if ( progress.aborted() )
1621  {
1622  WAR << "commit aborted by the user" << endl;
1623  abort = true;
1624  }
1625  else
1626  {
1627  WAR << "Install failed" << endl;
1628  }
1629  step->stepStage( sat::Transaction::STEP_ERROR );
1630  break; // stop
1631  }
1632 
1633  if ( success && !policy_r.dryRun() )
1634  {
1636  successfullyInstalledPackages.push_back( citem.satSolvable() );
1637  step->stepStage( sat::Transaction::STEP_DONE );
1638  }
1639  }
1640  else
1641  {
1642  RpmRemovePackageReceiver progress( citem.resolvable() );
1643  progress.connect(); // disconnected on destruction.
1644 
1645  bool success = false;
1646  rpm::RpmInstFlags flags( policy_r.rpmInstFlags() & rpm::RPMINST_JUSTDB );
1647  flags |= rpm::RPMINST_NODEPS;
1648  if (policy_r.dryRun()) flags |= rpm::RPMINST_TEST;
1649  try
1650  {
1651  rpm().removePackage( p, flags );
1652  HistoryLog().remove(citem);
1653 
1654  if ( progress.aborted() )
1655  {
1656  WAR << "commit aborted by the user" << endl;
1657  abort = true;
1658  step->stepStage( sat::Transaction::STEP_ERROR );
1659  break;
1660  }
1661  else
1662  {
1663  success = true;
1664  step->stepStage( sat::Transaction::STEP_DONE );
1665  }
1666  }
1667  catch (Exception & excpt_r)
1668  {
1669  ZYPP_CAUGHT( excpt_r );
1670  if ( progress.aborted() )
1671  {
1672  WAR << "commit aborted by the user" << endl;
1673  abort = true;
1674  step->stepStage( sat::Transaction::STEP_ERROR );
1675  break;
1676  }
1677  // else
1678  WAR << "removal of " << p << " failed";
1679  step->stepStage( sat::Transaction::STEP_ERROR );
1680  }
1681  if ( success && !policy_r.dryRun() )
1682  {
1684  step->stepStage( sat::Transaction::STEP_DONE );
1685  }
1686  }
1687  }
1688  else if ( ! policy_r.dryRun() ) // other resolvables (non-Package)
1689  {
1690  // Status is changed as the buddy package buddy
1691  // gets installed/deleted. Handle non-buddies only.
1692  if ( ! citem.buddy() )
1693  {
1694  if ( citem->isKind<Product>() )
1695  {
1696  Product::constPtr p = citem->asKind<Product>();
1697  if ( citem.status().isToBeInstalled() )
1698  {
1699  ERR << "Can't install orphan product without release-package! " << citem << endl;
1700  }
1701  else
1702  {
1703  // Deleting the corresponding product entry is all we con do.
1704  // So the product will no longer be visible as installed.
1705  std::string referenceFilename( p->referenceFilename() );
1706  if ( referenceFilename.empty() )
1707  {
1708  ERR << "Can't remove orphan product without 'referenceFilename'! " << citem << endl;
1709  }
1710  else
1711  {
1712  PathInfo referenceFile( Pathname::assertprefix( _root, Pathname( "/etc/products.d" ) ) / referenceFilename );
1713  if ( ! referenceFile.isFile() || filesystem::unlink( referenceFile.path() ) != 0 )
1714  {
1715  ERR << "Delete orphan product failed: " << referenceFile << endl;
1716  }
1717  }
1718  }
1719  }
1720  else if ( citem->isKind<SrcPackage>() && citem.status().isToBeInstalled() )
1721  {
1722  // SrcPackage is install-only
1723  SrcPackage::constPtr p = citem->asKind<SrcPackage>();
1724  installSrcPackage( p );
1725  }
1726 
1728  step->stepStage( sat::Transaction::STEP_DONE );
1729  }
1730 
1731  } // other resolvables
1732 
1733  } // for
1734 
1735  // process all remembered posttrans scripts.
1736  if ( !abort )
1737  postTransCollector.executeScripts();
1738  else
1739  postTransCollector.discardScripts();
1740 
1741  // Check presence of update scripts/messages. If aborting,
1742  // at least log omitted scripts.
1743  if ( ! successfullyInstalledPackages.empty() )
1744  {
1745  if ( ! RunUpdateScripts( _root, ZConfig::instance().update_scriptsPath(),
1746  successfullyInstalledPackages, abort ) )
1747  {
1748  WAR << "Commit aborted by the user" << endl;
1749  abort = true;
1750  }
1751  // send messages after scripts in case some script generates output,
1752  // that should be kept in t %ghost message file.
1753  RunUpdateMessages( _root, ZConfig::instance().update_messagesPath(),
1754  successfullyInstalledPackages,
1755  result_r );
1756  }
1757 
1758  if ( abort )
1759  {
1760  ZYPP_THROW( TargetAbortedException( N_("Installation has been aborted as directed.") ) );
1761  }
1762  }
1763 
1765 
1767  {
1768  return _rpm;
1769  }
1770 
1771  bool TargetImpl::providesFile (const std::string & path_str, const std::string & name_str) const
1772  {
1773  return _rpm.hasFile(path_str, name_str);
1774  }
1775 
1776 
1778  {
1779  return _rpm.timestamp();
1780  }
1781 
1783  namespace
1784  {
1785  parser::ProductFileData baseproductdata( const Pathname & root_r )
1786  {
1788  PathInfo baseproduct( Pathname::assertprefix( root_r, "/etc/products.d/baseproduct" ) );
1789 
1790  if ( baseproduct.isFile() )
1791  {
1792  try
1793  {
1794  ret = parser::ProductFileReader::scanFile( baseproduct.path() );
1795  }
1796  catch ( const Exception & excpt )
1797  {
1798  ZYPP_CAUGHT( excpt );
1799  }
1800  }
1801  else if ( PathInfo( Pathname::assertprefix( root_r, "/etc/products.d" ) ).isDir() )
1802  {
1803  ERR << "baseproduct symlink is dangling or missing: " << baseproduct << endl;
1804  }
1805  return ret;
1806  }
1807 
1808  inline Pathname staticGuessRoot( const Pathname & root_r )
1809  {
1810  if ( root_r.empty() )
1811  {
1812  // empty root: use existing Target or assume "/"
1813  Pathname ret ( ZConfig::instance().systemRoot() );
1814  if ( ret.empty() )
1815  return Pathname("/");
1816  return ret;
1817  }
1818  return root_r;
1819  }
1820 
1821  inline std::string firstNonEmptyLineIn( const Pathname & file_r )
1822  {
1823  std::ifstream idfile( file_r.c_str() );
1824  for( iostr::EachLine in( idfile ); in; in.next() )
1825  {
1826  std::string line( str::trim( *in ) );
1827  if ( ! line.empty() )
1828  return line;
1829  }
1830  return std::string();
1831  }
1832  } // namescpace
1834 
1836  {
1837  ResPool pool(ResPool::instance());
1838  for_( it, pool.byKindBegin<Product>(), pool.byKindEnd<Product>() )
1839  {
1840  Product::constPtr p = (*it)->asKind<Product>();
1841  if ( p->isTargetDistribution() )
1842  return p;
1843  }
1844  return nullptr;
1845  }
1846 
1847  LocaleSet TargetImpl::requestedLocales( const Pathname & root_r )
1848  {
1849  const Pathname needroot( staticGuessRoot(root_r) );
1850  const Target_constPtr target( getZYpp()->getTarget() );
1851  if ( target && target->root() == needroot )
1852  return target->requestedLocales();
1853  return RequestedLocalesFile( home(needroot) / "RequestedLocales" ).locales();
1854  }
1855 
1857  { return baseproductdata( _root ).registerTarget(); }
1858  // static version:
1859  std::string TargetImpl::targetDistribution( const Pathname & root_r )
1860  { return baseproductdata( staticGuessRoot(root_r) ).registerTarget(); }
1861 
1863  { return baseproductdata( _root ).registerRelease(); }
1864  // static version:
1865  std::string TargetImpl::targetDistributionRelease( const Pathname & root_r )
1866  { return baseproductdata( staticGuessRoot(root_r) ).registerRelease();}
1867 
1869  { return baseproductdata( _root ).registerFlavor(); }
1870  // static version:
1871  std::string TargetImpl::targetDistributionFlavor( const Pathname & root_r )
1872  { return baseproductdata( staticGuessRoot(root_r) ).registerFlavor();}
1873 
1875  {
1877  parser::ProductFileData pdata( baseproductdata( _root ) );
1878  ret.shortName = pdata.shortName();
1879  ret.summary = pdata.summary();
1880  return ret;
1881  }
1882  // static version:
1884  {
1886  parser::ProductFileData pdata( baseproductdata( staticGuessRoot(root_r) ) );
1887  ret.shortName = pdata.shortName();
1888  ret.summary = pdata.summary();
1889  return ret;
1890  }
1891 
1893  {
1894  if ( _distributionVersion.empty() )
1895  {
1897  if ( !_distributionVersion.empty() )
1898  MIL << "Remember distributionVersion = '" << _distributionVersion << "'" << endl;
1899  }
1900  return _distributionVersion;
1901  }
1902  // static version
1903  std::string TargetImpl::distributionVersion( const Pathname & root_r )
1904  {
1905  std::string distributionVersion = baseproductdata( staticGuessRoot(root_r) ).edition().version();
1906  if ( distributionVersion.empty() )
1907  {
1908  // ...But the baseproduct method is not expected to work on RedHat derivatives.
1909  // On RHEL, Fedora and others the "product version" is determined by the first package
1910  // providing 'redhat-release'. This value is not hardcoded in YUM and can be configured
1911  // with the $distroverpkg variable.
1912  scoped_ptr<rpm::RpmDb> tmprpmdb;
1913  if ( ZConfig::instance().systemRoot() == Pathname() )
1914  {
1915  try
1916  {
1917  tmprpmdb.reset( new rpm::RpmDb );
1918  tmprpmdb->initDatabase( /*default ctor uses / but no additional keyring exports */ );
1919  }
1920  catch( ... )
1921  {
1922  return "";
1923  }
1924  }
1927  distributionVersion = it->tag_version();
1928  }
1929  return distributionVersion;
1930  }
1931 
1932 
1934  {
1935  return firstNonEmptyLineIn( home() / "LastDistributionFlavor" );
1936  }
1937  // static version:
1938  std::string TargetImpl::distributionFlavor( const Pathname & root_r )
1939  {
1940  return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/LastDistributionFlavor" );
1941  }
1942 
1944 
1945  std::string TargetImpl::anonymousUniqueId() const
1946  {
1947  return firstNonEmptyLineIn( home() / "AnonymousUniqueId" );
1948  }
1949  // static version:
1950  std::string TargetImpl::anonymousUniqueId( const Pathname & root_r )
1951  {
1952  return firstNonEmptyLineIn( staticGuessRoot(root_r) / "/var/lib/zypp/AnonymousUniqueId" );
1953  }
1954 
1956 
1957  void TargetImpl::installSrcPackage( const SrcPackage_constPtr & srcPackage_r )
1958  {
1959  // provide on local disk
1960  ManagedFile localfile = provideSrcPackage(srcPackage_r);
1961  // install it
1962  rpm().installPackage ( localfile );
1963  }
1964 
1965  ManagedFile TargetImpl::provideSrcPackage( const SrcPackage_constPtr & srcPackage_r )
1966  {
1967  // provide on local disk
1968  repo::RepoMediaAccess access_r;
1969  repo::SrcPackageProvider prov( access_r );
1970  return prov.provideSrcPackage( srcPackage_r );
1971  }
1973  } // namespace target
1976 } // 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:889
ZYppCommitResult commit(ResPool pool_r, const ZYppCommitPolicy &policy_r)
Commit changes in the pool.
Definition: TargetImpl.cc:1234
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
Definition: PathInfo.cc:324
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:64
CommitPlugins()
Default ctor: Empty plugin list.
Definition: TargetImpl.cc:230
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:215
Target::DistributionLabel distributionLabel() const
This is version attribute of the installed base product.
Definition: TargetImpl.cc:1874
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:679
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:461
std::string md5sum(const Pathname &file)
Compute a files md5sum.
Definition: PathInfo.cc:957
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:988
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:857
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:854
std::string release() const
Release.
Definition: Edition.cc:110
Target::commit helper optimizing package provision.
bool isEnomethodCommand() const
Convenience to identify an _ENOMETHOD command.
Definition: PluginFrame.h:114
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:68
int chmod(const Pathname &path, mode_t mode)
Like 'chmod'.
Definition: PathInfo.cc:1025
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1894
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.
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:243
SolvableIterator solvablesEnd() const
Iterator behind the last Solvable.
Definition: Repository.cc:241
void load(const Pathname &path_r)
Find and launch plugins sending PLUGINSTART message.
Definition: TargetImpl.cc:269
Definition: Arch.h:330
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:379
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:1957
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:66
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:532
std::string distributionVersion() const
This is version attribute of the installed base product.
Definition: TargetImpl.cc:1892
JSON object.
Definition: Json.h:321
PluginFrame doSend(PluginScript &script_r, const PluginFrame &frame_r)
Send PluginFrame and expect valid answer (ACK|_ENOMETHOD).
Definition: TargetImpl.cc:308
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:157
Date timestamp() const
return the last modification date of the target
Definition: TargetImpl.cc:1777
[ ] 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:280
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
Definition: PathInfo.cc:1034
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
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
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
~CommitPlugins()
Dtor: Send PLUGINEND message and close plugins.
Definition: TargetImpl.cc:234
Pathname defaultSolvfilesPath() const
The systems default solv file location.
Definition: TargetImpl.cc:962
bool empty() const
Whether no plugins are waiting.
Definition: TargetImpl.cc:242
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:663
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:147
int rename(const Pathname &oldpath, const Pathname &newpath)
Like 'rename'.
Definition: PathInfo.cc:677
Just download all packages to the local cache.
Definition: DownloadMode.h:25
Options and policies for ZYpp::commit.
void send(const PluginFrame &frame_r)
Send PluginFrame to all open plugins.
Definition: TargetImpl.cc:249
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:1771
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
#define USR
Definition: Logger.h:69
int recursive_rmdir(const Pathname &path)
Like 'rm -r DIR'.
Definition: PathInfo.cc:417
Interim helper class to collect global options and settings.
Definition: ZConfig.h:59
#define WAR
Definition: Logger.h:65
bool isAckCommand() const
Convenience to identify an ACK command.
Definition: PluginFrame.h:106
void createLastDistributionFlavorCache() const
generates a cache of the last product flavor
Definition: TargetImpl.cc:914
std::string targetDistributionFlavor() const
This is register.flavor attribute of the installed base product.
Definition: TargetImpl.cc:1868
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition: String.h:1016
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:64
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:241
const LocaleSet & getRequestedLocales() const
Return the requested locales.
Definition: ResPool.cc:125
bool order()
Order transaction steps for commit.
Definition: Transaction.cc:327
void updateSolvFileIndex(const Pathname &solvfile_r)
Create solv file content digest for zypper bash completion.
Definition: Pool.cc:262
void open()
Setup connection and execute script.
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:731
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:1945
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
PluginFrame receive() const
Receive a PluginFrame.
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:843
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
void testCommitPlugins(const Pathname &path_r)
Definition: TargetImpl.cc:355
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:1856
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:599
void doLoad(const PathInfo &pi_r)
Launch a plugin sending PLUGINSTART message.
Definition: TargetImpl.cc:330
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:1933
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:247
Global ResObject pool.
Definition: ResPool.h:48
Pathname systemRoot() const
The target root directory.
Definition: ZConfig.cc:704
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
int close()
Close any open connection.
Base class for Exception.
Definition: Exception.h:143
Resolver & resolver() const
The Resolver.
Definition: ResPool.cc:57
bool isToBeInstalled() const
Definition: ResStatus.h:241
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:1835
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:178
void initDatabase(Pathname root_r=Pathname(), Pathname dbPath_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database.
Definition: RpmDb.cc:333
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:2083
virtual ~TargetImpl()
Dtor.
Definition: TargetImpl.cc:950
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:1304
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
Definition: HistoryLog.cc:156
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Definition: Exception.cc:75
detail::Dump< _Tp > dump(const _Tp &obj_r)
Definition: LogTools.h:384
TraitsType::constPtrType constPtr
Definition: SrcPackage.h:36
Date timestamp() const
timestamp of the rpm database (last modification)
Definition: RpmDb.cc:279
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:122
Helper for commit plugin execution.
Definition: TargetImpl.cc:226
sat::Transaction & rTransaction()
Manipulate transaction.
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurences of key_r.
Definition: PluginFrame.cc:319
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
void executeScripts()
Execute te remembered scripts.
ManagedFile provideSrcPackage(const SrcPackage_constPtr &srcPackage_r)
Provides a source package on the Target.
Definition: TargetImpl.cc:1965
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:800
Interface to pluigin scripts using a Stomp inspired communication protocol.
Definition: PluginScript.h:62
std::string targetDistributionRelease() const
This is register.release attribute of the installed base product.
Definition: TargetImpl.cc:1862
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
std::string asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:160
#define idstr(V)
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:986
void createAnonymousId() const
generates the unique anonymous id which is called when creating the target
Definition: TargetImpl.cc:894
void send(const PluginFrame &frame_r) const
Send a PluginFrame.
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
rpm::RpmDb & rpm()
The RPM database.
Definition: TargetImpl.cc:1766
TraitsType::constPtrType constPtr
Definition: Package.h:38
#define IMPL_PTR_TYPE(NAME)
#define DBG
Definition: Logger.h:63
bool preloaded() const
Whether preloaded hint is set.
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33
std::list< PluginScript > _scripts
Definition: TargetImpl.cc:352
void load(bool force=true)
Definition: TargetImpl.cc:1129