libzypp  15.28.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 
16 namespace zypp
17 {
19  namespace repo
20  {
22  { virtual ~Impl() {} };
23 
25 
27  {
28  RIMServiceRepos( const ServiceInfo & service,
29  const ServiceRepos::ProcessRepo & callback,
31  {
32  // repoindex.xml must be fetched always without using cookies (bnc #573897)
33  Url serviceUrl( service.url() );
34  serviceUrl.setQueryParam( "cookies", "0" );
35 
36  // download the repo index file
37  media::MediaManager mediamanager;
38  media::MediaAccessId mid = mediamanager.open( serviceUrl );
39  mediamanager.attach( mid );
40  mediamanager.provideFile( mid, "repo/repoindex.xml" );
41  Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
42  parser::RepoindexFileReader reader(path, callback);
43  service.setProbedTtl( reader.ttl() ); // hack! Modifying the const Service to set parsed TTL
44  mediamanager.release( mid );
45  mediamanager.close( mid );
46  }
47  };
48 
50 
52  {
53  PluginServiceRepos( const ServiceInfo & service,
54  const ServiceRepos::ProcessRepo & callback,
56  {
57  Url serviceUrl( service.url() );
58  stringstream buffer;
59 
61  args.reserve( 3 );
62  args.push_back( "/bin/sh" );
63  args.push_back( "-c" );
64  args.push_back( serviceUrl.getPathName() );
65  ExternalProgramWithStderr prog( args );
66  prog >> buffer;
67 
68  if ( prog.close() != 0 )
69  {
70  // ServicePluginInformalException:
71  // Ignore this error but we'd like to report it somehow...
72  std::string errbuffer;
73  prog.stderrGetUpTo( errbuffer, '\0' );
74  ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
75  ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
76  }
77  parser::RepoFileReader parser( buffer, callback );
78  }
79  };
80 
82 
84  const ServiceRepos::ProcessRepo & callback,
85  const ProgressData::ReceiverFnc &progress )
86  : _impl( ( service.type() == ServiceType::PLUGIN )
87  ? static_cast<ServiceRepos::Impl*>( new PluginServiceRepos( service, callback, progress ) )
88  : static_cast<ServiceRepos::Impl*>( new RIMServiceRepos (service, callback, progress ) ) )
89  {}
90 
92  {}
93 
94  } // namespace repo
96 } //namespace zypp
Service data.
Definition: ServiceInfo.h:36
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
Date::Duration ttl() const
Metadata TTL (repoindex.xml:xpath:/repoindex or 0).
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:827
Reads through a repoindex.xml file and collects repositories.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:321
ExternalProgram extended to offer reading programs stderr.
void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Provide provide file denoted by relative path below of the 'attach point' of the specified media and ...
Service plugin has trouble providing the metadata but this should not be treated as error...
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
#define ERR
Definition: Logger.h:66
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())
Definition: ServiceRepos.cc:83
RIMServiceRepos(const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:28
Service type enumeration.
Definition: ServiceType.h:26
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached...
Read repository data from a .repo file.
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.
PluginServiceRepos(const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:53
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees...
Definition: MediaManager.h:473
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Definition: ServiceInfo.cc:114
Url url() const
The service url.
Definition: ServiceInfo.cc:99
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.