Imported Upstream version 17.20.0
[platform/upstream/libzypp.git] / zypp / media / MediaAccess.cc
index 628b0bb..265684e 100644 (file)
@@ -30,7 +30,6 @@
 #include "zypp/media/MediaDISK.h"
 #include "zypp/media/MediaCIFS.h"
 #include "zypp/media/MediaCurl.h"
-#include "zypp/media/MediaAria2c.h"
 #include "zypp/media/MediaMultiCurl.h"
 #include "zypp/media/MediaISO.h"
 #include "zypp/media/MediaPlugin.h"
@@ -113,7 +112,7 @@ MediaAccess::open (const Url& o_url, const Pathname & preferred_attach_point)
 
     UrlResolverPlugin::HeaderList custom_headers;
     Url url = UrlResolverPlugin::resolveUrl(o_url, custom_headers);
-    
+
     std::string scheme = url.getScheme();
     MIL << "Trying scheme '" << scheme << "'" << endl;
 
@@ -133,67 +132,53 @@ MediaAccess::open (const Url& o_url, const Pathname & preferred_attach_point)
         _handler = new MediaDISK (url,preferred_attach_point);
     else if (scheme == "cifs" || scheme == "smb")
        _handler = new MediaCIFS (url,preferred_attach_point);
-    else if (scheme == "ftp" || scheme == "http" || scheme == "https")
+    else if (scheme == "ftp" || scheme == "tftp" || scheme == "http" || scheme == "https")
     {
-        // Another good idea would be activate MediaAria2c handler via external var
-        bool use_aria = false;
         bool use_multicurl = true;
-        const char *ariaenv = getenv( "ZYPP_ARIA2C" );
-        const char *multicurlenv = getenv( "ZYPP_MULTICURL" );
-        // if user disabled it manually
-        if ( use_multicurl && multicurlenv && ( strcmp(multicurlenv, "0" ) == 0 ) )
+        string urlmediahandler ( url.getQueryParam("mediahandler") );
+        if ( urlmediahandler == "multicurl" )
         {
-            WAR << "multicurl manually disabled." << endl;
-            use_multicurl = false;
+          use_multicurl = true;
         }
-        else if ( !use_multicurl && multicurlenv && ( strcmp(multicurlenv, "1" ) == 0 ) )
-       {
-            WAR << "multicurl manually enabled." << endl;
-            use_multicurl = true;
-       }
-        // if user disabled it manually
-        if ( use_aria && ariaenv && ( strcmp(ariaenv, "0" ) == 0 ) )
+        else if ( urlmediahandler == "curl" )
         {
-            WAR << "aria2c manually disabled. Falling back to curl" << endl;
-            use_aria = false;
+          use_multicurl = false;
         }
-        else if ( !use_aria && ariaenv && ( strcmp(ariaenv, "1" ) == 0 ) )
-       {
-            // no aria for ftp - no advantage in that over curl
-            if ( url.getScheme() == "ftp" )
-                WAR << "no aria2c for FTP, despite ZYPP_ARIA2C=1" << endl;
-            else
-            {
-                WAR << "aria2c manually enabled." << endl;
-                use_aria = true;
-            }
-       }
-
-        // disable if it does not exist
-        if ( use_aria && ! MediaAria2c::existsAria2cmd() )
+        else
         {
-            WAR << "aria2c not found. Falling back to curl" << endl;
-            use_aria = false;
+          if ( ! urlmediahandler.empty() )
+          {
+            WAR << "unknown mediahandler set: " << urlmediahandler << endl;
+          }
+          const char *multicurlenv = getenv( "ZYPP_MULTICURL" );
+          // if user disabled it manually
+          if ( use_multicurl && multicurlenv && ( strcmp(multicurlenv, "0" ) == 0 ) )
+          {
+              WAR << "multicurl manually disabled." << endl;
+              use_multicurl = false;
+          }
+          else if ( !use_multicurl && multicurlenv && ( strcmp(multicurlenv, "1" ) == 0 ) )
+          {
+              WAR << "multicurl manually enabled." << endl;
+              use_multicurl = true;
+          }
         }
 
-        MediaCurl *curl;        
+        MediaCurl *curl;
 
-        if ( use_aria )
-            curl = new MediaAria2c (url,preferred_attach_point);        
-        else if ( use_multicurl )                     
-            curl = new MediaMultiCurl (url,preferred_attach_point); 
+        if ( use_multicurl )
+            curl = new MediaMultiCurl (url,preferred_attach_point);
        else
             curl = new MediaCurl (url,preferred_attach_point);
-        
-        UrlResolverPlugin::HeaderList::const_iterator it;
-        for (it = custom_headers.begin();
-             it != custom_headers.end();
-             ++it) {
-            std::string header = it->first + ": " + it->second;            
+
+        for ( const auto & el : custom_headers ) {
+            std::string header { el.first };
+           header += ": ";
+           header += el.second;
             MIL << "Added custom header -> " << header << endl;
-            curl->settings().addHeader(header);
+            curl->settings().addHeader( std::move(header) );
         }
-        _handler = curl;        
+        _handler = curl;
     }
     else if (scheme == "plugin" )
        _handler = new MediaPlugin (url,preferred_attach_point);
@@ -351,13 +336,13 @@ MediaAccess::release( const std::string & ejectDev )
 // filename is interpreted relative to the attached url
 // and a path prefix is preserved to destination
 void
-MediaAccess::provideFile( const Pathname & filename ) const
+MediaAccess::provideFile(const Pathname & filename , const ByteCount &expectedFileSize) const
 {
   if ( !_handler ) {
     ZYPP_THROW(MediaNotOpenException("provideFile(" + filename.asString() + ")"));
   }
 
-  _handler->provideFile( filename );
+  _handler->provideFile( filename, expectedFileSize );
 }
 
 void
@@ -484,7 +469,7 @@ void MediaAccess::getFile( const Url &from, const Pathname &to )
   try {
     media.open( u );
     media.attach();
-    media._handler->provideFileCopy( base, to );
+    media._handler->provideFileCopy( base, to, 0 );
     media.release();
   }
   catch (const MediaException & excpt_r)