libzypp  17.7.2
ServiceRepos.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <sstream>
3 #include "zypp/base/Logger.h"
10 #include "zypp/ExternalProgram.h"
11 
12 using std::stringstream;
13 using std::endl;
14 
16 namespace zypp
17 {
19  namespace repo
20  {
22  { virtual ~Impl() {} };
23 
25 
27  {
28  RIMServiceRepos( const Pathname & /*root_r*/,
29  const ServiceInfo & service,
30  const ServiceRepos::ProcessRepo & callback,
32  {
33  // repoindex.xml must be fetched always without using cookies (bnc #573897)
34  Url serviceUrl( service.url() );
35  serviceUrl.setQueryParam( "cookies", "0" );
36 
37  // download the repo index file
38  media::MediaManager mediamanager;
39  media::MediaAccessId mid = mediamanager.open( serviceUrl );
40  mediamanager.attach( mid );
41  mediamanager.provideFile( mid, "repo/repoindex.xml" );
42  Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
43  parser::RepoindexFileReader reader(path, callback);
44  service.setProbedTtl( reader.ttl() ); // hack! Modifying the const Service to set parsed TTL
45  mediamanager.release( mid );
46  mediamanager.close( mid );
47  }
48  };
49 
51 
53  {
54  PluginServiceRepos( const Pathname & root_r,
55  const ServiceInfo & service,
56  const ServiceRepos::ProcessRepo & callback,
58  {
59  // bsc#1080693: Service script needs to be executed chrooted to the RepoManagers rootDir.
60  // The service is not aware of the rootDir, so it's explicitly passed and needs to be
61  // stripped from the URLs path.
62  stringstream buffer;
63 
65  args.reserve( 3 );
66  args.push_back( "/bin/sh" );
67  args.push_back( "-c" );
68  args.push_back( Pathname::stripprefix( root_r, service.url().getPathName() ).asString() );
69  ExternalProgramWithStderr prog( args, root_r );
70  prog >> buffer;
71 
72  if ( prog.close() != 0 )
73  {
74  // ServicePluginInformalException:
75  // Ignore this error but we'd like to report it somehow...
76  std::string errbuffer;
77  prog.stderrGetUpTo( errbuffer, '\0' );
78  ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
79  ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
80  }
81  parser::RepoFileReader parser( buffer, callback );
82  }
83  };
84 
86 
88  const ServiceInfo & service,
89  const ServiceRepos::ProcessRepo & callback,
90  const ProgressData::ReceiverFnc &progress )
91  : _impl( ( service.type() == ServiceType::PLUGIN )
92  ? static_cast<ServiceRepos::Impl*>( new PluginServiceRepos( root_r, service, callback, progress ) )
93  : static_cast<ServiceRepos::Impl*>( new RIMServiceRepos( root_r, service, callback, progress ) ) )
94  {}
95 
97  {}
98 
99  } // namespace repo
101 } //namespace zypp
Service data.
Definition: ServiceInfo.h:36
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Definition: ServiceInfo.cc:114
function< bool(const RepoInfo &)> ProcessRepo
Return false from the callback to get a AbortRequestException to be thrown and the processing to be c...
Definition: ServiceRepos.h:32
Retrieval of repository list for a service.
Definition: ServiceRepos.h:25
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:832
Reads through a repoindex.xml file and collects repositories.
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
ExternalProgram extended to offer reading programs stderr.
PluginServiceRepos(const Pathname &root_r, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:54
Service plugin has trouble providing the metadata but this should not be treated as error...
void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Provide provide file denoted by relative path below of the &#39;attach point&#39; of the specified media and ...
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
ServiceRepos(const Pathname &root_r, const ServiceInfo &service, const ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
bsc#1080693: Explicitly pass the RemoManagers rootDir until it can be queried from the ServiceInfo...
Definition: ServiceRepos.cc:87
#define ERR
Definition: Logger.h:66
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
std::vector< std::string > Arguments
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for &#39;localRoot() + pathname&#39;, but returns an empty pathname if media is not attached...
Interface of repoindex.xml file reader.
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Service type enumeration.
Definition: ServiceType.h:26
Read repository data from a .repo file.
Url url() const
The service url.
Definition: ServiceInfo.cc:99
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
bool stderrGetUpTo(std::string &retval_r, const char delim_r, bool returnDelim_r=false)
Read data up to delim_r from stderr (nonblocking).
RIMServiceRepos(const Pathname &, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:28
int close()
Wait for the progamm to complete.
Manages access to the &#39;physical&#39; media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:473
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:598
Date::Duration ttl() const
Metadata TTL (repoindex.xml:xpath:/repoindex or 0).
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
static Pathname stripprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r with any root_r dir prefix striped.
Definition: Pathname.cc:244
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
Url manipulation class.
Definition: Url.h:87
void close(MediaAccessId accessId)
Close the media access with specified id.