libzypp 17.34.0
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>
11
12using std::stringstream;
13using std::endl;
14
16namespace zypp
17{
19 namespace repo
20 {
22 {
23 Impl() = default;
24 Impl(const Impl &) = delete;
25 Impl(Impl &&) = delete;
26 Impl &operator=(const Impl &) = delete;
27 Impl &operator=(Impl &&) = delete;
28 virtual ~Impl() {}
29 };
30
32
34 {
35 RIMServiceRepos( const Pathname & /*root_r*/,
36 const ServiceInfo & service,
37 const ServiceRepos::ProcessRepo & callback,
39 {
40 // repoindex.xml must be fetched always without using cookies (bnc #573897)
41 Url serviceUrl( service.url() );
42 serviceUrl.setQueryParam( "cookies", "0" );
43
44 // download the repo index file
47 mediamanager.attach( mid );
48 mediamanager.provideFile( mid, OnMediaLocation("repo/repoindex.xml") );
49 Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
50 try {
51 parser::RepoindexFileReader reader(path, callback);
52 service.setProbedTtl( reader.ttl() ); // hack! Modifying the const Service to set parsed TTL
53 mediamanager.release( mid );
54 mediamanager.close( mid );
55 } catch ( const Exception &e ) {
56 //Reader throws a bare exception, we need to translate it into something our calling
57 //code expects and handles (bnc#1116840)
58 ZYPP_CAUGHT ( e );
60 ex.remember( e );
61 ZYPP_THROW( ex );
62 }
63 }
64 };
65
67
69 {
71 const ServiceInfo & service,
72 const ServiceRepos::ProcessRepo & callback,
74 {
75 // bsc#1080693: Service script needs to be executed chrooted to the RepoManagers rootDir.
76 // The service is not aware of the rootDir, so it's explicitly passed and needs to be
77 // stripped from the URLs path.
78 stringstream buffer;
79
81 args.reserve( 3 );
82 args.push_back( "/bin/sh" );
83 args.push_back( "-c" );
84 args.push_back( Pathname::stripprefix( root_r, service.url().getPathName() ).asString() );
86 prog >> buffer;
87
88 if ( prog.close() != 0 )
89 {
90 // ServicePluginInformalException:
91 // Ignore this error but we'd like to report it somehow...
92 std::string errbuffer;
93 prog.stderrGetUpTo( errbuffer, '\0' );
94 ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
96 }
97 parser::RepoFileReader parser( buffer, callback );
98 }
99 };
100
102
104 const ServiceInfo & service,
105 const ServiceRepos::ProcessRepo & callback,
106 const ProgressData::ReceiverFnc &progress )
107 : _impl( ( service.type() == ServiceType::PLUGIN )
108 ? static_cast<ServiceRepos::Impl*>( new PluginServiceRepos( root_r, service, callback, progress ) )
109 : static_cast<ServiceRepos::Impl*>( new RIMServiceRepos( root_r, service, callback, progress ) ) )
110 {}
111
114
115 } // namespace repo
117} //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:95
Base class for Exception.
Definition Exception.h:147
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:608
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.
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.
function< bool(const RepoInfo &)> ProcessRepo
Return false from the callback to get a AbortRequestException to be thrown and the processing to be c...
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())
Impl & operator=(Impl &&)=delete
Impl & operator=(const Impl &)=delete
Impl(const Impl &)=delete
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:437
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:429
#define ERR
Definition Logger.h:100