13 #include <zypp/base/LogTools.h> 14 #include <zypp/base/NonCopyable.h> 15 #include <zypp/base/Gettext.h> 18 #include <zypp/TmpPath.h> 19 #include <zypp/PathInfo.h> 22 #include <zypp/ExternalProgram.h> 29 #undef ZYPP_BASE_LOGGER_LOGGROUP 30 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::posttrans" 46 friend std::ostream &
dumpOn( std::ostream &
str,
const Impl & obj );
62 WAR <<
"Unexpectedly this is no package: " << rpmPackage_r << endl;
66 std::string prog( pkg->tag_posttransprog() );
67 if ( prog.empty() || prog ==
"<lua>" )
72 script.autoCleanup(
false );
74 std::ofstream out( script.path().c_str() );
75 out <<
"#! " << pkg->tag_posttransprog() << endl
76 << pkg->tag_posttrans() << endl;
78 _scripts.push_back( std::make_pair( script.path().basename(), pkg->tag_name() ) );
79 MIL <<
"COLLECT posttrans: '" <<
PathInfo( script.path() ) <<
"' for package: '" << pkg->tag_name() <<
"'" << endl;
98 str::Format fmtScriptProgress {
_(
"Executing %%posttrans script '%1%'") };
100 bool firstScript =
true;
101 str::Format fmtScriptFailedMsg {
"warning: %%posttrans(%1%) scriptlet failed, exit status %2%\n" };
104 const auto &scriptPair =
_scripts.front();
105 const std::string & script = scriptPair.first;
106 const std::string & pkgident( script.substr( 0, script.size()-6 ) );
108 scriptProgress.
name( fmtScriptProgress % pkgident );
110 bool canContinue =
true;
113 canContinue = scriptProgress.
toMin();
115 canContinue = scriptProgress.
incr();
120 msg <<
"Execution of %posttrans scripts cancelled";
122 historylog.
comment( msg,
true );
129 for ( it.
findByName( scriptPair.second ); *it; ++it )
132 MIL <<
"EXECUTE posttrans: " << script <<
" with argument: " << npkgs << endl;
135 (noRootScriptDir/script).
asString(),
153 int ret = prog.
close();
156 const std::string & msg { fmtScriptFailedMsg % pkgident % ret };
162 const std::string & scriptmsg( collect );
163 if ( ! scriptmsg.empty() )
166 msg <<
"Output of " << pkgident <<
" %posttrans script:\n" << scriptmsg;
167 historylog.
comment( msg,
true );
172 scriptProgress.
name(
_(
"Executing %posttrans scripts") );
173 scriptProgress.
toMax();
187 msg <<
"%posttrans scripts skipped while aborting:\n";
188 for (
const auto & script :
_scripts )
190 const std::string & pkgident( script.first.substr( 0, script.first.size()-6 ) );
191 WAR <<
"UNEXECUTED posttrans: " << script.first << endl;
192 msg <<
" " << pkgident <<
"\n";
195 historylog.
comment( msg,
true );
213 std::list< std::pair< std::string, std::string > >
_scripts;
221 {
return str <<
"RpmPostTransCollector::Impl"; }
225 {
return str << obj; }
234 : _pimpl( new
Impl( root_r ) )
std::string asString(const Patch::Category &obj)
JobReport convenience sending this instance of UserData with each message.
std::list< std::pair< std::string, std::string > > _scripts
void sendTo(const ReceiverFnc &fnc_r)
Set ReceiverFnc.
static ZConfig & instance()
Singleton ctor.
bool warning(const std::string &msg_r)
void discardScripts()
Discard all remembered scrips.
friend std::ostream & dumpOn(std::ostream &str, const Impl &obj)
String related utilities and Regular expression matching.
bool toMax()
Set counter value to current max value (unless no range).
Impl(const Pathname &root_r)
std::string receiveLine()
Read one line from the input stream.
std::ostream & dumpOn(std::ostream &str, const RpmPostTransCollector::Impl &obj)
Provide a new empty temporary file and delete it when no longer needed.
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
RW_pointer< Impl > _pimpl
Implementation class.
std::vector< std::string > Arguments
RpmPostTransCollector(const Pathname &root_r)
Default ctor.
Extract and remember posttrans scripts for later execution.
Subclass to retrieve database content.
bool info(const std::string &msg_r)
Pathname tmpDir()
Lazy create tmpdir on demand.
int addmod(const Pathname &path, mode_t mode)
Add the mode bits to the file given by path.
bool toMin()
Set counter value to current min value.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Provide a new empty temporary directory and recursively delete it when no longer needed.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
bool collectScriptFromPackage(ManagedFile rpmPackage_r)
Extract and remember a packages posttrans script for later execution.
bool executeScripts()
Execute the remembered scripts.
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
RpmPostTransCollector implementation.
Maintain [min,max] and counter (value) for progress counting.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
boost::scoped_ptr< filesystem::TmpDir > _ptrTmpdir
Writing the zypp history fileReference counted signleton for writhing the zypp history file...
bool incr(value_type val_r=1)
Increment counter value (default by 1).
std::string numstring(char n, int w=0)
std::ostream & dumpOn(std::ostream &str, const RpmPostTransCollector &obj)
int close()
Wait for the progamm to complete.
bool collectScriptFromPackage(ManagedFile rpmPackage_r)
Extract and remember a packages posttrans script for later execution.
void discardScripts()
Discard all remembered scrips.
~RpmPostTransCollector()
Dtor.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void comment(const std::string &comment, bool timestamp=false)
Log a comment (even multiline).
Wrapper class for ::stat/::lstat.
bool executeScripts()
Execute the remembered scripts.
void name(const std::string &name_r)
Set counter name.
Easy-to use interface to the ZYPP dependency resolver.
friend std::ostream & operator<<(std::ostream &str, const Impl &obj)
UserDataJobReport _myJobReport
JobReport with ContentType "cmdout/%posttrans".
std::ostream & operator<<(std::ostream &str, const RpmPostTransCollector::Impl &obj)