libzypp 17.34.1
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
45 media::MediaManager mediamanager;
46 media::MediaAccessId mid = mediamanager.open( serviceUrl );
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() );
85 ExternalProgramWithStderr prog( args, root_r );
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;
95 ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
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.
Base class for Exception.
Definition Exception.h:147
const std::string & msg() const
Return the message string provided to the ctor.
Definition Exception.h:196
void remember(const Exception &old_r)
Store an other Exception as history.
Definition Exception.cc:124
ExternalProgram extended to offer reading programs stderr.
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() override
Wait for the progamm to complete.
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
void setQueryParam(const std::string &param, const std::string &value)
Set or add value for the specified query parameter.
Definition Url.cc:842
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
const std::string & asString() const
String representation.
Definition Pathname.h:93
Manages access to the 'physical' media, e.g CDROM drives, Disk volumes, directory trees,...
MediaAccessId open(const Url &url, const Pathname &preferred_attach_point="")
Opens the media access for specified with the url.
void attach(MediaAccessId accessId)
Attach the media using the concrete handler (checks all devices).
void close(MediaAccessId accessId)
Close the media access with specified id.
ZYPP_DEPRECATED void provideFile(MediaAccessId accessId, const Pathname &filename, const ByteCount &expectedFileSize) const
void release(MediaAccessId accessId, const std::string &ejectDev="")
Release the attached media and optionally eject.
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.
Reads through a repoindex.xml file and collects repositories.
Date::Duration ttl() const
Metadata TTL (repoindex.xml:xpath:/repoindex@ttl or 0).
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...
unsigned int MediaAccessId
Media manager access Id type.
Definition MediaSource.h:30
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