libzypp 17.31.32
ServiceRepos.cc
Go to the documentation of this file.
1#include <iostream>
2#include <sstream>
3#include <zypp/base/Logger.h>
6#include <zypp-media/MediaException>
10#include <zypp/ExternalProgram.h>
11
12using std::stringstream;
13using std::endl;
14
16namespace 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
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 {
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() );
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;
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
107
108 } // namespace repo
110} //namespace zypp
Interface of repoindex.xml file reader.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:94
Base class for Exception.
Definition Exception.h:146
ExternalProgram extended to offer reading programs stderr.
std::vector< std::string > Arguments
Describes a resource file located on a medium.
function< bool(const ProgressData &) ReceiverFnc)
Most simple version of progress reporting The percentage in most cases.
Service data.
Definition ServiceInfo.h:37
void setProbedTtl(Date::Duration ttl_r) const
Lazy init sugested TTL.
Url url() const
The service url.
Url manipulation class.
Definition Url.h:92
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
Definition Url.cc:604
static Pathname stripprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r with any root_r dir prefix striped.
Definition Pathname.cc:281
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
Read repository data from a .repo file.
Reads through a repoindex.xml file and collects repositories.
Service plugin has trouble providing the metadata but this should not be treated as error.
Retrieval of repository list for a service.
function< bool(const RepoInfo &) ProcessRepo)
Return false from the callback to get a AbortRequestException to be thrown and the processing to be c...
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.
Easy-to use interface to the ZYPP dependency resolver.
PluginServiceRepos(const Pathname &root_r, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
RIMServiceRepos(const Pathname &, const ServiceInfo &service, const ServiceRepos::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Service type enumeration.
Definition ServiceType.h:27
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:436
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:428
#define ERR
Definition Logger.h:98