Mailinglist Archive: zypp-commit (500 mails)

< Previous Next >
[zypp-commit] r5879 - in /branches/REFACTORING-10_3/libzypp: tests/zypp/ tests/zypp/data/mediasetaccess/src1/cd1/dir/ tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/ zypp/
  • From: jkupec@xxxxxxxxxxxxxxxx
  • Date: Wed, 04 Jul 2007 13:05:13 -0000
  • Message-id: <20070704130513.E991A35454@xxxxxxxxxxxxxxxx>
Author: jkupec
Date: Wed Jul  4 15:05:13 2007
New Revision: 5879

URL: http://svn.opensuse.org/viewcvs/zypp?rev=5879&view=rev
Log:
MediaSetAccess::provideDir(Pathname,bool,unsigned) added 

Added:
    branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/
    branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file1
    branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file2
    branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/
    branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/file
Modified:
    branches/REFACTORING-10_3/libzypp/tests/zypp/MediaSetAccessTest.cc
    branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.cc
    branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.h

Modified: branches/REFACTORING-10_3/libzypp/tests/zypp/MediaSetAccessTest.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/tests/zypp/MediaSetAccessTest.cc?rev=5879&r1=5878&r2=5879&view=diff
==============================================================================
--- branches/REFACTORING-10_3/libzypp/tests/zypp/MediaSetAccessTest.cc (original)
+++ branches/REFACTORING-10_3/libzypp/tests/zypp/MediaSetAccessTest.cc Wed Jul  4 15:05:13 2007
@@ -148,24 +148,66 @@
   BOOST_CHECK(check_file_exists(file) == true);
 }
 
+/*
+ * Provide directory from src/cd1.
+ */
+void msa_provide_dir(const string &urlstr)
+{
+  Url url(urlstr);
+  MediaSetAccess setaccess(url);
+
+  Pathname dir = setaccess.provideDir("/dir", false, 1);
+
+  Pathname file1 = dir + "/file1";
+  BOOST_CHECK(check_file_exists(file1) == true);
+
+  Pathname file2 = dir + "/file2";
+  BOOST_CHECK(check_file_exists(file2) == true);
+
+  //! \todo ensure nothing else is here (e.g. the 'subdir' direcotry)
+}
+
+
+/*
+ * Provide directory from src/cd1 (recursively).
+ */
+void msa_provide_dirtree(const string &urlstr)
+{
+  Url url(urlstr);
+  MediaSetAccess setaccess(url);
+
+  Pathname dir = setaccess.provideDir("/dir", false, 1);
+
+  Pathname file1 = dir + "/file1";
+  BOOST_CHECK(check_file_exists(file1) == true);
+
+  Pathname file2 = dir + "/file2";
+  BOOST_CHECK(check_file_exists(file2) == true);
+
+  Pathname file3 = dir + "/subdir/file";
+  BOOST_CHECK(check_file_exists(file3) == true);
+}
+
 
 /*
  * 
  * test data dir structure:
  * 
- * src1/
- * src1/cd1/
- * src1/cd1/test.txt
- * src1/cd1/.media1
- * src1/cd2/
- * src1/cd2/test.txt
- * src1/cd2/.mediabad
- * src1/cd3/
- * src1/cd3/test.txt
- * src1/cd3/.media3
- * src2
- * src2/test.txt
- * src2/.media
+ * .
+ * |-- src1
+ * |   |-- cd1
+ * |   |   |-- dir
+ * |   |   |   |-- file1
+ * |   |   |   |-- file2
+ * |   |   |   `-- subdir
+ * |   |   |       `-- file
+ * |   |   `-- test.txt
+ * |   |-- cd2
+ * |   |   `-- test.txt
+ * |   `-- cd3
+ * |       `-- test.txt
+ * `-- src2
+ *     `-- test.txt
  * 
  */
 
@@ -201,6 +243,14 @@
   test->add(BOOST_PARAM_TEST_CASE(&msa_provide_files_single,
                                   (std::string const*)params_single, params_single+1));
 
+  // provide directory
+  test->add(BOOST_PARAM_TEST_CASE(&msa_provide_dir,
+                                  (std::string const*)params, params+1));
+
+  // provide directory tree
+  test->add(BOOST_PARAM_TEST_CASE(&msa_provide_dirtree,
+                                  (std::string const*)params, params+1));
+
   return test;
 }
 

Added: branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file1
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file1?rev=5879&view=auto
==============================================================================
--- branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file1 (added)
+++ branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file1 Wed Jul  4 15:05:13 2007
@@ -0,0 +1 @@
+this is a file from dir

Added: branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file2
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file2?rev=5879&view=auto
==============================================================================
--- branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file2 (added)
+++ branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/file2 Wed Jul  4 15:05:13 2007
@@ -0,0 +1 @@
+Occifer! I'm not as think as you stoned I am!

Added: branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/file
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/file?rev=5879&view=auto
==============================================================================
--- branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/file (added)
+++ branches/REFACTORING-10_3/libzypp/tests/zypp/data/mediasetaccess/src1/cd1/dir/subdir/file Wed Jul  4 15:05:13 2007
@@ -0,0 +1 @@
+this is a file from subdir

Modified: branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.cc
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.cc?rev=5879&r1=5878&r2=5879&view=diff
==============================================================================
--- branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.cc (original)
+++ branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.cc Wed Jul  4 15:05:13 2007
@@ -308,6 +308,136 @@
     return media_mgr.localPath( media, file );
   }
 
+
+  Pathname MediaSetAccess::provideDir(const Pathname & dir,
+                                      bool recursive,
+                                      unsigned media_nr)
+  {
+    callback::SendReport<media::MediaChangeReport> report;
+    media::MediaManager media_mgr;
+
+    // get the mediaId, but don't try to attach it here
+    media::MediaAccessId _media = getMediaAccessId(media_nr);
+    do
+    {
+      try
+      {
+        DBG << "Going to try provide direcotry " << dir
+            << (recursive ? " (recursively)" : "")
+            << " from media nr. " << media_nr << endl;
+
+        // try to attach the media
+        if (!media_mgr.isAttached(_media))
+          media_mgr.attachDesiredMedia(_media);
+
+        _media = getMediaAccessId(media_nr); // in case of redirect
+
+        if (recursive)
+          media_mgr.provideDirTree(_media, dir);
+        else
+          media_mgr.provideDir(_media, dir);
+
+        break; // quit the retry loop
+      }
+      catch (Exception & excp)
+      {
+        ZYPP_CAUGHT(excp);
+        media::MediaChangeReport::Action user;
+
+        do
+        {
+          DBG << "Media couldn't provide dir " << dir << ", releasing." << endl;
+          try
+          {
+            media_mgr.release (_media, false);
+          }
+          catch (const Exception & excpt_r)
+          {
+            ZYPP_CAUGHT(excpt_r);
+            ERR << "Failed to release media " << _media << endl;
+          }
+
+          //MIL << "Releasing all medias of all sources" << endl;
+          try
+          {
+            //! \todo do we need replacement for this at all?
+            //zypp::SourceManager::sourceManager()->releaseAllSources();
+          }
+          catch (const zypp::Exception& excpt_r)
+          {
+            ZYPP_CAUGHT(excpt_r);
+            ERR << "Failed to release all sources" << endl;
+          }
+
+          // set up the reason
+          media::MediaChangeReport::Error reason = media::MediaChangeReport::INVALID;
+
+          if (typeid(excp) == typeid(media::MediaFileNotFoundException)
+              || typeid(excp) == typeid(media::MediaNotAFileException))
+          {
+            reason = media::MediaChangeReport::NOT_FOUND;
+          }
+          else if (typeid(excp) == typeid( media::MediaNotDesiredException)
+              || typeid(excp) == typeid(media::MediaNotAttachedException))
+          {
+            reason = media::MediaChangeReport::WRONG;
+          }
+
+          user = report->requestMedia(Repository::noRepository,
+                                      media_nr,
+                                      reason,
+                                      excp.asUserString());
+
+          DBG << "ProvideFile exception caught, callback answer: " << user << endl;
+
+          if (user == media::MediaChangeReport::ABORT)
+          {
+            DBG << "Aborting" << endl;
+            ZYPP_RETHROW ( excp );
+          }
+          else if (user == media::MediaChangeReport::EJECT)
+          {
+            DBG << "Eject: try to release" << endl;
+            try
+            {
+              //! \todo do we need replacement for this at all?
+              // zypp::SourceManager::sourceManager()->releaseAllSources();
+            }
+            catch (const zypp::Exception& excpt_r)
+            {
+              ZYPP_CAUGHT(excpt_r);
+              ERR << "Failed to release all sources" << endl;
+            }
+            media_mgr.release (_media, true); // one more release needed for eject
+            // FIXME: this will not work, probably
+          }
+          else if (user == media::MediaChangeReport::RETRY ||
+              user == media::MediaChangeReport::CHANGE_URL)
+          {
+            // retry
+            DBG << "Going to try again" << endl;
+
+            // not attaching, media set will do that for us
+            // this could generate uncaught exception (#158620)
+
+            break;
+          }
+          else
+          {
+            DBG << "Don't know, let's ABORT" << endl;
+
+            ZYPP_RETHROW (excp);
+          }
+        }
+        while (user == media::MediaChangeReport::EJECT);
+      }
+      // retry or change URL
+    }
+    while (true);
+
+    return media_mgr.localPath(_media, dir);
+  }
+
   media::MediaAccessId MediaSetAccess::getMediaAccessId (media::MediaNr medianr)
   {
     media::MediaManager media_mgr;

Modified: branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.h
URL: http://svn.opensuse.org/viewcvs/zypp/branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.h?rev=5879&r1=5878&r2=5879&view=diff
==============================================================================
--- branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.h (original)
+++ branches/REFACTORING-10_3/libzypp/zypp/MediaSetAccess.h Wed Jul  4 15:05:13 2007
@@ -102,6 +102,11 @@
        * Provides \a file from media \a media_nr. 
        */
       Pathname provideFile(const Pathname & file, unsigned media_nr = 1 );
+      
+      /**
+       * 
+       */
+      Pathname provideDir(const Pathname & file, bool recursive, unsigned media_nr = 1);
 
       /**
        * check if a file exists on the specified media

--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages