Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / repo / ServiceRepos.cc
index 95069c0..86d0dc5 100644 (file)
@@ -2,12 +2,15 @@
 #include <sstream>
 #include "zypp/base/Logger.h"
 #include "zypp/repo/ServiceRepos.h"
+#include "zypp/repo/RepoException.h"
+#include "zypp/media/MediaException.h"
 #include "zypp/parser/RepoFileReader.h"
 #include "zypp/media/MediaManager.h"
 #include "zypp/parser/RepoindexFileReader.h"
 #include "zypp/ExternalProgram.h"
 
 using std::stringstream;
+using std::endl;
 
 namespace zypp
 {
@@ -20,7 +23,7 @@ public:
     Impl()
     {
     }
-    
+
     virtual ~Impl()
     {
     }
@@ -30,7 +33,7 @@ class RIMServiceRepos : public ServiceRepos::Impl
 {
 public:
     ServiceRepos::ProcessRepo _callback;
-    
+
     RIMServiceRepos(const ServiceInfo &service,
                     const ServiceRepos::ProcessRepo & callback,
                     const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
@@ -39,7 +42,7 @@ public:
       // repoindex.xml must be fetched always without using cookies (bnc #573897)
       Url serviceUrl( service.url() );
       serviceUrl.setQueryParam( "cookies", "0" );
-      
+
       // download the repo index file
       media::MediaManager mediamanager;
       media::MediaAccessId mid = mediamanager.open( serviceUrl );
@@ -50,7 +53,7 @@ public:
       mediamanager.release( mid );
       mediamanager.close( mid );
     }
-    
+
     ~RIMServiceRepos()
     {
 
@@ -61,7 +64,7 @@ class PluginServiceRepos : public ServiceRepos::Impl
 {
 public:
     ServiceRepos::ProcessRepo _callback;
-    
+
     PluginServiceRepos(const ServiceInfo &service,
                       const ServiceRepos::ProcessRepo & callback,
                       const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
@@ -69,33 +72,44 @@ public:
     {
       Url serviceUrl( service.url() );
       stringstream buffer;
-     
-      ExternalProgram prog(serviceUrl.getPathName(), ExternalProgram::Discard_Stderr, false, -1, true);
-      std::string line;
-      for(line = prog.receiveLine(); !line.empty(); line = prog.receiveLine() )
-          buffer << line;
-      prog.close();
+
+      ExternalProgram::Arguments args;
+      args.reserve( 3 );
+      args.push_back( "/bin/sh" );
+      args.push_back( "-c" );
+      args.push_back( serviceUrl.getPathName() );
+      ExternalProgramWithStderr prog( args );
+      prog >> buffer;
+
+      if ( prog.close() != 0 )
+      {
+       // ServicePluginInformalException:
+       // Ignore this error but we'd like to report it somehow...
+       std::string errbuffer;
+       prog.stderrGetUpTo( errbuffer, '\0' );
+       ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
+       ZYPP_THROW( repo::ServicePluginInformalException( service, errbuffer ) );
+      }
+
       parser::RepoFileReader parser(buffer, _callback);
     }
-    
-    ~PluginServiceRepos()
-    {
 
-    }
+    ~PluginServiceRepos()
+    {}
 };
 
-    
+
 ServiceRepos::ServiceRepos(const ServiceInfo &service,
                            const ServiceRepos::ProcessRepo & callback,
                            const ProgressData::ReceiverFnc &progress)
     : _impl( (service.type() == ServiceType::PLUGIN) ? (ServiceRepos::Impl *)(new PluginServiceRepos(service, callback, progress)) : (ServiceRepos::Impl *)(new RIMServiceRepos(service, callback, progress)))
 {
 }
-    
+
 ServiceRepos::~ServiceRepos()
 {
 }
-    
+
 
 }
 }