added functions to reattach all non-mounted sources
authorJiri Srain <jsrain@suse.cz>
Tue, 28 Feb 2006 14:59:12 +0000 (14:59 +0000)
committerJiri Srain <jsrain@suse.cz>
Tue, 28 Feb 2006 14:59:12 +0000 (14:59 +0000)
zypp/Source.cc
zypp/Source.h
zypp/SourceManager.cc
zypp/SourceManager.h
zypp/source/MediaSet.cc
zypp/source/MediaSet.h
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h

index 5d04fa6..84fb5ee 100644 (file)
@@ -137,6 +137,10 @@ namespace zypp
 
   void Source_Ref::release()
   { _pimpl->release(); }
+
+  void Source_Ref::reattach(const Pathname &attach_point,
+                           bool temporary)
+  { _pimpl->reattach(attach_point, temporary)
   
   media::MediaVerifierRef Source_Ref::verifier(unsigned media_nr)
   { return _pimpl->verifier(media_nr); }
index b1fcaae..f2a6e77 100644 (file)
@@ -138,6 +138,15 @@ namespace zypp
     void release();
 
     /**
+     * Reattach the source if it is not mounted, but downloaded,
+     * to different directory
+     *
+     * \throws Exception
+     */
+    void reattach(const Pathname &attach_point,
+                 bool temporary = false);
+
+    /**
      * Provide a media verifier suitable for the given media number
      */
     media::MediaVerifierRef verifier(unsigned media_nr);
index 9647730..b540571 100644 (file)
@@ -98,6 +98,17 @@ namespace zypp
     }
   }
 
+  void SourceManager::reattachSources(const Pathname &attach_point,
+                                     bool temporary)
+  {
+    for (SourceMap::iterator it = _sources.begin();
+        it != _sources.end(); it++)
+    {
+      it->second->reattach(attach_point, temporary);
+    }
+  }
+
+
   void SourceManager::removeSource(const std::string & alias_r)
   {
     for (SourceMap::iterator it = _sources.begin(); it != _sources.end(); ++it)
index 8b05c9d..ccde1b8 100644 (file)
@@ -138,6 +138,15 @@ namespace zypp
     void releaseAllSources();
 
     /**
+     * Reattach all sources which are not mounted, but downloaded,
+     * to different directory
+     *
+     * \throws Exception
+     */
+    void reattachSources(const Pathname &attach_point,
+                        bool temporary = false);
+
+    /**
      * Disable all registered sources
      */
 #warning: this could be done by providing iterator-like methods
index f53e2ee..f3b810c 100644 (file)
@@ -39,6 +39,21 @@ namespace zypp
       medias[medianr] = media_id;
     }
 
+    void MediaSet::reattach(const Pathname &attach_point,
+                           bool temporary)
+    {
+      media::MediaManager media_mgr;
+      for (MediaMap::iterator it = medias.begin(); it != medias.end(); it++)
+      {
+       Url url = media_mgr.url(it->second);
+       std::string scheme = url.getScheme();
+       if (scheme == "http" || scheme == "ftp" || scheme == "https" || scheme == "ftps")
+       {
+         media_mgr.reattach(it->second, attach_point, temporary);
+       }
+      }
+    }
+
     void MediaSet::reset()
     {
       medias = MediaMap();
index 19ebb07..16fd510 100644 (file)
@@ -46,6 +46,14 @@ namespace zypp
       media::MediaAccessId getMediaAccessId (media::MediaNr medianr, bool no_attach = false);
       /** Redirect specified media to a new MediaId */
       void redirect (media::MediaNr medianr, media::MediaAccessId media_id);
+      /**
+       * Reattach the source if it is not mounted, but downloaded,
+       * to different directory
+       *
+       * \throws Exception
+       */
+      void reattach(const Pathname &attach_point,
+                   bool temporary = false);
       /** Reset the handles to the medias */
       void reset();
       /**
index a898158..ece1e7a 100644 (file)
@@ -211,6 +211,11 @@ namespace zypp
       media::MediaAccessId id = media_mgr.open(new_url);
       _media_set->redirect(media_nr, id);
     }
+    void SourceImpl::reattach(const Pathname &attach_point,
+                             bool temporary)
+    {
+      _media_set->reattach(attach_point, temporary);
+    }
 
     void SourceImpl::release()
     {
index d116b5e..d7d5bf6 100644 (file)
@@ -158,6 +158,14 @@ namespace zypp
 
       virtual void redirect(unsigned media_nr, const Url & new_url);
       /**
+       * Reattach the source if it is not mounted, but downloaded,
+       * to different directory
+       *
+       * \throws Exception
+       */
+      void reattach(const Pathname &attach_point,
+                   bool temporary = false);
+      /**
        * Release all medias attached by the source
        */
       void release();