Imported Upstream version 17.0.0
[platform/upstream/libzypp.git] / zypp / media / MediaHandler.cc
index 28c581b..2e20218 100644 (file)
 #include <fstream>
 #include <sstream>
 
+#include "zypp/ZConfig.h"
 #include "zypp/TmpPath.h"
 #include "zypp/Date.h"
 #include "zypp/base/LogTools.h"
+#include "zypp/base/Gettext.h"
 #include "zypp/base/String.h"
 #include "zypp/media/MediaHandler.h"
 #include "zypp/media/MediaManager.h"
@@ -56,7 +58,7 @@ MediaHandler::MediaHandler ( const Url &      url_r,
                             const bool       does_download_r )
     : _mediaSource()
     , _attachPoint( new AttachPoint())
-    , _AttachPointHint()
+    , _attachPointHint()
     , _relativeRoot( urlpath_below_attachpoint_r)
     , _does_download( does_download_r )
     , _attach_mtime(0)
@@ -268,8 +270,8 @@ MediaHandler::setAttachPoint(const AttachPointRef &ref)
 void
 MediaHandler::attachPointHint(const Pathname &path, bool temporary)
 {
-  _AttachPointHint.path = path;
-  _AttachPointHint.temp = temporary;
+  _attachPointHint.path = path;
+  _attachPointHint.temp = temporary;
 }
 
 ///////////////////////////////////////////////////////////////////
@@ -283,7 +285,7 @@ MediaHandler::attachPointHint(const Pathname &path, bool temporary)
 AttachPoint
 MediaHandler::attachPointHint() const
 {
-  return _AttachPointHint;
+  return _attachPointHint;
 }
 
 ///////////////////////////////////////////////////////////////////
@@ -340,36 +342,36 @@ MediaHandler::setAttachPrefix(const Pathname &attach_prefix)
 Pathname
 MediaHandler::createAttachPoint() const
 {
-  /////////////////////////////////////////////////////////////////
-  // provide a default (temporary) attachpoint
-  /////////////////////////////////////////////////////////////////
-  const char * defmounts[] = {
-      "/var/adm/mount", filesystem::TmpPath::defaultLocation().c_str(), /**/NULL/**/
-  };
-
+  Pathname aroot;
   Pathname apoint;
-  Pathname aroot( MediaHandler::_attachPrefix);
-
-  if( !aroot.empty())
   {
-    apoint = createAttachPoint(aroot);
+    aroot = MediaHandler::_attachPrefix;       // explicit request
+    if ( ! aroot.empty() )
+      apoint = createAttachPoint( aroot );
   }
-  for ( const char ** def = defmounts; *def && apoint.empty(); ++def ) {
-    aroot = *def;
-    if( aroot.empty())
-      continue;
 
-    apoint = createAttachPoint(aroot);
+  if ( apoint.empty() )                                // fallback to config value
+  {
+    aroot = ZConfig::instance().download_mediaMountdir();
+    if ( ! aroot.empty() )
+      apoint = createAttachPoint( aroot );
   }
 
-  if ( aroot.empty() ) {
-    ERR << "Create attach point: Can't find a writable directory to create an attach point" << std::endl;
-    return aroot;
+  if ( apoint.empty() )                                // fall back to temp space
+  {
+    aroot = filesystem::TmpPath::defaultLocation();
+    if ( ! aroot.empty() )
+      apoint = createAttachPoint( aroot );
   }
 
-  if ( !apoint.empty() ) {
-    MIL << "Created default attach point " << apoint << std::endl;
+  if ( apoint.empty() )
+  {
+    auto except = MediaBadAttachPointException( url() );
+    except.addHistory( _("Create attach point: Can't find a writable directory to create an attach point") );
+    ZYPP_THROW( std::move(except) );
   }
+
+  MIL << "Created default attach point " << apoint << std::endl;
   return apoint;
 }
 
@@ -989,8 +991,8 @@ MediaHandler::dependsOnParent(MediaAccessId parentId, bool exactIdMatch)
 //
 //     DESCRIPTION :
 //
-void MediaHandler::provideFileCopy(Pathname srcFilename,
-                                       Pathname targetFilename , const ByteCount &expectedFileSize_r) const
+void MediaHandler::provideFileCopy( Pathname srcFilename,
+                                       Pathname targetFilename ) const
 {
   if ( !isAttached() ) {
     INT << "Media not_attached on provideFileCopy(" << srcFilename
@@ -998,18 +1000,18 @@ void MediaHandler::provideFileCopy(Pathname srcFilename,
     ZYPP_THROW(MediaNotAttachedException(url()));
   }
 
-  getFileCopy( srcFilename, targetFilename, expectedFileSize_r ); // pass to concrete handler
+  getFileCopy( srcFilename, targetFilename ); // pass to concrete handler
   DBG << "provideFileCopy(" << srcFilename << "," << targetFilename  << ")" << endl;
 }
 
-void MediaHandler::provideFile(Pathname filename , const ByteCount &expectedFileSize_r) const
+void MediaHandler::provideFile( Pathname filename ) const
 {
   if ( !isAttached() ) {
     INT << "Error: Not attached on provideFile(" << filename << ")" << endl;
     ZYPP_THROW(MediaNotAttachedException(url()));
   }
 
-  getFile( filename, expectedFileSize_r ); // pass to concrete handler
+  getFile( filename ); // pass to concrete handler
   DBG << "provideFile(" << filename << ")" << endl;
 }
 
@@ -1174,7 +1176,7 @@ void MediaHandler::getDirectoryYast( filesystem::DirContent & retlist,
 
   // look for directory.yast
   Pathname dirFile = dirname + "directory.yast";
-  getFile( dirFile, 0 );
+  getFile( dirFile );
   DBG << "provideFile(" << dirFile << "): " << "OK" << endl;
 
   // using directory.yast
@@ -1230,7 +1232,7 @@ ostream & operator<<( ostream & str, const MediaHandler & obj )
 //     DESCRIPTION : Asserted that media is attached.
 //                    Default implementation of pure virtual.
 //
-void MediaHandler::getFile(const Pathname & filename , const ByteCount &) const
+void MediaHandler::getFile( const Pathname & filename ) const
 {
     PathInfo info( localPath( filename ) );
     if( info.isFile() ) {
@@ -1244,9 +1246,9 @@ void MediaHandler::getFile(const Pathname & filename , const ByteCount &) const
 }
 
 
-void MediaHandler::getFileCopy (const Pathname & srcFilename, const Pathname & targetFilename , const ByteCount &expectedFileSize_r) const
+void MediaHandler::getFileCopy ( const Pathname & srcFilename, const Pathname & targetFilename ) const
 {
-  getFile(srcFilename, expectedFileSize_r);
+  getFile(srcFilename);
 
   if ( copy( localPath( srcFilename ), targetFilename ) != 0 ) {
     ZYPP_THROW(MediaWriteException(targetFilename));