36 using Callback = std::function<bool(std::optional<std::string>)>;
39 : _timeout { timeout_r }
50 line += readResult.second;
52 switch ( readResult.first ) {
55 goOn = reportLine( line, cb_r );
60 goOn = reportTimeout( cb_r );
65 reportFinalLineUnlessEmpty( line, cb_r );
73 WAR <<
"ABORT by callback: pid " << prog_r.
getpid() << endl;
76 return prog_r.
close();
83 if ( not line_r.empty() && line_r.back() ==
'\n' )
85 return cb_r( std::move(line_r) );
91 return cb_r ? cb_r( std::nullopt ) :
true;
95 if ( cb_r && not line_r.empty() )
96 cb_r( std::move(line_r) );
111 Pathname &&sigpathLocal_r, Pathname &&keypathLocal_r,
RepoInfo &&repo_r )
112 : _parent { std::move( parent_r ) }
113 , _sigpathLocal { std::move(sigpathLocal_r) }
114 , _keypathLocal { std::move(keypathLocal_r) }
115 , _repoinfo { std::move(repo_r) }
131 friend std::ostream &
dumpOn( std::ostream &
str,
const Impl & obj );
139 Impl &operator=(
const Impl &) =
delete;
144 _chroot{std::move(chroot_r)} {}
150 {
return _isNeeded; }
154 if ( _watchPlugindir.hasChanged() ) {
158 [
this](
const Pathname & dir_r,
const char *
const name_r ) ->
bool {
161 this->_isNeeded =
true;
174 [&,
this](
const Pathname & dir_r,
const char *
const name_r ) ->
bool {
177 this->pluginVerify( name_r, file_r, *datap_r );
185 Pathname pluginPath { plugindir()/plugin_r };
186 if ( not _chroot.emptyOrRoot() ) {
189 INT <<
"chroot PluginRepoverification does not yet work." << endl;
194 args.push_back( pluginPath.asString() );
196 args.push_back(
"--file" );
197 args.push_back( file_r.
asString() );
198 args.push_back(
"--fsig" );
200 args.push_back(
"--fkey" );
202 args.push_back(
"--ralias" );
209 jobReport.
set(
"CmdId",
unsigned(cmd.getpid()) );
211 jobReport.set(
"CmdName",
"Repoverification plugin "+plugin_r );
212 jobReport.set(
"RepoInfo", data_r.
_repoinfo );
214 std::optional<std::ostringstream> buffer;
215 jobReport.debug(
"?" );
216 if ( not jobReport.haskey(
"!" ) )
217 buffer = std::ostringstream();
219 int ret = monitor( cmd, [&jobReport,&buffer,&cmd]( std::optional<std::string> line_r )->
bool {
221 DBG <<
"["<<cmd.getpid()<<
"> " << *line_r << endl;
222 if ( buffer ) (*buffer) << *line_r << endl;
223 return jobReport.data( *line_r );
226 return jobReport.debug(
"ping" );
232 const std::string & msg {
str::Format(
"Metadata rejected by '%1%' plugin (returned %2%)" ) % plugin_r % ret };
235 if ( buffer ) excp.
addHistory( buffer->str() );
236 excp.addHistory(
str::Format(
"%1%%2% returned %3%" ) % (_chroot.emptyOrRoot()?
"":
"("+_chroot.asString()+
")") % pluginPath % ret );
243 {
return _watchPlugindir.path(); }
248 bool _isNeeded =
false;
253 {
return str <<
"PluginRepoverification(" << obj.
plugindir() <<
", " << obj.
isNeeded() <<
")"; }
257 {
return str << obj; }
271 : _pimpl( new
Impl(
std::move(plugindir_r),
std::move(chroot_r) ) )
void verifyWorkflow(const Pathname &file_r, RW_pointer< PluginRepoverification::Checker::Impl > datap_r) const
JobReport convenience sending this instance of UserData with each message.
Repository metadata verification beyond GPG.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
bool kill()
Kill the program.
RW_pointer< PluginRepoverification::Impl > _parent
PluginRepoverification implementation.
bool reportFinalLineUnlessEmpty(std::string &line_r, Callback &cb_r)
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
int operator()(ExternalProgram &prog_r, Callback cb_r=Callback())
void addHistory(const std::string &msg_r)
Add some message text to the history.
WatchFile _watchPlugindir
String related utilities and Regular expression matching.
bool reportTimeout(Callback &cb_r)
What is known about a repository.
Impl(Pathname &&plugindir_r, Pathname &&chroot_r)
bool running()
Return whether program is running.
bool isNeeded() const
Whether the last checkIfNeeded found plugins to execute at all.
bool reportLine(std::string &line_r, Callback &cb_r)
Remember a files attributes to detect content changes.
void pluginVerify(std::string plugin_r, const Pathname &file_r, const PluginRepoverification::Checker::Impl &data_r) const
std::ostream & dumpOn(std::ostream &str, const PluginRepoverification::Impl &obj)
PluginRepoverification()
Default ctor, do nothing.
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
bool set(const std::string &key_r, AnyType val_r)
Set the value for key (nonconst version always returns true).
const std::string & asString() const
String representation.
std::string alias() const
unique identifier for this source.
void operator()(const Pathname &file_r) const
Check the downloaded master index file.
int close() override
Wait for the progamm to complete.
std::vector< std::string > Arguments
const Pathname & plugindir() const
std::string numstring(char n, int w=0)
std::ostream & operator<<(std::ostream &str, const zypp::sat::detail::CDataiterator *obj)
bool operator==(const PluginRepoverification &lhs, const PluginRepoverification &rhs)
Impl(RW_pointer< PluginRepoverification::Impl > parent_r, Pathname &&sigpathLocal_r, Pathname &&keypathLocal_r, RepoInfo &&repo_r)
FileChecker checking all repoverification plugins.
std::function< bool(std::optional< std::string >)> Callback
Report a line of output (without trailing NL) otherwise a life ping on timeout.
std::pair< ReceiveUpToResult, std::string > receiveUpto(FILE *file, char c, timeout_type timeout, bool failOnUnblockError)
constexpr std::string_view FILE("file")
std::ostream & operator<<(std::ostream &str, const PluginRepoverification &obj)
zypp_private::repo::PluginRepoverification PluginRepoverification
Monitor(io::timeout_type timeout_r=io::no_timeout)
~PluginRepoverification()
Dtor.
Exceptiontype thrown if a plugins verification fails.
Wrapper for const correct access via Smart pointer types.
RW_pointer< Impl > _pimpl
Implementation class.
Wrapper class for ::stat/::lstat.
void setBlocking(bool mode)
Set the blocking mode of the input stream.
static constexpr timeout_type no_timeout
std::ostream & operator<<(std::ostream &str, const PluginRepoverification::Impl &obj)
FILE * inputFile() const
Return the input stream.
PluginRepoverification::Checker data storage.
Checker getChecker(Pathname sigpathLocal_r, Pathname keypathLocal_r, RepoInfo repo_r) const
FileChecker factory remembering the location of the master index files GPG signature and key...
Easy-to use interface to the ZYPP dependency resolver.
static Pathname stripprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r with any root_r dir prefix striped.
std::ostream & dumpOn(std::ostream &str, const PluginRepoverification &obj)
bool checkIfNeeded()
Checks whether there are plugins to execute at all.