Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / media / MediaManager.cc
index d4956d4..7295132 100644 (file)
 #include "zypp/media/Mount.h"
 #include "zypp/thread/Mutex.h"
 #include "zypp/thread/MutexLock.h"
-#include "zypp/target/hal/HalContext.h"
 
 #include "zypp/base/String.h"
 #include "zypp/base/Logger.h"
 #include "zypp/Pathname.h"
 #include "zypp/PathInfo.h"
 
-#define  DISABLE_AUTOMOUNTER      0
-
-
 //////////////////////////////////////////////////////////////////////
 namespace zypp
 { ////////////////////////////////////////////////////////////////////
@@ -126,142 +122,6 @@ namespace zypp
       // -------------------------------------------------------------
       typedef std::map<MediaAccessId, ManagedMedia> ManagedMediaMap;
 
-
-      // -------------------------------------------------------------
-      enum AutoMounterCleanUp
-      {
-        NONE, ENABLE, REMOVE
-      };
-
-      #define HAL_AUTOMOUNTER_UDI  "/org/freedesktop/Hal/devices/computer"
-      #define HAL_AUTOMOUNTER_KEY  "storage.disable_volume_handling"
-
-      // -------------------------------------------------------------
-      AutoMounterCleanUp
-      disableAutoMounter()
-      {
-        using namespace zypp::target::hal;
-
-        AutoMounterCleanUp cleanup(NONE);
-#if DISABLE_AUTOMOUNTER
-        try
-        {
-          HalContext hal(true);
-          bool disabled(false);
-
-          // query
-          XXX << "Checking HAL volume handling property"
-              << std::endl;
-          try
-          {
-            disabled = hal.getDevicePropertyBool(
-              HAL_AUTOMOUNTER_UDI, HAL_AUTOMOUNTER_KEY
-            );
-
-            if( disabled)
-            {
-              MIL << "HAL volume handling is already disabled"
-                  << std::endl;
-            }
-            else
-            {
-              cleanup = ENABLE;
-              XXX << "HAL volume handling is enabled"
-                  << std::endl;
-            }
-          }
-          catch(const HalException &e)
-          {
-            ZYPP_CAUGHT(e);
-            XXX << "HAL volume handling is enabled (no property)"
-                << std::endl;
-            disabled = false;
-            cleanup  = REMOVE;
-          }
-
-          // disable
-          if( !disabled)
-          {
-            XXX << "Trying to disable HAL volume handling"
-                << std::endl;
-            try
-            {
-              hal.setDevicePropertyBool(
-                HAL_AUTOMOUNTER_UDI, HAL_AUTOMOUNTER_KEY,
-                true
-              );
-
-              MIL << "Disabled HAL volume handling (automounter)"
-                  << std::endl;
-            }
-            catch(const HalException &e)
-            {
-              ZYPP_CAUGHT(e);
-              WAR << "Unable to disable HAL volume handling (automounter)"
-                  << std::endl;
-
-              cleanup  = NONE;
-            }
-          }
-        }
-        catch(const HalException &e)
-        {
-          ZYPP_CAUGHT(e);
-          WAR << "Unable to disable HAL volume handling (automounter)"
-              << std::endl;
-        }
-#endif // DISABLE_AUTOMOUNTER
-        return cleanup;
-      }
-
-      // -------------------------------------------------------------
-      void
-      restoreAutoMounter(AutoMounterCleanUp cleanup)
-      {
-        using namespace zypp::target::hal;
-
-        if(cleanup == NONE)
-          return;
-
-#if DISABLE_AUTOMOUNTER
-        try
-        {
-          HalContext hal(true);
-
-          if(cleanup == ENABLE)
-          {
-            XXX << "Trying to restore HAL volume handling -- enable"
-                << std::endl;
-
-            hal.setDevicePropertyBool(
-              HAL_AUTOMOUNTER_UDI, HAL_AUTOMOUNTER_KEY,
-              false
-            );
-          }
-          else
-          if(cleanup == REMOVE)
-          {
-            XXX << "Trying to restore HAL volume handling -- remove"
-                << std::endl;
-
-            hal.removeDeviceProperty(
-              HAL_AUTOMOUNTER_UDI, HAL_AUTOMOUNTER_KEY
-            );
-          }
-
-          cleanup = NONE;
-          MIL << "Restored HAL volume handling (automounter)"
-              << std::endl;
-        }
-        catch(const HalException &e)
-        {
-          ZYPP_CAUGHT(e);
-          WAR << "Unable to restore HAL volume handling (automounter)"
-              << std::endl;
-        }
-#endif // DISABLE_AUTOMOUNTER
-      }
-
       ////////////////////////////////////////////////////////////////
     } // anonymous
     //////////////////////////////////////////////////////////////////
@@ -290,15 +150,11 @@ namespace zypp
       friend class MediaManager;
 
       MediaAccessId       last_accessid;
-      AutoMounterCleanUp  am_cleanup;
       ManagedMediaMap     mediaMap;
 
       MediaManager_Impl()
         : last_accessid(0)
-      {
-        // disable automounter
-        am_cleanup = disableAutoMounter();
-      }
+      {}
 
     public:
       ~MediaManager_Impl()
@@ -330,9 +186,6 @@ namespace zypp
 
           // remove all other handlers
           mediaMap.clear();
-
-          // restore automounter state
-          restoreAutoMounter(am_cleanup);
         }
         catch( ... )
         {}
@@ -378,9 +231,7 @@ namespace zypp
       static inline MountEntries
       getMountEntries()
       {
-        // use "/etc/mtab" by default,
-        // fallback to "/proc/mounts"
-        return Mount::getEntries(/* "/etc/mtab" */);
+        return Mount::getEntries();
       }
 
     };
@@ -388,7 +239,7 @@ namespace zypp
 
     //////////////////////////////////////////////////////////////////
     // STATIC
-    zypp::RW_pointer<MediaManager_Impl> MediaManager::m_impl(NULL);
+    zypp::RW_pointer<MediaManager_Impl> MediaManager::m_impl;
 
 
     //////////////////////////////////////////////////////////////////
@@ -498,14 +349,6 @@ namespace zypp
     }
 
     // ---------------------------------------------------------------
-    // STATIC
-    bool
-    MediaManager::downloads(const Url &url)
-    {
-      return MediaAccess::downloads( url);
-    }
-
-    // ---------------------------------------------------------------
     Url
     MediaManager::url(MediaAccessId accessId) const
     {
@@ -561,20 +404,7 @@ namespace zypp
     }
 
     // ---------------------------------------------------------------
-    void
-    MediaManager::attach(MediaAccessId accessId, bool next)
-    {
-      MutexLock glock(g_Mutex);
-
-      ManagedMedia &ref( m_impl->findMM(accessId));
-
-      DBG << "attach(id=" << accessId << ")" << std::endl;
-
-      return ref.handler->attach(next);
-    }
-
-    // ---------------------------------------------------------------
-    void MediaManager::attachDesiredMedia(MediaAccessId accessId)
+    void MediaManager::attach(MediaAccessId accessId)
     {
       MutexLock glock(g_Mutex);
 
@@ -865,6 +695,20 @@ namespace zypp
 
     // ---------------------------------------------------------------
     void
+    MediaManager::setDeltafile(MediaAccessId   accessId,
+                              const Pathname &filename ) const
+    {
+      MutexLock glock(g_Mutex);
+
+      ManagedMedia &ref( m_impl->findMM(accessId));
+
+      ref.checkDesired(accessId);
+
+      ref.handler->setDeltafile(filename);
+    }
+
+    // ---------------------------------------------------------------
+    void
     MediaManager::provideDir(MediaAccessId   accessId,
                              const Pathname &dirname) const
     {