Remove error prone methods from OnMediaLocation API to prevent
authorMichael Andres <ma@suse.de>
Fri, 24 Oct 2008 16:18:47 +0000 (16:18 +0000)
committerMichael Andres <ma@suse.de>
Fri, 24 Oct 2008 16:18:47 +0000 (16:18 +0000)
  accidental missuse. (bnc #437328)

VERSION.cmake
package/libzypp.changes
tests/zypp/Fetcher_test.cc
zypp/Fetcher.cc
zypp/OnMediaLocation.h
zypp/repo/yum/Downloader.cc

index 79f4324..f4ac3ff 100644 (file)
 #   changes file. See './mkChangelog -h' for help.
 #
 SET(LIBZYPP_MAJOR "5")
-SET(LIBZYPP_COMPATMINOR "17")
-SET(LIBZYPP_MINOR "18")
+SET(LIBZYPP_COMPATMINOR "19")
+SET(LIBZYPP_MINOR "19")
 SET(LIBZYPP_PATCH "0")
 #
-# LAST RELEASED: 5.18.0 (17)
+# LAST RELEASED: 5.19.0 (19)
 # (The number in parenthesis is LIBZYPP_COMPATMINOR)
 #=======
index 305d5e5..3c94205 100644 (file)
@@ -1,4 +1,12 @@
 -------------------------------------------------------------------
+Fri Oct 24 18:12:34 CEST 2008 - ma@suse.de
+
+- Remove error prone methods from OnMediaLocation API to prevent 
+  accidental missuse. (bnc #437328)
+- revision 11487
+- version 5.19.0 (19)
+
+-------------------------------------------------------------------
 Fri Oct 24 16:07:45 CEST 2008 - ma@suse.de
 
 - Provide the /etc/products.d enties filename as Product::referenceFilename.
index 05b096f..fda8ad9 100644 (file)
@@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(fetcher)
   {
       filesystem::TmpDir dest;
 
-      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+      fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
       BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
       fetcher.reset();
   }
@@ -44,14 +44,14 @@ BOOST_AUTO_TEST_CASE(fetcher)
 
       // add the key as trusted
       getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
-      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+      fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
       fetcher.start( dest.path(), media );
 
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2").isExist() );
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir2/subdir2-file1.txt").isExist() );
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file1.txt").isExist() );
       BOOST_CHECK( PathInfo(dest.path() + "/complexdir/subdir1/subdir1-file2.txt").isExist() );
-  
+
       fetcher.reset();
   }
 
@@ -61,20 +61,20 @@ BOOST_AUTO_TEST_CASE(fetcher)
 
       // add the key as trusted
       getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir-broken/subdir1/SHA1SUMS.key"), true);
-      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir-broken"), true);
-      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);  
+      fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
+      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
       fetcher.reset();
   }
 
 
-  {  
+  {
       filesystem::TmpDir dest;
 
-      fetcher.enqueue(OnMediaLocation().setFilename("/file-1.txt"));
-      fetcher.start( dest.path(), media );  
+      fetcher.enqueue(OnMediaLocation("/file-1.txt"));
+      fetcher.start( dest.path(), media );
       BOOST_CHECK( PathInfo(dest.path() + "/file-1.txt").isExist() );
   }
-  
+
   //MIL << fetcher;
 }
 
@@ -92,13 +92,13 @@ BOOST_AUTO_TEST_CASE(fetcher_remove)
       Fetcher fetcher;
       filesystem::TmpDir dest;
 
-      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+      fetcher.enqueueDir(OnMediaLocation("/complexdir"), true);
       fetcher.start( dest.path(), media );
 
       fetcher.reset();
 
-      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir-broken"), true);
-      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);  
+      fetcher.enqueueDir(OnMediaLocation("/complexdir-broken"), true);
+      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);
 
       fetcher.reset();
 
index 7214206..38a1eea 100644 (file)
@@ -35,7 +35,7 @@ namespace zypp
    */
   struct FetcherJob
   {
-      
+
     FetcherJob( const OnMediaLocation &loc )
       : location(loc)
       , directory(false)
@@ -53,7 +53,7 @@ namespace zypp
     //CompositeFileChecker checkers;
     list<FileChecker> checkers;
     bool directory;
-    bool recursive;      
+    bool recursive;
   };
 
   typedef shared_ptr<FetcherJob> FetcherJob_Ptr;
@@ -77,7 +77,7 @@ namespace zypp
     ~Impl() {
       MIL << endl;
      }
-    
+
       void enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker()  );
       void enqueueDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() );
       void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() );
@@ -106,7 +106,7 @@ namespace zypp
        * \throws Exception
        */
       void validate( const OnMediaLocation &resource, const Pathname &dest_dir, const list<FileChecker> &checkers );
-      
+
       /**
        * scan the directory and adds the individual jobs
        */
@@ -138,8 +138,8 @@ namespace zypp
       job->checkers.push_back(checker);
     _resources.push_back(job);
   }
-    
-  void Fetcher::Impl::enqueueDir( const OnMediaLocation &resource, 
+
+  void Fetcher::Impl::enqueueDir( const OnMediaLocation &resource,
                                   bool recursive,
                                   const FileChecker &checker )
   {
@@ -150,7 +150,7 @@ namespace zypp
     job->directory = true;
     job->recursive = recursive;
     _resources.push_back(job);
-  }  
+  }
 
   void Fetcher::Impl::enqueue( const OnMediaLocation &resource, const FileChecker &checker )
   {
@@ -186,13 +186,13 @@ namespace zypp
     {
         ERR << "Not adding cache '" << cache_dir << "'. Path does not exists." << endl;
     }
-    
+
   }
 
   bool Fetcher::Impl::provideFromCache( const OnMediaLocation &resource, const Pathname &dest_dir )
   {
     Pathname dest_full_path = dest_dir + resource.filename();
-          
+
     // first check in the destination directory
     if ( PathInfo(dest_full_path).isExist() )
     {
@@ -200,7 +200,7 @@ namespace zypp
            && (! resource.checksum().empty() ) )
           return true;
     }
-    
+
     MIL << "start fetcher with " << _caches.size() << " cache directories." << endl;
     for_ ( it_cache, _caches.begin(), _caches.end() )
     {
@@ -240,7 +240,7 @@ namespace zypp
     } // iterate over caches
     return false;
   }
-    
+
     void Fetcher::Impl::validate( const OnMediaLocation &resource, const Pathname &dest_dir, const list<FileChecker> &checkers )
   {
     // no matter where did we got the file, try to validate it:
@@ -261,7 +261,7 @@ namespace zypp
           ERR << "Invalid checker for '" << localfile << "'" << endl;
         }
       }
-       
+
     }
     catch ( const FileCheckException &e )
     {
@@ -278,7 +278,7 @@ namespace zypp
   }
 
   void Fetcher::Impl::addDirJobs( MediaSetAccess &media,
-                                  const OnMediaLocation &resource, 
+                                  const OnMediaLocation &resource,
                                   const Pathname &dest_dir, bool recursive  )
   {
       // first get the content of the directory so we can add
@@ -286,12 +286,12 @@ namespace zypp
       MIL << "Adding directory " << resource.filename() << endl;
       filesystem::DirContent content;
       media.dirInfo( content, resource.filename(), false /* dots */, resource.medianr());
-      
+
       filesystem::DirEntry shafile, shasig, shakey;
       shafile.name = "SHA1SUMS"; shafile.type = filesystem::FT_FILE;
       shasig.name = "SHA1SUMS.asc"; shasig.type = filesystem::FT_FILE;
       shakey.name = "SHA1SUMS.key"; shakey.type = filesystem::FT_FILE;
-      
+
       // create a new fetcher with a different state to transfer the
       // file containing checksums and its signature
       Fetcher fetcher;
@@ -300,7 +300,7 @@ namespace zypp
       SignatureFileChecker sigchecker;
 
       // now try to find the SHA1SUMS signature
-      if ( find(content.begin(), content.end(), shasig) 
+      if ( find(content.begin(), content.end(), shasig)
            != content.end() )
       {
           MIL << "found checksums signature file: " << shasig.name << endl;
@@ -317,7 +317,7 @@ namespace zypp
           MIL << "no signature for " << shafile.name << endl;
 
       // look for the SHA1SUMS.key file
-      if ( find(content.begin(), content.end(), shakey) 
+      if ( find(content.begin(), content.end(), shakey)
            != content.end() )
       {
           MIL << "found public key file: " << shakey.name << endl;
@@ -330,19 +330,19 @@ namespace zypp
       }
 
       // look for the SHA1SUMS public key file
-      if ( find(content.begin(), content.end(), shafile) 
+      if ( find(content.begin(), content.end(), shafile)
            != content.end() )
       {
           MIL << "found checksums file: " << shafile.name << endl;
           fetcher.enqueue( OnMediaLocation(resource.filename() + shafile.name, resource.medianr()).setOptional(true) );
-          assert_dir(dest_dir + resource.filename()); 
+          assert_dir(dest_dir + resource.filename());
           fetcher.start( dest_dir, media );
           fetcher.reset();
       }
 
       // hash table to store checksums
       map<string, CheckSum> checksums;
-      
+
       // look for the SHA1SUMS file
       if ( find(content.begin(), content.end(), shafile) != content.end() )
       {
@@ -360,7 +360,7 @@ namespace zypp
           std::ifstream in( pShafile.c_str() );
           string buffer;
           if ( ! in.fail() )
-          {          
+          {
               while ( getline(in, buffer) )
               {
                   vector<string> words;
@@ -383,9 +383,9 @@ namespace zypp
           // skip SHA1SUMS* as they were already retrieved
           if ( str::hasPrefix(it->name, "SHA1SUMS") )
               continue;
-          
+
           Pathname filename = resource.filename() + it->name;
-          
+
           switch ( it->type )
           {
           case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
@@ -394,15 +394,14 @@ namespace zypp
               CheckSum checksum;
               if ( checksums.find(it->name) != checksums.end() )
                   checksum = checksums[it->name];
-                  
+
               // create a resource from the file
               // if checksum was not available we will have a empty
               // checksum, which will end in a validation anyway
               // warning the user that there is no checksum
-              enqueueDigested(OnMediaLocation()
-                              .setFilename(filename)
+              enqueueDigested(OnMediaLocation(filename, resource.medianr())
                               .setChecksum(checksum));
-                  
+
               break;
           }
           case filesystem::FT_DIR: // newer directory.yast contain at least directory info
@@ -419,14 +418,14 @@ namespace zypp
   void Fetcher::Impl::provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir )
   {
     bool got_from_cache = false;
-      
+
     // start look in cache
     got_from_cache = provideFromCache(resource, dest_dir);
-      
+
     if ( ! got_from_cache )
     {
       MIL << "Not found in cache, downloading" << endl;
-       
+
       // try to get the file from the net
       try
       {
@@ -454,7 +453,7 @@ namespace zypp
       // continue with next file
         return;
     }
-  }  
+  }
 
   void Fetcher::Impl::start( const Pathname &dest_dir,
                              MediaSetAccess &media,
@@ -464,7 +463,7 @@ namespace zypp
     progress.sendTo(progress_receiver);
 
     for ( list<FetcherJob_Ptr>::const_iterator it_res = _resources.begin(); it_res != _resources.end(); ++it_res )
-    { 
+    {
 
       if ( (*it_res)->directory )
       {
@@ -477,7 +476,7 @@ namespace zypp
 
       // validate job, this throws if not valid
       validate((*it_res)->location, dest_dir, (*it_res)->checkers);
-      
+
       if ( ! progress.incr() )
         ZYPP_THROW(AbortRequestException());
     } // for each job
@@ -487,7 +486,7 @@ namespace zypp
   inline std::ostream & operator<<( std::ostream & str, const Fetcher::Impl & obj )
   {
       for ( list<FetcherJob_Ptr>::const_iterator it_res = obj._resources.begin(); it_res != obj._resources.end(); ++it_res )
-      { 
+      {
           str << *it_res;
       }
       return str;
index e947990..b7a7b80 100644 (file)
@@ -57,7 +57,7 @@ namespace zypp
     /**
      * media number where the resource is located.
      * for a url cd:// this could be 1..N.
-     * for a url of type http://host/path/CD1, a media number 2 
+     * for a url of type http://host/path/CD1, a media number 2
      * means looking on http://host/path/CD1/../CD2
      */
     unsigned          medianr()        const { return _medianr; }
@@ -124,7 +124,7 @@ namespace zypp
     OnMediaLocation & setOpenChecksum( const CheckSum & val_r )
     { _openchecksum = val_r; return *this; }
 
-    /** 
+    /**
      * Set the wether the resource is optional or not
      * \see optional
      */
@@ -132,34 +132,22 @@ namespace zypp
     { _optional = val; return *this; }
 
   public:
-   /** 
-    * Individual manipulation of \c medianr.
-    * Using \ref setLocation is prefered.
+   /**
+    * Individual manipulation of \c medianr (prefer \ref setLocation).
+    * Using \ref setLocation is prefered as us usually have to adjust
+    * \c filename and \c medianr in sync.
     */
-    OnMediaLocation & setMedianr( unsigned val_r )
+    OnMediaLocation & changeMedianr( unsigned val_r )
     { _medianr = val_r; return *this; }
 
     /**
-     * Individual manipulation of \c medianr.
-     * Use \ref setMediaNr instead
-     */
-    ZYPP_DEPRECATED OnMediaLocation & changeMedianr( unsigned val_r )
-    { return setMedianr(val_r); }
-
-    /** 
-     * Individual manipulation of \c filename.
-     * Using \ref setLocation is prefered.
+     * Individual manipulation of \c filename (prefer \ref setLocation).
+     * Using \ref setLocation is preferedas us usually have to adjust
+     * \c filename and \c medianr in sync.
      */
-    OnMediaLocation &setFilename( const Pathname & val_r )
+    OnMediaLocation & changeFilename( const Pathname & val_r )
     { _filename = val_r; return *this; }
 
-    /** 
-     * Individual manipulation of \c filename.
-     * Use \ref setFilename instead.
-    */
-    ZYPP_DEPRECATED OnMediaLocation & changeFilename( const Pathname & val_r )
-    { return setFilename(val_r); }
-
   private:
     unsigned  _medianr;
     Pathname  _filename;
index 1ca9d2c..acfbfc1 100644 (file)
@@ -53,7 +53,7 @@ loc_with_path_prefix(const OnMediaLocation & loc,
     return loc;
 
   OnMediaLocation loc_with_path(loc);
-  loc_with_path.setFilename(prefix / loc.filename());
+  loc_with_path.changeFilename(prefix / loc.filename());
   return loc_with_path;
 }