- release all attached media before attempting to eject (#293428)
authorJan Kupec <jkupec@suse.cz>
Tue, 25 Sep 2007 09:07:54 +0000 (09:07 +0000)
committerJan Kupec <jkupec@suse.cz>
Tue, 25 Sep 2007 09:07:54 +0000 (09:07 +0000)
zypp/MediaSetAccess.cc
zypp/media/MediaManager.cc
zypp/media/MediaManager.h

index b9427b33ab35b24d2d3008bde4f60c8798578464..27a00a73b03b043398ce38f1f18213d33afae008 100644 (file)
@@ -166,17 +166,8 @@ IMPL_PTR_TYPE(MediaSetAccess);
           else if ( user == media::MediaChangeReport::EJECT )
           {
             DBG << "Eject: try to release" << endl;
-            try
-            {
-              //zypp::SourceManager::sourceManager()->releaseAllSources();
-            }
-            catch (const zypp::Exception& excpt_r)
-            {
-              ZYPP_CAUGHT(excpt_r);
-              ERR << "Failed to release all sources" << endl;
-            }
+            media_mgr.releaseAll();
             media_mgr.release (media, true); // one more release needed for eject
-            // FIXME: this will not work, probably
           }
           else if ( user == media::MediaChangeReport::RETRY  ||
             user == media::MediaChangeReport::CHANGE_URL )
@@ -283,17 +274,8 @@ IMPL_PTR_TYPE(MediaSetAccess);
           else if ( user == media::MediaChangeReport::EJECT )
           {
             DBG << "Eject: try to release" << endl;
-            try
-            {
-              //zypp::SourceManager::sourceManager()->releaseAllSources();
-            }
-            catch (const zypp::Exception& excpt_r)
-            {
-              ZYPP_CAUGHT(excpt_r);
-              ERR << "Failed to release all sources" << endl;
-            }
+            media_mgr.releaseAll();
             media_mgr.release (media, true); // one more release needed for eject
-            // FIXME: this will not work, probably
           }
           else if ( user == media::MediaChangeReport::RETRY  ||
             user == media::MediaChangeReport::CHANGE_URL )
@@ -414,18 +396,8 @@ IMPL_PTR_TYPE(MediaSetAccess);
           else if (user == media::MediaChangeReport::EJECT)
           {
             DBG << "Eject: try to release" << endl;
-            try
-            {
-              //! \todo do we need replacement for this at all?
-              // zypp::SourceManager::sourceManager()->releaseAllSources();
-            }
-            catch (const zypp::Exception& excpt_r)
-            {
-              ZYPP_CAUGHT(excpt_r);
-              ERR << "Failed to release all sources" << endl;
-            }
+            media_mgr.releaseAll();
             media_mgr.release (_media, true); // one more release needed for eject
-            // FIXME: this will not work, probably
           }
           else if (user == media::MediaChangeReport::RETRY ||
               user == media::MediaChangeReport::CHANGE_URL)
index d24f99299756f1c4c19af5195d500ec19c9558c2..cacc02da63ec626b691906f4c62855bd14596389 100644 (file)
@@ -683,6 +683,43 @@ namespace zypp
       ref.handler->release(eject);
     }
 
+    // ---------------------------------------------------------------
+    void
+    MediaManager::releaseAll()
+    {
+      MutexLock glock(g_Mutex);
+
+      MIL << "Releasing all attached media" << std::endl;
+
+      ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
+      for( ; m != m_impl->mediaMap.end(); ++m)
+      {
+        if( m->second.handler->dependsOnParent())
+          continue;
+
+        try
+        {
+          if(m->second.handler->isAttached())
+          {
+            DBG << "Releasing media id " << m->first << std::endl;
+            m->second.desired  = false;
+            m->second.handler->release(false);
+          }
+          else
+          {
+            DBG << "Media id " << m->first << " not attached " << std::endl;
+          }
+        }
+        catch(const MediaException & e)
+        {
+          ZYPP_CAUGHT(e);
+          ERR << "Failed to release media id " << m->first << std::endl;
+        }
+      }
+
+      MIL << "Exit" << std::endl;
+    }
+
     // ---------------------------------------------------------------
     void
     MediaManager::disconnect(MediaAccessId accessId)
index 0a0a6e3683e66d3cc5f9ac880efff8069864ae96..d92647e8a513e04cde235b251497b26461aba0b7 100644 (file)
@@ -602,6 +602,12 @@ namespace zypp
       void
       release(MediaAccessId accessId, bool eject = false);
 
+      /**
+       * Release all attached media.
+       */
+      void
+      releaseAll();
+
       /**
        * Disconnect a remote media.
        *