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