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