- Removed MediaNr, handled completely by source.
authorMarius Tomaschewski <mt@suse.de>
Fri, 10 Feb 2006 18:59:00 +0000 (18:59 +0000)
committerMarius Tomaschewski <mt@suse.de>
Fri, 10 Feb 2006 18:59:00 +0000 (18:59 +0000)
zypp/media/MediaException.cc
zypp/media/MediaException.h
zypp/media/MediaManager.cc
zypp/media/MediaManager.h

index 3dc6d0ec750731473e5df707270d39f78038c928..8c9df90db8d24aaf332ce69424e74ad0803dbff2 100644 (file)
@@ -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;
     }
 
   /////////////////////////////////////////////////////////////////
index c81efb00fef9ee634fb78e404867d2c7add6c0ad..65384d0830695fb928a63f8305e56a46da0314c8 100644 (file)
@@ -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;
     };
 
   /////////////////////////////////////////////////////////////////
index da44a2cf47ad65d166fdb93d9b65b40aac2364dc..29d190991133ae378f1eca2c14e7dd946cda7fc3 100644 (file)
@@ -46,9 +46,17 @@ namespace zypp
       // STATIC
       static Mutex  g_Mutex;
 
+      /*
+      ** Use a map<ID, struct { handler, verifier, isVerified }> ?
+      */
+      enum MediaVerifyState
+      {
+        NOT_VERIFIED, VERIFIED
+      };
+
       typedef std::map<MediaAccessId, MediaVerifierRef> MediaVfyMap;
       typedef std::map<MediaAccessId, MediaAccessRef>   MediaAccMap;
-
+      typedef std::map<MediaAccessId, MediaVerifyState> 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(
index 26727457a58d127abf9cd8c4d38c61ce4abcc13e..f43ad6f4398514fb22cb731e4f01a71b4272bae7 100644 (file)
@@ -15,7 +15,6 @@
 #include <zypp/media/MediaAccess.h>
 
 #include <zypp/base/NonCopyable.h>
-#include <zypp/base/Deprecated.h>
 #include <zypp/base/PtrTypes.h>
 #include <zypp/Pathname.h>
 #include <zypp/Url.h>
@@ -35,6 +34,8 @@ namespace zypp
     ///////////////////////////////////////////////////////////////////
     typedef zypp::RW_pointer<MediaAccess> 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,