libzypp  17.28.0
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, OnMediaLocation("repo/repoindex.xml") );
42  Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
43  try {
44  parser::RepoindexFileReader reader(path, callback);
45  service.setProbedTtl( reader.ttl() ); // hack! Modifying the const Service to set parsed TTL
46  mediamanager.release( mid );
47  mediamanager.close( mid );
48  } catch ( const Exception &e ) {
49  //Reader throws a bare exception, we need to translate it into something our calling
50  //code expects and handles (bnc#1116840)
51  ZYPP_CAUGHT ( e );
53  ex.remember( e );
54  ZYPP_THROW( ex );
55  }
56  }
57  };
58 
60 
62  {
63  PluginServiceRepos( const Pathname & root_r,
64  const ServiceInfo & service,
65  const ServiceRepos::ProcessRepo & callback,
67  {
68  // bsc#1080693: Service script needs to be executed chrooted to the RepoManagers rootDir.
69  // The service is not aware of the rootDir, so it's explicitly passed and needs to be
70  // stripped from the URLs path.
71  stringstream buffer;
72 
74  args.reserve( 3 );
75  args.push_back( "/bin/sh" );
76  args.push_back( "-c" );
77  args.push_back( Pathname::stripprefix( root_r, service.url().getPathName() ).asString() );
78  ExternalProgramWithStderr prog( args, root_r );
79  prog >> buffer;
80 
81  if ( prog.close() != 0 )
82  {
83  // ServicePluginInformalException:
84  // Ignore this error but we'd like to report it somehow...
85  std::string errbuffer;
86  prog.stderrGetUpTo( errbuffer, '\0' );
87  ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
88  ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
89  }
90  parser::RepoFileReader parser( buffer, callback );
91  }
92  };
93 
95 
97  const ServiceInfo & service,
98  const ServiceRepos::ProcessRepo & callback,
99  const ProgressData::ReceiverFnc &progress )
100  : _impl( ( service.type() == ServiceType::PLUGIN )
101  ? static_cast<ServiceRepos::Impl*>( new PluginServiceRepos( root_r, service, callback, progress ) )
102  : static_cast<ServiceRepos::Impl*>( new RIMServiceRepos( root_r, service, callback, progress ) ) )
103  {}
104 
106  {}
107 
108  } // namespace repo
110 } //namespace zypp
zypp::repo::ServiceRepos
Retrieval of repository list for a service.
Definition: ServiceRepos.h:26
zypp::repo::ServiceType
Service type enumeration.
Definition: ServiceType.h:27
ERR
#define ERR
Definition: Logger.h:98
zypp::ServiceInfo::url
Url url() const
The service url.
Definition: ServiceInfo.cc:99
zypp::ExternalProgramWithStderr
ExternalProgram extended to offer reading programs stderr.
Definition: ExternalProgram.h:254
zypp::ServiceInfo
Service data.
Definition: ServiceInfo.h:37
zypp::Exception
Base class for Exception.
Definition: Exception.h:146
zypp::repo::ServicePluginInformalException
Service plugin has trouble providing the metadata but this should not be treated as error.
Definition: RepoException.h:263
zypp::Url::setQueryParam
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition: Url.cc:833
zypp::repo::PluginServiceRepos
Definition: ServiceRepos.cc:62
zypp::repo::ServiceRepos::Impl::~Impl
virtual ~Impl()
Definition: ServiceRepos.cc:22
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition: OnMediaLocation.h:39
zypp::repo::RIMServiceRepos::RIMServiceRepos
RIMServiceRepos(const Pathname &, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:28
zypp::media::MediaManager::attach
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
Definition: MediaManager.cc:437
MediaManager.h
ServiceRepos.h
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:396
zypp::repo::ServiceRepos::ServiceRepos
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:96
zypp::filesystem::Pathname::stripprefix
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
zypp::media::MediaAccessId
unsigned int MediaAccessId
Media manager access Id type.
Definition: MediaSource.h:29
zypp::ExternalProgram::Arguments
std::vector< std::string > Arguments
Definition: ExternalProgram.h:68
zypp::Exception::remember
void remember(const Exception &old_r)
Store an other Exception as history.
Definition: Exception.cc:105
zypp::repo::RIMServiceRepos
Definition: ServiceRepos.cc:27
zypp::repo::PluginServiceRepos::PluginServiceRepos
PluginServiceRepos(const Pathname &root_r, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Definition: ServiceRepos.cc:63
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:392
zypp::media::MediaManager
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Definition: MediaManager.h:454
zypp::parser::RepoindexFileReader::ttl
Date::Duration ttl() const
Metadata TTL (repoindex.xml:xpath:/repoindex@ttl or 0).
Definition: RepoindexFileReader.cc:276
MediaException.h
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::media::MediaManager::open
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
Definition: MediaManager.cc:313
zypp::ServiceInfo::setProbedTtl
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Definition: ServiceInfo.cc:114
zypp::ExternalProgram::close
int close()
Wait for the progamm to complete.
Definition: ExternalProgram.cc:339
zypp::media::MediaManager::localPath
Pathname localPath(MediaAccessId accessId, const Pathname &pathname) const
Shortcut for 'localRoot() + pathname', but returns an empty pathname if media is not attached.
Definition: MediaManager.cc:685
zypp::parser::RepoindexFileReader
Reads through a repoindex.xml file and collects repositories.
Definition: RepoindexFileReader.h:45
zypp::repo::ServiceRepos::Impl
Definition: ServiceRepos.cc:22
zypp::ExternalProgramWithStderr::stderrGetUpTo
bool stderrGetUpTo(std::string &retval_r, const char delim_r, bool returnDelim_r=false)
Read data up to delim_r from stderr (nonblocking).
Definition: ExternalProgram.cc:503
zypp::ProgressData::ReceiverFnc
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
Definition: ProgressData.h:139
zypp::media::MediaManager::close
void close(MediaAccessId accessId)
Close the media access with specified id.
Definition: MediaManager.cc:331
zypp::Url::getPathName
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition: Url.cc:599
zypp::media::MediaManager::release
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
Definition: MediaManager.cc:506
RepoFileReader.h
zypp::parser::RepoFileReader
Read repository data from a .repo file.
Definition: RepoFileReader.h:52
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::repo::ServiceRepos::ProcessRepo
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
RepoindexFileReader.h
Interface of repoindex.xml file reader.
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition: Pathname.h:91
RepoException.h
zypp::Url
Url manipulation class.
Definition: Url.h:92
zypp::media::MediaManager::provideFile
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
Definition: MediaManager.cc:696
zypp::repo::ServiceRepos::~ServiceRepos
~ServiceRepos()
Definition: ServiceRepos.cc:105
zypp::Exception::msg
const std::string & msg() const
Return the message string provided to the ctor.
Definition: Exception.h:195