provide file download callbacks (#160206)
authorStanislav Visnovsky <visnov@suse.cz>
Mon, 24 Apr 2006 09:33:46 +0000 (09:33 +0000)
committerStanislav Visnovsky <visnov@suse.cz>
Mon, 24 Apr 2006 09:33:46 +0000 (09:33 +0000)
package/libzypp.changes
zypp/source/SourceImpl.cc
zypp/source/SourceImpl.h

index db79e39..0ed415e 100644 (file)
@@ -1,4 +1,9 @@
 -------------------------------------------------------------------
+Mon Apr 24 11:20:17 CEST 2006 - visnov@suse.cz
+
+- fix callbacks for providing a single file (#160206) 
+
+-------------------------------------------------------------------
 Sun Apr 23 12:28:21 CEST 2006 - kkaempf@suse.de
 
 - If an installed package looses a dependency, the solver tries
index f607f31..ef91297 100644 (file)
@@ -32,7 +32,7 @@ namespace zypp
     IMPL_PTR_TYPE(SourceImpl);
 
 
-    class DownloadProgressReceiver
+    class DownloadProgressPackageReceiver
        : public callback::ReceiveReport<media::DownloadProgressReport>
     {
        callback::SendReport <DownloadResolvableReport> & _report;
@@ -40,7 +40,7 @@ namespace zypp
 
       public:
 
-       DownloadProgressReceiver (
+       DownloadProgressPackageReceiver (
            callback::SendReport <DownloadResolvableReport> & report_r,
            Resolvable::constPtr resolvable_r
        )
@@ -48,7 +48,7 @@ namespace zypp
        , _resolvable (resolvable_r)
        {}
        
-       virtual ~DownloadProgressReceiver () {} 
+       virtual ~DownloadProgressPackageReceiver () {} 
        
        virtual void reportbegin() {}
        
@@ -65,6 +65,35 @@ namespace zypp
     };
 
 
+    class DownloadProgressFileReceiver
+       : public callback::ReceiveReport<media::DownloadProgressReport>
+    {
+       callback::SendReport <DownloadFileReport> & _report;
+
+      public:
+
+       DownloadProgressFileReceiver (
+           callback::SendReport <DownloadFileReport> & report_r
+       )
+       : _report (report_r)
+       {}
+       
+       virtual ~DownloadProgressFileReceiver () {} 
+       
+       virtual void reportbegin() {}
+       
+       virtual void reportend() {}
+
+        /**
+         * Inform about progress
+         * Return true on abort
+         */
+        virtual bool progress( int percent, Url url )
+       {
+           return _report->progress( percent, url );
+       }
+    };
+
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : SourceImpl::SourceImpl
@@ -170,7 +199,7 @@ namespace zypp
       bool digest_ok = false;
       Pathname file;
       callback::SendReport<source::DownloadResolvableReport> report;
-      DownloadProgressReceiver download_report( report, package );
+      DownloadProgressPackageReceiver download_report( report, package );
       
       while (retry)
       {
@@ -178,7 +207,7 @@ namespace zypp
        
        callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
        
-        file = package->source().provideFile( package->location(), package->mediaId());
+        file = provideJustFile( package->location(), package->mediaId());
 
         report->finish( package, source::DownloadResolvableReport::NO_ERROR, "" );
         
@@ -226,6 +255,30 @@ namespace zypp
                                           const unsigned media_nr,
                                           bool cached,
                                           bool checkonly )
+    {    
+      callback::SendReport<source::DownloadFileReport> report;
+      DownloadProgressFileReceiver download_report( report );
+      
+      SourceFactory source_factory;
+      
+      Url file_url( url().asString() + file_r.asString() );
+
+      report->start( source_factory.createFrom(this), file_url );
+       
+      callback::TempConnect<media::DownloadProgressReport> tmp_download( download_report );
+       
+      Pathname file = provideJustFile( file_r, media_nr, cached, checkonly );
+
+      report->finish( file_url, source::DownloadFileReport::NO_ERROR, "" );
+      
+      return file;
+    }
+
+
+    const Pathname SourceImpl::provideJustFile(const Pathname & file_r,
+                                          const unsigned media_nr,
+                                          bool cached,
+                                          bool checkonly )
     {
       callback::SendReport<media::MediaChangeReport> report;
 
index fc855de..236d75c 100644 (file)
@@ -204,8 +204,16 @@ namespace zypp
        * Release all medias attached by the source
        */
       void release();
+
       /**
-       * Get media verifier for the specified media
+       * Get media verifier for the specified medium. In the
+       * default installation, an instance of media::NoVerifier is 
+       * returned. The specific implementations of the sources
+       * should overload this method to return a proper verifier.
+       *
+       * \param media_nr number of the medium
+       *
+       * \return instance of a media verifier for the given medium.
        */
       virtual media::MediaVerifierRef verifier(unsigned media_nr);
 
@@ -214,6 +222,29 @@ namespace zypp
       Source_Ref selfSourceRef()
       { return Source_Ref( this ); }
 
+      /**
+       * Provide a file to local filesystem on the given path,
+       * no checking or progress information redirection.
+       * used by \ref provideFile and \ref providePackage.
+       * If \c checkonly is true, no media change callback 
+       * will be invoked.
+       *
+       * \param path file with a path to be provided by the source
+       * \param media_nr number of the media to look for the path
+       * \param cached provide a cached copy of the file, if available
+       * \param checkonly just check if it is possible to provide the file
+       *
+       * \return the local path for the provided file
+       *
+       * \throws Exception
+       *
+       */
+      const Pathname provideJustFile(const Pathname & path,
+                                const unsigned media_nr = 1,
+                                bool cached = false,
+                                bool checkonly = false);
+
+
     protected:
       /** All resolvables provided by this source. */
       ResStore _store;