- Added check to reattach if the media src for iso loop.
authorMarius Tomaschewski <mt@suse.de>
Tue, 28 Feb 2006 16:22:49 +0000 (16:22 +0000)
committerMarius Tomaschewski <mt@suse.de>
Tue, 28 Feb 2006 16:22:49 +0000 (16:22 +0000)
- Moved isUseableAttachPoint from MediaHandler, extended.

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

index f5426cc..8e1c3a5 100644 (file)
@@ -335,8 +335,19 @@ namespace zypp
 
       ManagedMedia &ref( m_impl->findMM(accessId));
 
-      (void)temporary;
-      return ref.handler->reattach(attach_point);
+      ManagedMediaMap::iterator m(m_impl->mediaMap.begin());
+      for( ; m != m_impl->mediaMap.end(); ++m)
+      {
+        // don't allow a reattach if it is the
+        // source for an loop mounted ISO file
+        if( m->second.handler->dependsOnParent(accessId))
+        {
+          ZYPP_THROW(MediaIsSharedException(
+            m->second.handler->url().asString()
+          ));
+        }
+      }
+      return ref.handler->reattach(attach_point, temporary);
     }
 
     // ---------------------------------------------------------------
@@ -621,6 +632,72 @@ namespace zypp
     }
 
     // ---------------------------------------------------------------
+    bool
+    MediaManager::isUseableAttachPoint(const Pathname &path) const
+    {
+      if( path.empty() || path == "/" || !PathInfo(path).isDir())
+        return false;
+
+      MutexLock glock(g_Mutex);
+
+      //
+      // check against our current attach points
+      //
+      ManagedMediaMap::const_iterator m(m_impl->mediaMap.begin());
+      for( ; m != m_impl->mediaMap.end(); ++m)
+      {
+        AttachedMedia ret = m->second.handler->attachedMedia();
+        if( ret.mediaSource && ret.attachPoint)
+        {
+          std::string mnt(ret.attachPoint->path.asString());
+          std::string our(path.asString());
+
+          if( our == mnt)
+          {
+            // already used as attach point
+            return false;
+          }
+          else
+          if( mnt.size() > our.size()   &&
+              mnt.at(our.size()) == '/' &&
+             !mnt.compare(0, our.size(), our))
+          {
+            // mountpoint is bellow of path
+            // (would hide the content)
+            return false;
+          }
+        }
+      }
+
+      //
+      // check against system mount entries
+      //
+      MountEntries  entries( m_impl->getMountEntries());
+      MountEntries::const_iterator e;
+      for( e = entries.begin(); e != entries.end(); ++e)
+      {
+        std::string mnt(Pathname(e->dir).asString());
+        std::string our(path.asString());
+
+        if( our == mnt)
+        {
+          // already used as mountpoint
+          return false;
+        }
+        else
+        if( mnt.size() > our.size()   &&
+            mnt.at(our.size()) == '/' &&
+           !mnt.compare(0, our.size(), our))
+        {
+          // mountpoint is bellow of path
+          // (would hide the content)
+          return false;
+        }
+      }
+      return true;
+    }
+
+    // ---------------------------------------------------------------
     AttachedMedia
     MediaManager::getAttachedMedia(MediaAccessId &accessId) const
     {
index 92a2176..45e2ee3 100644 (file)
@@ -230,6 +230,7 @@ namespace zypp
       /**
        * Reattach to a new attach point.
        *
+       * \param accessId A media access Id.
        * \param attach_point A new attach point directory.
        * \param temporary    Whether to reattach to a temporary
        *      attach point bellow of \p attach_point and cleanup
@@ -239,9 +240,10 @@ namespace zypp
        * \throws MediaNotOpenException
        * \throws MediaNotSupportedException
        */
-      void reattach(MediaAccessId   accessId,
-                    const Pathname &attach_point,
-                    bool            temporary = false);
+      void
+      reattach(MediaAccessId   accessId,
+               const Pathname &attach_point,
+               bool            temporary = false);
 
       /**
        * Release the attached media and optionally eject.
@@ -418,6 +420,9 @@ namespace zypp
       std::vector<MountEntry>
       getMountEntries() const;
 
+      bool
+      isUseableAttachPoint(const Pathname &path) const;
+
     private:
       friend class MediaHandler;