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;
15 ///////////////////////////////////////////////////////////////////
18 ///////////////////////////////////////////////////////////////////
21 struct ServiceRepos::Impl
22 { virtual ~Impl() {} };
24 ///////////////////////////////////////////////////////////////////
26 struct RIMServiceRepos : public ServiceRepos::Impl
28 RIMServiceRepos( const ServiceInfo & service,
29 const ServiceRepos::ProcessRepo & callback,
30 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() )
32 // repoindex.xml must be fetched always without using cookies (bnc #573897)
33 Url serviceUrl( service.url() );
34 serviceUrl.setQueryParam( "cookies", "0" );
36 // download the repo index file
37 media::MediaManager mediamanager;
38 media::MediaAccessId mid = mediamanager.open( serviceUrl );
39 mediamanager.attach( mid );
40 mediamanager.provideFile( mid, "repo/repoindex.xml" );
41 Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
42 parser::RepoindexFileReader reader(path, callback);
43 service.setProbedTtl( reader.ttl() ); // hack! Modifying the const Service to set parsed TTL
44 mediamanager.release( mid );
45 mediamanager.close( mid );
49 ///////////////////////////////////////////////////////////////////
51 struct PluginServiceRepos : public ServiceRepos::Impl
53 PluginServiceRepos( const ServiceInfo & service,
54 const ServiceRepos::ProcessRepo & callback,
55 const ProgressData::ReceiverFnc & progress = ProgressData::ReceiverFnc() )
57 Url serviceUrl( service.url() );
60 ExternalProgram::Arguments args;
62 args.push_back( "/bin/sh" );
63 args.push_back( "-c" );
64 args.push_back( serviceUrl.getPathName() );
65 ExternalProgramWithStderr prog( args );
68 if ( prog.close() != 0 )
70 // ServicePluginInformalException:
71 // Ignore this error but we'd like to report it somehow...
72 std::string errbuffer;
73 prog.stderrGetUpTo( errbuffer, '\0' );
74 ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
75 ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
77 parser::RepoFileReader parser( buffer, callback );
81 ///////////////////////////////////////////////////////////////////
83 ServiceRepos::ServiceRepos( const ServiceInfo & service,
84 const ServiceRepos::ProcessRepo & callback,
85 const ProgressData::ReceiverFnc &progress )
86 : _impl( ( service.type() == ServiceType::PLUGIN )
87 ? static_cast<ServiceRepos::Impl*>( new PluginServiceRepos( service, callback, progress ) )
88 : static_cast<ServiceRepos::Impl*>( new RIMServiceRepos (service, callback, progress ) ) )
91 ServiceRepos::~ServiceRepos()
95 ///////////////////////////////////////////////////////////////////
97 ///////////////////////////////////////////////////////////////////