3 #include "zypp/base/Logger.h"
4 #include "zypp/repo/ServiceRepos.h"
5 #include "zypp/repo/RepoException.h"
6 #include "zypp/media/MediaException.h"
7 #include "zypp/parser/RepoFileReader.h"
8 #include "zypp/media/MediaManager.h"
9 #include "zypp/parser/RepoindexFileReader.h"
10 #include "zypp/ExternalProgram.h"
12 using std::stringstream;
20 class ServiceRepos::Impl
32 class RIMServiceRepos : public ServiceRepos::Impl
35 ServiceRepos::ProcessRepo _callback;
37 RIMServiceRepos(const ServiceInfo &service,
38 const ServiceRepos::ProcessRepo & callback,
39 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
42 // repoindex.xml must be fetched always without using cookies (bnc #573897)
43 Url serviceUrl( service.url() );
44 serviceUrl.setQueryParam( "cookies", "0" );
46 // download the repo index file
47 media::MediaManager mediamanager;
48 media::MediaAccessId mid = mediamanager.open( serviceUrl );
49 mediamanager.attach( mid );
50 mediamanager.provideFile( mid, "repo/repoindex.xml" );
51 Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
52 parser::RepoindexFileReader reader(path, _callback);
53 mediamanager.release( mid );
54 mediamanager.close( mid );
63 class PluginServiceRepos : public ServiceRepos::Impl
66 ServiceRepos::ProcessRepo _callback;
68 PluginServiceRepos(const ServiceInfo &service,
69 const ServiceRepos::ProcessRepo & callback,
70 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
73 Url serviceUrl( service.url() );
76 ExternalProgram::Arguments args;
78 args.push_back( "/bin/sh" );
79 args.push_back( "-c" );
80 args.push_back( serviceUrl.getPathName() );
81 ExternalProgramWithStderr prog( args );
84 if ( prog.close() != 0 )
86 // ServicePluginInformalException:
87 // Ignore this error but we'd like to report it somehow...
88 std::string errbuffer;
89 prog.stderrGetUpTo( errbuffer, '\0' );
90 ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
91 ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
94 parser::RepoFileReader parser(buffer, _callback);
102 ServiceRepos::ServiceRepos(const ServiceInfo &service,
103 const ServiceRepos::ProcessRepo & callback,
104 const ProgressData::ReceiverFnc &progress)
105 : _impl( (service.type() == ServiceType::PLUGIN) ? (ServiceRepos::Impl *)(new PluginServiceRepos(service, callback, progress)) : (ServiceRepos::Impl *)(new RIMServiceRepos(service, callback, progress)))
109 ServiceRepos::~ServiceRepos()