- Added getMountTableMTime() and getMountEntries()
authorMarius Tomaschewski <mt@suse.de>
Mon, 20 Feb 2006 21:24:04 +0000 (21:24 +0000)
committerMarius Tomaschewski <mt@suse.de>
Mon, 20 Feb 2006 21:24:04 +0000 (21:24 +0000)
  to the interface, cleaned up a little bit

zypp/media/MediaManager.cc
zypp/media/MediaManager.h

index df0ccde..d0731a9 100644 (file)
@@ -63,7 +63,7 @@ namespace zypp
           , verifier(m.verifier)
         {}
 
-        ManagedMedia(MediaAccess *h, MediaVerifierBase *v)
+        ManagedMedia(const MediaAccessRef &h, const MediaVerifierRef &v)
           : desired (false)
           , handler (h)
           , verifier(v)
@@ -137,11 +137,20 @@ namespace zypp
 
       Impl()
         : mtab_mtime(0)
+        , mtab_table()
         , last_accessid(0)
       {}
 
       ~Impl()
-      {}
+      {
+        try
+        {
+          mtab_table.clear();
+          mediaMap.clear();
+        }
+        catch( ... )
+        {}
+      }
 
       inline MediaAccessId
       nextAccessId()
@@ -168,16 +177,24 @@ namespace zypp
         return it->second;
       }
 
+      inline time_t
+      getMountTableMTime() const
+      {
+        return zypp::PathInfo("/etc/mtab").mtime();
+      }
+
       inline MountEntries
       getMountEntries()
       {
-        if( mtab_mtime == 0 ||
-            mtab_mtime != zypp::PathInfo("/etc/mtab").mtime())
+        time_t old = mtab_mtime;
+        mtab_mtime = getMountTableMTime();
+        if( old <= 0 || mtab_mtime != old)
         {
           mtab_table = Mount::getEntries("/etc/mtab");
         }
         return mtab_table;
       }
+
     };
 
 
@@ -208,7 +225,9 @@ namespace zypp
       MutexLock glock(g_Mutex);
 
       // create new access handler for it
-      ManagedMedia tmp( new MediaAccess(), new NoVerifier());
+      MediaAccessRef handler( new MediaAccess());
+      MediaVerifierRef verifier( new NoVerifier());
+      ManagedMedia tmp( handler, verifier);
 
       tmp.handler->open(url, preferred_attach_point);
 
@@ -222,55 +241,6 @@ namespace zypp
     }
 
     // ---------------------------------------------------------------
-    /*
-    void
-    MediaManager::reopen(MediaAccessId accessId, const Url &url,
-                         const Pathname & preferred_attach_point)
-    {
-      MutexLock glock(g_Mutex);
-
-      // FIXME: onbsolete
-
-      ManagedMedia &ref( m_impl->findMM(accessId));
-
-      ManagedMedia  tmp( new MediaAccess(), new NoVerifier());
-
-      tmp.handler->open(url, preferred_attach_point);
-
-      // release and close the old one
-      ref.handler->close();
-
-      // assign new one
-      ref = tmp;
-
-      DBG << "Reopened media access id " << accessId
-          << " to " << url.asString() << std::endl;
-    }
-    */
-    
-    // ---------------------------------------------------------------
-    /*
-    bool
-    MediaManager::swap(MediaAccessId idOne, MediaAccessId idTwo)
-    {
-      MutexLock glock(g_Mutex);
-
-      if( idOne != idTwo && m_impl->hasId(idOne) &&  m_impl->hasId(idTwo))
-      {
-        ManagedMedia tmp( m_impl->mediaMap[idOne]);
-        
-        m_impl->mediaMap[idOne] = m_impl->mediaMap[idTwo];
-        m_impl->mediaMap[idTwo] = tmp;
-
-        DBG << "Swapped media access ids "
-            << idOne << " and " << idTwo << std::endl;
-        return true;
-      }
-      return false;
-    }
-    */
-
-    // ---------------------------------------------------------------
     void
     MediaManager::close(MediaAccessId accessId)
     {
@@ -356,63 +326,6 @@ namespace zypp
     }
 
     // ---------------------------------------------------------------
-#if 0
-    void
-    MediaManager::attachDesiredMedia(MediaAccessId accessId,
-                                     bool          eject)
-    {
-      MutexLock glock(g_Mutex);
-
-      if( !m_impl->hasMediaAcc( accessId))
-      {
-        ZYPP_THROW(MediaNotOpenException(
-          "Invalid media access id " + str::numstring(accessId)
-        ));
-      }
-
-      // 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
     MediaManager::release(MediaAccessId accessId, bool eject)
     {
@@ -646,6 +559,23 @@ namespace zypp
       ref.handler->dirInfo(retlist, dirname, dots);
     }
 
+    // ---------------------------------------------------------------
+    time_t
+    MediaManager::getMountTableMTime() const
+    {
+      MutexLock glock(g_Mutex);
+
+      return m_impl->getMountTableMTime();
+    }
+
+    // ---------------------------------------------------------------
+    MountEntries
+    MediaManager::getMountEntries() const
+    {
+      MutexLock glock(g_Mutex);
+
+      return m_impl->getMountEntries();
+    }
 
     // ---------------------------------------------------------------
     AttachedMedia
index c2b82af..1fceba9 100644 (file)
@@ -32,6 +32,10 @@ namespace zypp
 
 
     ///////////////////////////////////////////////////////////////////
+    class MountEntry;
+
+
+    ///////////////////////////////////////////////////////////////////
     typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
     typedef unsigned int                  MediaAccessId;
 
@@ -127,22 +131,6 @@ namespace zypp
       open(const Url &url, const Pathname & preferred_attach_point = "");
 
       /**
-       * 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.
-       *
-       * \returns True, if idOne and and idTwo was both valid.
-      bool
-      swap(MediaAccessId idOne, MediaAccessId idTwo);
-       */
-
-      /**
        * close the media
        */
       void
@@ -189,25 +177,6 @@ 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 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
-      attachDesiredMedia(MediaAccessId accessId, bool eject = true);
-       */
-
-      /**
        * Release the attached media and optionally eject.
        * \throws MediaIsSharedException if eject is true
        *         and media is shared.
@@ -337,18 +306,27 @@ namespace zypp
 
       /**
        */
-      void dirInfo(MediaAccessId           accessId,
-                   std::list<std::string> &retlist,
-                   const Pathname         &dirname,
-                   bool                    dots = true) const;
+      void
+      dirInfo(MediaAccessId           accessId,
+              std::list<std::string> &retlist,
+              const Pathname         &dirname,
+              bool                    dots = true) const;
 
       /**
        */
-      void dirInfo(MediaAccessId           accessId,
-                   filesystem::DirContent &retlist,
-                   const Pathname         &dirname,
-                   bool                   dots = true) const;
+      void
+      dirInfo(MediaAccessId           accessId,
+              filesystem::DirContent &retlist,
+              const Pathname         &dirname,
+              bool                   dots = true) const;
+
+
+    public:
+      time_t
+      getMountTableMTime() const;
 
+      std::vector<MountEntry>
+      getMountEntries() const;
 
     private:
       friend class MediaHandler;