- merge Stano's patch to keep downloaded rpms
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 15 Feb 2008 12:58:44 +0000 (12:58 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 15 Feb 2008 12:58:44 +0000 (12:58 +0000)
zypp/Fetcher.cc
zypp/RepoInfo.cc
zypp/RepoInfo.h
zypp/RepoManager.cc
zypp/RepoManager.h
zypp/ZConfig.cc
zypp/ZConfig.h
zypp/parser/RepoFileReader.cc
zypp/repo/RepoProvideFile.cc

index 31e4903..fd444ac 100644 (file)
@@ -139,8 +139,13 @@ namespace zypp
       {
         // does the current file exists in the current cache?
         Pathname cached_file = *it_cache + (*it_res)->location.filename();
+       
+       MIL << "Trying cached file: " << cached_file << endl;
+       
         if ( PathInfo( cached_file ).isExist() )
         {
+         MIL << "File exist, testing checksum " << (*it_res)->location.checksum() << endl;
+
           // check the checksum
           if ( is_checksum( cached_file, (*it_res)->location.checksum() ) && (! (*it_res)->location.checksum().empty() ) )
           {
@@ -151,16 +156,20 @@ namespace zypp
 
             // replicate the complete path in the target directory
             Pathname dest_full_path = dest_dir + (*it_res)->location.filename();
-            if ( assert_dir( dest_full_path.dirname() ) != 0 )
-              ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
+           
+           if( dest_full_path != cached_file )
+           {
+              if ( assert_dir( dest_full_path.dirname() ) != 0 )
+                ZYPP_THROW( Exception("Can't create " + dest_full_path.dirname().asString()));
 
-            if ( filesystem::copy(cached_file, dest_full_path ) != 0 )
-            { //copy_file2dir
-              //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString()));
-              ERR << "Can't copy " << cached_file + " to " + dest_dir << endl;
-              // try next cache
-              continue;
-            }
+              if ( filesystem::copy(cached_file, dest_full_path ) != 0 )
+              { //copy_file2dir
+                //ZYPP_THROW(SourceIOException("Can't copy " + cached_file.asString() + " to " + destination.asString()));
+                ERR << "Can't copy " << cached_file + " to " + dest_dir << endl;
+                // try next cache
+                continue;
+              }
+           }
 
             got_from_cache = true;
             break;
@@ -170,6 +179,8 @@ namespace zypp
 
       if ( ! got_from_cache )
       {
+        MIL << "Not found in cache, downloading" << endl;
+       
         // try to get the file from the net
         try
         {
index 7257973..66473b9 100644 (file)
@@ -33,6 +33,7 @@ namespace zypp
       : enabled (false),
         autorefresh(false),
         gpgcheck(true),
+       keeppackages(false),
         type(repo::RepoType::NONE_e)
     {}
 
@@ -44,6 +45,7 @@ namespace zypp
     bool enabled;
     bool autorefresh;
     bool gpgcheck;
+    bool keeppackages;
     Url gpgkey_url;
     repo::RepoType type;
     Url mirrorlist_url;
@@ -54,6 +56,7 @@ namespace zypp
     std::string name;
     Pathname filepath;
     Pathname metadatapath;
+    Pathname packagespath;
   public:
 
   private:
@@ -185,6 +188,18 @@ namespace zypp
     return *this;
   }
 
+  RepoInfo & RepoInfo::setPackagesPath( const Pathname &path )
+  {
+    _pimpl->packagespath = path;
+    return *this;
+  }
+
+  RepoInfo & RepoInfo::setKeepPackages( bool keep )
+  {
+    _pimpl->keeppackages = keep;
+    return *this;
+  }
+
   bool RepoInfo::enabled() const
   { return _pimpl->enabled; }
 
@@ -217,6 +232,9 @@ namespace zypp
   Pathname RepoInfo::metadataPath() const
   { return _pimpl->metadatapath; }
 
+  Pathname RepoInfo::packagesPath() const
+  { return _pimpl->packagespath; }
+
   repo::RepoType RepoInfo::type() const
   { return _pimpl->type; }
 
@@ -264,6 +282,9 @@ namespace zypp
   bool RepoInfo::baseUrlsEmpty() const
   { return _pimpl->baseUrls.empty(); }
 
+  bool RepoInfo::keepPackages() const
+  { return _pimpl->keeppackages; }
+
   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
   {
     str << "--------------------------------------" << std::endl;
@@ -281,6 +302,7 @@ namespace zypp
     str << "- autorefresh : " << autorefresh() << std::endl;
     str << "- gpgcheck : " << gpgCheck() << std::endl;
     str << "- gpgkey : " << gpgKeyUrl() << std::endl;
+    str << "- keeppackages : " << keepPackages() << std::endl;
 
     return str;
   }
@@ -312,6 +334,8 @@ namespace zypp
     str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
     if ( ! (gpgKeyUrl().asString().empty()) )
       str << "gpgkey=" <<gpgKeyUrl() << endl;
+      
+    str << "keeppackages=" << keepPackages() << endl;
 
     return str;
   }
index d384e54..07bc316 100644 (file)
@@ -189,6 +189,11 @@ namespace zypp
      Pathname metadataPath() const;
 
      /**
+     * \short Path where this repo packages are cached
+     */
+     Pathname packagesPath() const;
+
+     /**
      * \short Whether to check or not this repository with gpg
      *
      * \note This is a just a hint to the application and can
@@ -209,6 +214,11 @@ namespace zypp
      Url gpgKeyUrl() const;
 
     /**
+     * \short Whether to keep the packages downloaded from this repository will be kept in local cache
+     */
+    bool keepPackages() const;
+
+    /**
      * Add a base url. \see baseUrls
      * \param url The base url for the repository.
      *
@@ -285,6 +295,13 @@ namespace zypp
     RepoInfo & setMetadataPath( const Pathname &path );
 
     /**
+     * \short set the path where the local packages are stored
+     *
+     * \param path directory path
+     */
+    RepoInfo & setPackagesPath( const Pathname &path );
+
+    /**
      * \short Whether to check or not this repository with gpg
      *
      * \param check true (check) or false (dont'check)
@@ -305,6 +322,17 @@ namespace zypp
      *
      */
     RepoInfo & setGpgKeyUrl( const Url &gpgkey );
+    
+    /**
+     * \short Set if the packaqes downloaded from this repository will be kept in local cache
+     *
+     * If the setting is true, all downloaded packages from this repository will be 
+     * copied to the local raw cache.
+     *
+     * \param keep true (keep the downloaded packages) or false (delete them after installation)
+     *
+     */
+    RepoInfo & setKeepPackages( bool keep );
 
     /**
      * Write a human-readable representation of this RepoInfo object
index 1a793cc..fb12f0a 100644 (file)
@@ -67,6 +67,7 @@ namespace zypp
   {
     repoCachePath    = ZConfig::instance().repoCachePath();
     repoRawCachePath = ZConfig::instance().repoMetadataPath();
+    repoPackagesCachePath = ZConfig::instance().repoPackagesPath();
     knownReposPath   = ZConfig::instance().knownReposPath();
   }
 
@@ -197,6 +198,15 @@ namespace zypp
     return opt.repoRawCachePath + info.alias();
   }
 
+  /**
+   * \short Calculates the packages cache path for a repository
+   */
+  static Pathname packagescache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
+  {
+    assert_alias(info);
+    return opt.repoPackagesCachePath + info.alias();
+  }
+
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : RepoManager::Impl
@@ -277,6 +287,10 @@ namespace zypp
         // set the metadata path for the repo
         Pathname metadata_path = rawcache_path_for_repoinfo(_pimpl->options, (*it));
         (*it).setMetadataPath(metadata_path);
+       
+       // set the downloaded packages path for the repo
+       Pathname packages_path = packagescache_path_for_repoinfo(_pimpl->options, (*it));
+       (*it).setPackagesPath(packages_path);
       }
       return repos;
     }
@@ -599,10 +613,17 @@ namespace zypp
 
         // ok we have the metadata, now exchange
         // the contents
-        TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
-        filesystem::rename( rawpath, oldmetadata.path() );
+       
+       // first, clean up the old rawcache metadata
+       // #FIXME       
+       // now, move the new metadata in
+       // #FIXME
+       
+        //TmpDir oldmetadata( TmpDir::makeSibling( rawpath ) );
+        //filesystem::rename( rawpath, oldmetadata.path() );
         // move the just downloaded there
-        filesystem::rename( tmpdir.path(), rawpath );
+        //filesystem::rename( tmpdir.path(), rawpath );
+
         // we are done.
         return;
       }
index 2303461..711c3ff 100644 (file)
@@ -52,6 +52,7 @@ namespace zypp
 
     Pathname repoCachePath;
     Pathname repoRawCachePath;
+    Pathname repoPackagesCachePath;
     Pathname knownReposPath;
   };
 
index 9e2ca91..814db0b 100644 (file)
@@ -216,6 +216,10 @@ namespace zypp
                 {
                   cfg_vendor_path = Pathname(value);
                 }
+                else if ( entry == "packagesdir" )
+                {
+                  cfg_packages_path = Pathname(value);
+                }
               }
             }
           }
@@ -249,6 +253,7 @@ namespace zypp
     Locale   cfg_textLocale;
 
     Pathname cfg_metadata_path;
+    Pathname cfg_packages_path;
     Pathname cfg_cache_path;
     Pathname cfg_known_repos_path;
     Pathname cfg_vendor_path;
@@ -347,6 +352,12 @@ namespace zypp
         ? Pathname("/var/cache/zypp/raw") : _pimpl->cfg_metadata_path );
   }
 
+  Pathname ZConfig::repoPackagesPath() const
+  {
+    return ( _pimpl->cfg_packages_path.empty()
+        ? Pathname("/var/cache/zypp/packages") : _pimpl->cfg_packages_path );
+  }
+
   Pathname ZConfig::repoCachePath() const
   {
     return ( _pimpl->cfg_cache_path.empty()
index abb6528..ef2a8bb 100644 (file)
@@ -93,6 +93,11 @@ namespace zypp
       Pathname repoMetadataPath() const;
 
       /**
+       * Path where the repo packages are downloaded and kept.
+       */
+      Pathname repoPackagesPath() const;
+
+      /**
        * Path where the processed cache is kept
        * (this is where zypp.db is located.
        */
index ff98834..4327511 100644 (file)
@@ -69,6 +69,8 @@ namespace zypp
             info.setGpgKeyUrl( Url(it->second) );
           else if ( it->first == "gpgcheck" )
             info.setGpgCheck( it->second == "1" );
+         else if ( it->first == "keeppackages" )
+           info.setKeepPackages( it->second == "1" );
           else
             ERR << "Unknown attribute " << it->second << " ignored" << endl;
         }
index 52a8f8d..0ca120c 100644 (file)
@@ -28,6 +28,7 @@
 #include "zypp/repo/SUSEMediaVerifier.h"
 #include "zypp/repo/RepoException.h"
 #include "zypp/FileChecker.h"
+#include "zypp/Fetcher.h"
 
 using std::endl;
 using std::set;
@@ -214,7 +215,12 @@ namespace zypp
         repo_excpt.remember(RepoException(_("No url in repository.")));
         ZYPP_THROW(repo_excpt);
       }
+
+      Fetcher fetcher;
+      fetcher.addCachePath( info.packagesPath() );
       
+      MIL << "Added cache path " << info.packagesPath() << endl;
+            
       for ( RepoInfo::urls_const_iterator it = info.baseUrlsBegin();
             it != info.baseUrlsEnd();
             /* incremented in the loop */ )
@@ -227,11 +233,17 @@ namespace zypp
               << "' from " << url << endl;
           shared_ptr<MediaSetAccess> access = _impl->mediaAccessForUrl(url);
           _impl->setVerifierForRepo(repo_r, access);
+         
+         fetcher.enqueue( loc_r );
+         
+         // FIXME: works for packages only
+         fetcher.start( info.packagesPath(), *access );
 
-          ManagedFile ret( access->provideFile(loc_r) );
+         // reached if no exception has been thrown, so this is the correct file
+          ManagedFile ret( info.packagesPath() + loc_r.filename() );
 
           std::string scheme( url.getScheme() );
-          if ( scheme == "http" || scheme == "https" || scheme == "ftp" )
+          if ( !info.keepPackages() )
           {
             ret.setDispose( filesystem::unlink );
           }