libzypp  13.10.6
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 
15 namespace zypp
16 {
17 namespace repo
18 {
19 
21 {
22 public:
23  Impl()
24  {
25  }
26 
27  virtual ~Impl()
28  {
29  }
30 };
31 
33 {
34 public:
36 
37  RIMServiceRepos(const ServiceInfo &service,
38  const ServiceRepos::ProcessRepo & callback,
40  : _callback(callback)
41  {
42  // repoindex.xml must be fetched always without using cookies (bnc #573897)
43  Url serviceUrl( service.url() );
44  serviceUrl.setQueryParam( "cookies", "0" );
45 
46  // download the repo index file
47  media::MediaManager mediamanager;
48  media::MediaAccessId mid = mediamanager.open( serviceUrl );
49  mediamanager.attach( mid );
50  mediamanager.provideFile( mid, "repo/repoindex.xml" );
51  Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
53  mediamanager.release( mid );
54  mediamanager.close( mid );
55  }
56 
58  {
59 
60  }
61 };
62 
64 {
65 public:
67 
69  const ServiceRepos::ProcessRepo & callback,
71  : _callback(callback)
72  {
73  Url serviceUrl( service.url() );
74  stringstream buffer;
75 
77  args.reserve( 3 );
78  args.push_back( "/bin/sh" );
79  args.push_back( "-c" );
80  args.push_back( serviceUrl.getPathName() );
81  ExternalProgramWithStderr prog( args );
82  prog >> buffer;
83 
84  if ( prog.close() != 0 )
85  {
86  // ServicePluginInformalException:
87  // Ignore this error but we'd like to report it somehow...
88  std::string errbuffer;
89  prog.stderrGetUpTo( errbuffer, '\0' );
90  ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
92  }
93 
94  parser::RepoFileReader parser(buffer, _callback);
95  }
96 
98  {}
99 };
100 
101 
103  const ServiceRepos::ProcessRepo & callback,
104  const ProgressData::ReceiverFnc &progress)
105  : _impl( (service.type() == ServiceType::PLUGIN) ? (ServiceRepos::Impl *)(new PluginServiceRepos(service, callback, progress)) : (ServiceRepos::Impl *)(new RIMServiceRepos(service, callback, progress)))
106 {
107 }
108 
110 {
111 }
112 
113 
114 }
115 }
PluginServiceRepos(const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:68
function< bool(const RepoInfo &)> ProcessRepo
Callback definition.
Definition: ServiceRepos.h:38
Retrieval of repository list for a service.
Definition: ServiceRepos.h:26
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:827
Reads through a repoindex.xml file and collects repositories.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:320
ExternalProgram extended to offer reading programs stderr.
Service plugin has trouble providing the metadata but this should not be treated as error...
void provideFile(MediaAccessId accessId, const Pathname &filename) 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:144
#define ERR
Definition: Logger.h:49
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
std::vector< std::string > Arguments
Interface of repoindex.xml file reader.
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
ServiceRepos(const ServiceInfo &service, const ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
RIMServiceRepos(const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:37
Service type enumeration.
Definition: ServiceType.h:26
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for &#39;localRoot() + pathname&#39;, but returns an empty pathname if media is not attached...
Read repository data from a .repo file.
ServiceRepos::ProcessRepo _callback
Definition: ServiceRepos.cc:66
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).
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
ServiceRepos::ProcessRepo _callback
Definition: ServiceRepos.cc:35
Url url() const
Gets url to service.
Definition: ServiceInfo.cc:101
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.