From 15c9af4113fedb6d5350cb975928b5cce1f08aa2 Mon Sep 17 00:00:00 2001 From: Marius Tomaschewski Date: Fri, 10 Feb 2006 18:59:00 +0000 Subject: [PATCH] - Removed MediaNr, handled completely by source. --- zypp/media/MediaException.cc | 7 +- zypp/media/MediaException.h | 22 ++++- zypp/media/MediaManager.cc | 163 +++++++++++++++++++---------------- zypp/media/MediaManager.h | 62 +++++-------- 4 files changed, 135 insertions(+), 119 deletions(-) diff --git a/zypp/media/MediaException.cc b/zypp/media/MediaException.cc index 3dc6d0ec7..8c9df90db 100644 --- a/zypp/media/MediaException.cc +++ b/zypp/media/MediaException.cc @@ -136,7 +136,12 @@ namespace zypp std::ostream & MediaNotDesiredException::dumpOn( std::ostream & str ) const { - return str << "Media source " << _url << " does not contain the desired media number: " << _nr << endl; + return str << "Media source " << _url << " does not contain the desired media" << endl; + } + + std::ostream & MediaIsSharedException::dumpOn( std::ostream & str ) const + { + return str << "Media " << _name << " is in use by another instance" << endl; } ///////////////////////////////////////////////////////////////// diff --git a/zypp/media/MediaException.h b/zypp/media/MediaException.h index c81efb00f..65384d083 100644 --- a/zypp/media/MediaException.h +++ b/zypp/media/MediaException.h @@ -354,18 +354,32 @@ namespace zypp class MediaNotDesiredException : public MediaException { public: - MediaNotDesiredException(const Url & url_r, - unsigned int mediaNr) + MediaNotDesiredException(const Url & url_r) : MediaException() , _url(url_r.asString()) - , _nr(mediaNr) {} virtual ~MediaNotDesiredException() throw() {}; protected: virtual std::ostream & dumpOn( std::ostream & str ) const; private: std::string _url; - unsigned int _nr; + }; + + class MediaIsSharedException : public MediaException + { + public: + /** + * \param name A media source as string (see MediaSource class). + */ + MediaIsSharedException(const std::string &name) + : MediaException() + , _name(name) + {} + virtual ~MediaIsSharedException() throw() {}; + protected: + virtual std::ostream & dumpOn( std::ostream & str ) const; + private: + std::string _name; }; ///////////////////////////////////////////////////////////////// diff --git a/zypp/media/MediaManager.cc b/zypp/media/MediaManager.cc index da44a2cf4..29d190991 100644 --- a/zypp/media/MediaManager.cc +++ b/zypp/media/MediaManager.cc @@ -46,9 +46,17 @@ namespace zypp // STATIC static Mutex g_Mutex; + /* + ** Use a map ? + */ + enum MediaVerifyState + { + NOT_VERIFIED, VERIFIED + }; + typedef std::map MediaVfyMap; typedef std::map MediaAccMap; - + typedef std::map MediaVStMap; //////////////////////////////////////////////////////////////// } // anonymous @@ -66,6 +74,7 @@ namespace zypp public: MediaVfyMap mediaVfyMap; MediaAccMap mediaAccMap; + MediaVStMap mediaVStMap; Impl() : mtab_mtime(0) @@ -140,6 +149,7 @@ namespace zypp m_impl->mediaAccMap[nextId] = accRef; m_impl->mediaVfyMap[nextId] = vfyRef; + m_impl->mediaVStMap[nextId] = NOT_VERIFIED; DBG << "Opened new media access using id " << nextId << " to " << url.asString() << std::endl; @@ -147,6 +157,7 @@ namespace zypp } // --------------------------------------------------------------- + /* void MediaManager::reopen(MediaAccessId accessId, const Url &url, const Pathname & preferred_attach_point) @@ -169,11 +180,13 @@ namespace zypp // assign new one m_impl->mediaAccMap[accessId] = accRef; + m_impl->mediaVStMap[accessId] = NOT_VERIFIED; DBG << "Reopened media access id " << accessId << " to " << url.asString() << std::endl; } - + */ + // --------------------------------------------------------------- /* bool @@ -183,6 +196,7 @@ namespace zypp if( m_impl->hasMediaAcc(idOne) && m_impl->hasMediaAcc(idTwo)) { + // FIXME: swich verifier and its state as well MediaAccessRef tmp( m_impl->mediaAccMap[idOne]); m_impl->mediaAccMap[idOne] = m_impl->mediaAccMap[idTwo]; @@ -212,6 +226,7 @@ namespace zypp m_impl->mediaAccMap[accessId]->close(); m_impl->mediaAccMap.erase(accessId); m_impl->mediaVfyMap.erase(accessId); + m_impl->mediaVStMap.erase(accessId); } // --------------------------------------------------------------- @@ -302,10 +317,10 @@ namespace zypp } // --------------------------------------------------------------- +#if 0 void - MediaManager::attachMediaNr(MediaAccessId accessId, - MediaNr mediaNr, - bool eject) + MediaManager::attachDesiredMedia(MediaAccessId accessId, + bool eject) { MutexLock glock(g_Mutex); @@ -316,8 +331,47 @@ namespace zypp )); } + // this should never happen, since we allways add a NoVerifier! + if( !m_impl->hasVerifier( accessId)) + ZYPP_THROW(MediaException("Invalid verifier detected")); + + // check the attached media first.. + if( m_impl->mediaAccMap[accessId]->isAttached()) + { + bool desired; + try { + desired = m_impl->mediaVfyMap[accessId]->isDesiredMedia( + m_impl->mediaAccMap[accessId] + ); + } + catch(const zypp::Exception &e) { + ZYPP_CAUGHT(e); + desired = false; + } + + if( desired) { + // we found it already attached + return; + } + else { + try + { + m_impl->mediaAccMap[accessId]->release(eject); + } + /* + ** FIXME: remember it for later + ** + catch(const zypp::MediaIsSharedException &e) { + ZYPP_CAUGHT(e); + } + */ + // allow to escape umount exceptions + } + } + // FIXME: implement it. } +#endif // --------------------------------------------------------------- void @@ -370,7 +424,7 @@ namespace zypp // --------------------------------------------------------------- bool - MediaManager::isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr) const + MediaManager::isDesiredMedia(MediaAccessId accessId) const { MutexLock glock(g_Mutex); @@ -384,17 +438,19 @@ namespace zypp bool ok; try { ok = m_impl->mediaVfyMap[accessId]->isDesiredMedia( - m_impl->mediaAccMap[accessId], mediaNr + m_impl->mediaAccMap[accessId] ); } - catch( ... ) { ok = false; } + catch(const zypp::Exception &e) { + ZYPP_CAUGHT(e); + ok = false; + } return ok; } // --------------------------------------------------------------- bool MediaManager::isDesiredMedia(MediaAccessId accessId, - MediaNr mediaNr, const MediaVerifierRef &verifier) const { MutexLock glock(g_Mutex); @@ -409,10 +465,13 @@ namespace zypp bool ok; try { ok = v->isDesiredMedia( - m_impl->mediaAccMap[accessId], mediaNr + m_impl->mediaAccMap[accessId] ); } - catch( ... ) { ok = false; } + catch(const zypp::Exception &e) { + ZYPP_CAUGHT(e); + ok = false; + } return ok; } @@ -457,38 +516,21 @@ namespace zypp // --------------------------------------------------------------- void MediaManager::provideFile(MediaAccessId accessId, - MediaNr mediaNr, const Pathname &filename, bool cached, bool checkonly) const { MutexLock glock(g_Mutex); - if( !isDesiredMedia(accessId, mediaNr)) + // FIXME: cache the results + /* + if( !isDesiredMedia(accessId)) { ZYPP_THROW(MediaNotDesiredException( - m_impl->mediaAccMap[accessId]->url(), mediaNr - )); - } - - m_impl->mediaAccMap[accessId]->provideFile(filename, cached, checkonly); - } - - // --------------------------------------------------------------- - void - MediaManager::provideFile(MediaAccessId accessId, - const Pathname &filename, - bool cached, - bool checkonly) const - { - MutexLock glock(g_Mutex); - - if( !m_impl->hasMediaAcc( accessId)) - { - ZYPP_THROW(MediaNotOpenException( - "Invalid media access id " + str::numstring(accessId) + m_impl->mediaAccMap[accessId]->url() )); } + */ m_impl->mediaAccMap[accessId]->provideFile(filename, cached, checkonly); } @@ -496,34 +538,19 @@ namespace zypp // --------------------------------------------------------------- void MediaManager::provideDir(MediaAccessId accessId, - MediaNr mediaNr, const Pathname &dirname) const { MutexLock glock(g_Mutex); - if( !isDesiredMedia(accessId, mediaNr)) + // FIXME: cache the results + /* + if( !isDesiredMedia(accessId)) { ZYPP_THROW(MediaNotDesiredException( - m_impl->mediaAccMap[accessId]->url(), mediaNr - )); - } - - m_impl->mediaAccMap[accessId]->provideDir(dirname); - } - - // --------------------------------------------------------------- - void - MediaManager::provideDir(MediaAccessId accessId, - const Pathname &dirname) const - { - MutexLock glock(g_Mutex); - - if( !m_impl->hasMediaAcc( accessId)) - { - ZYPP_THROW(MediaNotOpenException( - "Invalid media access id " + str::numstring(accessId) + m_impl->mediaAccMap[accessId]->url() )); } + */ m_impl->mediaAccMap[accessId]->provideDir(dirname); } @@ -531,34 +558,19 @@ namespace zypp // --------------------------------------------------------------- void MediaManager::provideDirTree(MediaAccessId accessId, - MediaNr mediaNr, const Pathname &dirname) const { MutexLock glock(g_Mutex); - if( !isDesiredMedia(accessId, mediaNr)) + // FIXME: cache the results + /* + if( !isDesiredMedia(accessId)) { ZYPP_THROW(MediaNotDesiredException( - m_impl->mediaAccMap[accessId]->url(), mediaNr - )); - } - - m_impl->mediaAccMap[accessId]->provideDirTree(dirname); - } - - // --------------------------------------------------------------- - void - MediaManager::provideDirTree(MediaAccessId accessId, - const Pathname &dirname) const - { - MutexLock glock(g_Mutex); - - if( !m_impl->hasMediaAcc( accessId)) - { - ZYPP_THROW(MediaNotOpenException( - "Invalid media access id " + str::numstring(accessId) + m_impl->mediaAccMap[accessId]->url() )); } + */ m_impl->mediaAccMap[accessId]->provideDirTree(dirname); } @@ -570,6 +582,7 @@ namespace zypp { MutexLock glock(g_Mutex); + // FIXME: check isDesiredMedia(accessId) ??? if( !m_impl->hasMediaAcc( accessId)) { ZYPP_THROW(MediaNotOpenException( @@ -587,6 +600,7 @@ namespace zypp { MutexLock glock(g_Mutex); + // FIXME: check isDesiredMedia(accessId) ??? if( !m_impl->hasMediaAcc( accessId)) { ZYPP_THROW(MediaNotOpenException( @@ -605,6 +619,7 @@ namespace zypp { MutexLock glock(g_Mutex); + // FIXME: check isDesiredMedia(accessId) ??? if( !m_impl->hasMediaAcc( accessId)) { ZYPP_THROW(MediaNotOpenException( @@ -624,6 +639,7 @@ namespace zypp { MutexLock glock(g_Mutex); + // FIXME: check isDesiredMedia(accessId) ??? if( !m_impl->hasMediaAcc( accessId)) { ZYPP_THROW(MediaNotOpenException( @@ -643,6 +659,7 @@ namespace zypp { MutexLock glock(g_Mutex); + // FIXME: check isDesiredMedia(accessId) ??? if( !m_impl->hasMediaAcc( accessId)) { ZYPP_THROW(MediaNotOpenException( diff --git a/zypp/media/MediaManager.h b/zypp/media/MediaManager.h index 26727457a..f43ad6f43 100644 --- a/zypp/media/MediaManager.h +++ b/zypp/media/MediaManager.h @@ -15,7 +15,6 @@ #include #include -#include #include #include #include @@ -35,6 +34,8 @@ namespace zypp /////////////////////////////////////////////////////////////////// typedef zypp::RW_pointer MediaAccessRef; typedef unsigned int MediaAccessId; + + // OBSOLETE HERE: typedef MediaAccessId MediaId; typedef unsigned int MediaNr; @@ -58,13 +59,10 @@ namespace zypp /* ** Check if the specified attached media contains - ** the desired media number (e.g. SLES10 CD1). + ** the desired media (e.g. SLES10 CD1). */ virtual bool - isDesiredMedia(const MediaAccessRef &ref, MediaNr mediaNr) - { - return false; - } + isDesiredMedia(const MediaAccessRef &ref) = 0; }; @@ -90,8 +88,9 @@ namespace zypp ** the desired media number. Always return true. */ virtual bool - isDesiredMedia(const MediaAccessRef &ref, MediaNr mediaNr) + isDesiredMedia(const MediaAccessRef &ref) { + (void)ref; return true; } }; @@ -130,10 +129,10 @@ namespace zypp /** * Open new access handler with specifier url and attach * point reusing the specified accessId. - */ void reopen(MediaAccessId accessId, const Url &url, const Pathname & preferred_attach_point = ""); + */ /** * Swap access handlers of idOne and idTwo. @@ -190,24 +189,28 @@ namespace zypp attach(MediaAccessId accessId, bool next = false); /** + * FIXME: Jiri, do you want this one? + * * Attach the media if needed and verify, if desired - * media number is avaliable. If the access handler - * supports multiple drives (e.g. CD/DVD), all drives - * are verified. + * media is avaliable. If the access handler supports + * multiple drives (e.g. CD/DVD), all drives will be + * verified. + * On success, the media is attached and verified. + * On failure, the media is released and optionally + * ejected if possible (not shared). * * \throws MediaNotDesiredException if unable to find * desired media in any drive. * \throws FIXME if all drives are in use and no one * was ejected. - */ void - attachMediaNr(MediaAccessId accessId, MediaNr mediaNr, - bool eject = true); + attachDesiredMedia(MediaAccessId accessId, bool eject = true); + */ /** * Release the attached media and optionally eject. - * \throws exception if eject is true and media is - * shared. + * \throws MediaIsSharedException if eject is true + * and media is shared. */ void release(MediaAccessId accessId, bool eject = false); @@ -241,7 +244,7 @@ namespace zypp * \return True if desired media is attached. */ bool - isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr) const; + isDesiredMedia(MediaAccessId accessId) const; /** * Ask the specified verifier if the attached @@ -249,7 +252,7 @@ namespace zypp * \return True if desired media is attached. */ bool - isDesiredMedia(MediaAccessId accessId, MediaNr mediaNr, + isDesiredMedia(MediaAccessId accessId, const MediaVerifierRef &verifier) const; /** @@ -278,7 +281,6 @@ namespace zypp * on the media. * * \param accessId The media access id to use. - * \param mediaNr The desired media number that should be on the media. * \param cached If cached is set to true, the function checks, if * the file already exists and doesn't download it again * if it does. Currently only the existence is checked, @@ -289,48 +291,26 @@ namespace zypp * returned always. * * \throws MediaException - * - * \deprecated checking the media number on each access. */ void - provideFile(MediaAccessId accessId, - MediaNr mediaNr, - const Pathname &filename, - bool cached = false, - bool checkonly = false) const ZYPP_DEPRECATED; - - void provideFile(MediaAccessId accessId, const Pathname &filename, bool cached = false, bool checkonly = false) const; /** - * \deprecated checking the media number on each access. */ void - provideDir(MediaAccessId accessId, - MediaNr mediaNr, - const Pathname &dirname) const ZYPP_DEPRECATED; - - void provideDir(MediaAccessId accessId, const Pathname &dirname) const; /** - * \deprecated checking the media number on each access. */ void - provideDirTree(MediaAccessId accessId, - MediaNr mediaNr, - const Pathname &dirname) const ZYPP_DEPRECATED; - - void provideDirTree(MediaAccessId accessId, const Pathname &dirname) const; /** - * \deprecated checking the media number on each access. */ void releaseFile(MediaAccessId accessId, -- 2.34.1