- support optional deltafile for provideFile and enqueueDigested
authorMichael Schroeder <mls@suse.de>
Tue, 27 Jul 2010 08:28:33 +0000 (10:28 +0200)
committerMichael Schroeder <mls@suse.de>
Tue, 27 Jul 2010 08:28:33 +0000 (10:28 +0200)
makes use of the MediaHandler's setDeltafile function for now

zypp/Fetcher.cc
zypp/Fetcher.h
zypp/MediaSetAccess.cc
zypp/MediaSetAccess.h

index 14b2325..3528dce 100644 (file)
@@ -92,8 +92,9 @@ namespace zypp
     ZYPP_DECLARE_FLAGS(Flags, Flag);
 
 
-    FetcherJob( const OnMediaLocation &loc )
+    FetcherJob( const OnMediaLocation &loc, const Pathname dfile = Pathname())
       : location(loc)
+      , deltafile(dfile)
       , flags(None)
     {
       //MIL << location << endl;
@@ -105,6 +106,7 @@ namespace zypp
     }
 
     OnMediaLocation location;
+    Pathname deltafile;
     //CompositeFileChecker checkers;
     list<FileChecker> checkers;
     Flags flags;
@@ -141,7 +143,7 @@ namespace zypp
     void enqueueDigestedDir( const OnMediaLocation &resource, bool recursive, const FileChecker &checker = FileChecker() );
 
     void enqueue( const OnMediaLocation &resource, const FileChecker &checker = FileChecker()  );
-    void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker() );
+    void enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker = FileChecker(), const Pathname &deltafile = Pathname() );
     void addCachePath( const Pathname &cache_dir );
     void reset();
     void start( const Pathname &dest_dir,
@@ -212,7 +214,7 @@ namespace zypp
       /**
        * Provide the resource to \ref dest_dir
        */
-      void provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir );
+      void provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir , const Pathname &deltafile);
 
   private:
     friend Impl * rwcowClone<Impl>( const Impl * rhs );
@@ -232,10 +234,10 @@ namespace zypp
   };
   ///////////////////////////////////////////////////////////////////
 
-  void Fetcher::Impl::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker )
+  void Fetcher::Impl::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker, const Pathname &deltafile )
   {
     FetcherJob_Ptr job;
-    job.reset(new FetcherJob(resource));
+    job.reset(new FetcherJob(resource, deltafile));
     job->flags |= FetcherJob:: AlwaysVerifyChecksum;
     _resources.push_back(job);
   }
@@ -534,7 +536,7 @@ namespace zypp
       }
   }
 
-  void Fetcher::Impl::provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir )
+  void Fetcher::Impl::provideToDest( MediaSetAccess &media, const OnMediaLocation &resource, const Pathname &dest_dir, const Pathname &deltafile )
   {
     bool got_from_cache = false;
 
@@ -548,7 +550,7 @@ namespace zypp
       // try to get the file from the net
       try
       {
-        Pathname tmp_file = media.provideFile(resource, resource.optional() ? MediaSetAccess::PROVIDE_NON_INTERACTIVE : MediaSetAccess::PROVIDE_DEFAULT );
+        Pathname tmp_file = media.provideFile(resource, resource.optional() ? MediaSetAccess::PROVIDE_NON_INTERACTIVE : MediaSetAccess::PROVIDE_DEFAULT, deltafile );
 
         Pathname dest_full_path = dest_dir + resource.filename();
 
@@ -788,7 +790,7 @@ namespace zypp
           autoaddIndexes(content, media, Pathname("/"), dest_dir);
       }
 
-      provideToDest(media, (*it_res)->location, dest_dir);
+      provideToDest(media, (*it_res)->location, dest_dir, (*it_res)->deltafile);
 
       // if the file was not transfered, and no exception, just
       // return, as it was an optional file
@@ -860,9 +862,9 @@ namespace zypp
     return _pimpl->options();
   }
 
-  void Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker )
+  void Fetcher::enqueueDigested( const OnMediaLocation &resource, const FileChecker &checker, const Pathname &deltafile )
   {
-    _pimpl->enqueueDigested(resource, checker);
+    _pimpl->enqueueDigested(resource, checker, deltafile);
   }
 
   void Fetcher::enqueueDir( const OnMediaLocation &resource,
index 90babd8..4cb8c54 100644 (file)
@@ -190,9 +190,15 @@ namespace zypp
     * the user could be asked twice.
     *
     * \todo FIXME implement checker == operator to avoid this.
+    *
+    * the optional deltafile argument describes a file that can
+    * be used for delta download algorithms. Usable files are
+    * uncompressed files or files compressed with gzip --rsyncable.
+    * Other files like rpms do not work, as the compression
+    * breaks the delta algorithm.
     */
     void enqueueDigested( const OnMediaLocation &resource,
-                          const FileChecker &checker = FileChecker() );
+                          const FileChecker &checker = FileChecker(), const Pathname &deltafile = Pathname());
 
 
     /**
index eb126dc..c063563 100644 (file)
@@ -154,10 +154,10 @@ IMPL_PTR_TYPE(MediaSetAccess);
 
 
 
-  Pathname MediaSetAccess::provideFile( const OnMediaLocation & resource, ProvideFileOptions options )
+  Pathname MediaSetAccess::provideFile( const OnMediaLocation & resource, ProvideFileOptions options, const Pathname &deltafile )
   {
     ProvideFileOperation op;
-    provide( boost::ref(op), resource, options );
+    provide( boost::ref(op), resource, options, deltafile );
     return op.result;
   }
 
@@ -166,7 +166,7 @@ IMPL_PTR_TYPE(MediaSetAccess);
     OnMediaLocation resource;
     ProvideFileOperation op;
     resource.setLocation(file, media_nr);
-    provide( boost::ref(op), resource, options );
+    provide( boost::ref(op), resource, options, Pathname() );
     return op.result;
   }
 
@@ -175,13 +175,14 @@ IMPL_PTR_TYPE(MediaSetAccess);
     ProvideFileExistenceOperation op;
     OnMediaLocation resource;
     resource.setLocation(file, media_nr);
-    provide( boost::ref(op), resource, PROVIDE_DEFAULT);
+    provide( boost::ref(op), resource, PROVIDE_DEFAULT, Pathname());
     return op.result;
   }
 
   void MediaSetAccess::provide( ProvideOperation op,
                                 const OnMediaLocation &resource,
-                                ProvideFileOptions options )
+                                ProvideFileOptions options,
+                                const Pathname &deltafile )
   {
     Pathname file(resource.filename());
     unsigned media_nr(resource.medianr());
@@ -195,6 +196,7 @@ IMPL_PTR_TYPE(MediaSetAccess);
     {
       // get the mediaId, but don't try to attach it here
       media = getMediaAccessId( media_nr);
+      bool deltafileset = false;
 
       try
       {
@@ -203,12 +205,17 @@ IMPL_PTR_TYPE(MediaSetAccess);
         // try to attach the media
         if ( ! media_mgr.isAttached(media) )
           media_mgr.attach(media);
+       media_mgr.setDeltafile(media, deltafile);
+       deltafileset = true;
         op(media, file);
+       media_mgr.setDeltafile(media, Pathname());
         break;
       }
       catch ( media::MediaException & excp )
       {
         ZYPP_CAUGHT(excp);
+       if (deltafileset)
+         media_mgr.setDeltafile(media, Pathname());
         media::MediaChangeReport::Action user = media::MediaChangeReport::ABORT;
         unsigned int devindex = 0;
         vector<string> devices;
@@ -329,11 +336,11 @@ IMPL_PTR_TYPE(MediaSetAccess);
     if ( recursive )
     {
         ProvideDirTreeOperation op;
-        provide( boost::ref(op), resource, options);
+        provide( boost::ref(op), resource, options, Pathname());
         return op.result;
     }
     ProvideDirOperation op;
-    provide( boost::ref(op), resource, options);
+    provide( boost::ref(op), resource, options, Pathname());
     return op.result;
   }
 
index 7ec1ff4..bd9fb45 100644 (file)
@@ -135,6 +135,9 @@ namespace zypp
        * If the resource is marked as optional, no Exception is thrown
        * and Pathname() is returned
        *
+       * the optional deltafile argument describes a file that can
+       * be used for delta download algorithms.
+       *
        * \note interaction with the user does not ocurr if
        * \ref ProvideFileOptions::NON_INTERACTIVE is set.
        *
@@ -142,7 +145,7 @@ namespace zypp
        *
        * \see zypp::media::MediaManager::provideFile()
        */
-      Pathname provideFile( const OnMediaLocation & resource, ProvideFileOptions options = PROVIDE_DEFAULT );
+      Pathname provideFile( const OnMediaLocation & resource, ProvideFileOptions options = PROVIDE_DEFAULT, const Pathname &deltafile = Pathname() );
 
       /**
        * Provides \a file from media \a media_nr.
@@ -268,7 +271,7 @@ namespace zypp
 
       typedef function<void( media::MediaAccessId, const Pathname & )> ProvideOperation;
 
-      void provide( ProvideOperation op, const OnMediaLocation &resource, ProvideFileOptions options );
+      void provide( ProvideOperation op, const OnMediaLocation &resource, ProvideFileOptions options, const Pathname &deltafile );
 
       media::MediaAccessId getMediaAccessId (media::MediaNr medianr);
       virtual std::ostream & dumpOn( std::ostream & str ) const;