From a2072bc1cbb537ace94071632a86b086003e70ed Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Tue, 25 Sep 2007 09:07:54 +0000 Subject: [PATCH] - release all attached media before attempting to eject (#293428) --- zypp/MediaSetAccess.cc | 34 +++------------------------------- zypp/media/MediaManager.cc | 37 +++++++++++++++++++++++++++++++++++++ zypp/media/MediaManager.h | 6 ++++++ 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/zypp/MediaSetAccess.cc b/zypp/MediaSetAccess.cc index b9427b33a..27a00a73b 100644 --- a/zypp/MediaSetAccess.cc +++ b/zypp/MediaSetAccess.cc @@ -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) diff --git a/zypp/media/MediaManager.cc b/zypp/media/MediaManager.cc index d24f99299..cacc02da6 100644 --- a/zypp/media/MediaManager.cc +++ b/zypp/media/MediaManager.cc @@ -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) diff --git a/zypp/media/MediaManager.h b/zypp/media/MediaManager.h index 0a0a6e368..d92647e8a 100644 --- a/zypp/media/MediaManager.h +++ b/zypp/media/MediaManager.h @@ -602,6 +602,12 @@ namespace zypp void release(MediaAccessId accessId, bool eject = false); + /** + * Release all attached media. + */ + void + releaseAll(); + /** * Disconnect a remote media. * -- 2.34.1