Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / media / MediaNFS.cc
index 529d886..626651c 100644 (file)
@@ -11,6 +11,7 @@
 */
 
 #include <iostream>
+#include <sstream>
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/String.h"
@@ -29,7 +30,7 @@ namespace zypp {
     // CLASS NAME : MediaNFS
     //
     ///////////////////////////////////////////////////////////////////
-    
+
     ///////////////////////////////////////////////////////////////////
     //
     //
@@ -85,16 +86,16 @@ namespace zypp {
        return;
       }
 
-      const char* const filesystem = "nfs";
-      std::string       mountpoint = attachPoint().asString();
-      Mount mount;
+      if( !isUseableAttachPoint( attachPoint() ) )
+      {
+       setAttachPoint( createAttachPoint(), true );
+      }
+      std::string mountpoint( attachPoint().asString() );
 
-      if( !isUseableAttachPoint(attachPoint()))
+      std::string filesystem( _url.getScheme() );
+      if ( filesystem != "nfs4" && _url.getQueryParam("type") == "nfs4" )
       {
-       mountpoint = createAttachPoint().asString();
-       if( mountpoint.empty())
-         ZYPP_THROW( MediaBadAttachPointException(url()));
-       setAttachPoint( mountpoint, true);
+        filesystem = "nfs4";
       }
 
       string options = _url.getQueryParam("mountoptions");
@@ -102,21 +103,44 @@ namespace zypp {
       {
        options="ro";
       }
-    
-      // Add option "nolock", unless option "lock" or "unlock" is already set.
-      // This should prevent the mount command hanging when the portmapper isn't
-      // running.
+
       vector<string> optionList;
       str::split( options, std::back_inserter(optionList), "," );
       vector<string>::const_iterator it;
+      bool contains_lock  = false, contains_soft = false,
+           contains_timeo = false, contains_hard = false;
+
       for( it = optionList.begin(); it != optionList.end(); ++it ) {
-       if ( *it == "lock" || *it == "nolock" ) break;
+        if ( *it == "lock" || *it == "nolock" ) contains_lock = true;
+        else if ( *it == "soft") contains_soft = true;
+        else if ( *it == "hard") contains_hard = true;
+        else if ( it->find("timeo") != string::npos ) contains_timeo = true;
       }
-      if ( it == optionList.end() ) {
-       optionList.push_back( "nolock" );
-       options = str::join( optionList, "," );
+
+      if ( !(contains_lock && contains_soft) ) {
+        // Add option "nolock", unless option "lock" or "unlock" is already set.
+        // This should prevent the mount command hanging when the portmapper isn't
+        // running.
+        if ( !contains_lock ) {
+          optionList.push_back( "nolock" );
+        }
+        // Add options "soft,timeo=NFS_MOUNT_TIMEOUT", unless they are set
+        // already or "hard" option is explicitly specified. This prevent
+        // the mount command from hanging when the nfs server is not responding
+        // and file transactions from an unresponsive to throw an error after
+        // a short time instead of hanging forever
+        if ( !(contains_soft || contains_hard) ) {
+          optionList.push_back( "soft" );
+          if ( !contains_timeo ) {
+            ostringstream s;
+            s << "timeo=" << NFS_MOUNT_TIMEOUT;
+            optionList.push_back( s.str() );
+          }
+        }
+        options = str::join( optionList, "," );
       }
 
+      Mount mount;
       mount.mount(path,mountpoint,filesystem,options);
 
       setMediaSource(media);
@@ -158,24 +182,23 @@ namespace zypp {
     bool
     MediaNFS::isAttached() const
     {
-      return checkAttached(false, true);
+      return checkAttached(true);
     }
 
     ///////////////////////////////////////////////////////////////////
     //
     //
-    // METHOD NAME : MediaNFS::releaseFrom
-    // METHOD TYPE : PMError
+    //  METHOD NAME : MediaNFS::releaseFrom
+    //  METHOD TYPE : void
     //
-    // DESCRIPTION : Asserted that media is attached.
+    //  DESCRIPTION : Asserted that media is attached.
     //
-    void MediaNFS::releaseFrom( bool eject )
+    void MediaNFS::releaseFrom( const std::string & ejectDev )
     {
       Mount mount;
       mount.umount(attachPoint().asString());
     }
 
-
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : MediaNFS::getFile
@@ -187,7 +210,7 @@ namespace zypp {
     {
       MediaHandler::getFile( filename );;
     }
-    
+
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : MediaNFS::getDir
@@ -199,7 +222,7 @@ namespace zypp {
     {
       MediaHandler::getDir( dirname, recurse_r );
     }
-    
+
     ///////////////////////////////////////////////////////////////////
     //
     //
@@ -213,7 +236,7 @@ namespace zypp {
     {
       MediaHandler::getDirInfo( retlist, dirname, dots );
     }
-    
+
     ///////////////////////////////////////////////////////////////////
     //
     //
@@ -228,5 +251,11 @@ namespace zypp {
       MediaHandler::getDirInfo( retlist, dirname, dots );
     }
 
+    bool MediaNFS::getDoesFileExist( const Pathname & filename ) const
+    {
+      return MediaHandler::getDoesFileExist( filename );
+    }
+
+
   } // namespace media
 } // namespace zypp