- dont check for existence of keys but provde a way to retrieve optional
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 21 May 2008 17:02:02 +0000 (17:02 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Wed, 21 May 2008 17:02:02 +0000 (17:02 +0000)
  files, in order to avoid a HEAD request. related to bnc#381280

zypp/Fetcher.cc
zypp/MediaSetAccess.cc
zypp/MediaSetAccess.h
zypp/repo/susetags/Downloader.cc
zypp/repo/yum/Downloader.cc

index 5267b3ce39f9506e10dbcfbcca83f765710c0e8c..0ce398266b3e783eb0918f1410f8041f31bad56d 100644 (file)
@@ -213,6 +213,14 @@ namespace zypp
         catch (Exception & excpt_r)
         {
           ZYPP_CAUGHT(excpt_r);
+
+          // do not error on optional files
+          if ((*it_res)->location.optional() )
+          {
+              MIL << "Skipping optional file " << (*it_res)->location << endl;
+              continue;
+          }
+          
           excpt_r.remember("Can't provide " + (*it_res)->location.filename().asString() + " : " + excpt_r.msg());
           ZYPP_RETHROW(excpt_r);
         }
index 3cd0745fd8ef47ec2e0ea2f5c55f1bc1737c3282..f28b3d1dd2dce05060e2649d4390f8ece40518a6 100644 (file)
@@ -69,16 +69,6 @@ IMPL_PTR_TYPE(MediaSetAccess);
     }
   }
 
-//       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;
-
   void MediaSetAccess::releaseFile( const OnMediaLocation & on_media_file )
   {
     releaseFile( on_media_file.filename(), on_media_file.medianr() );
@@ -101,13 +91,23 @@ IMPL_PTR_TYPE(MediaSetAccess);
 
   Pathname MediaSetAccess::provideFile( const OnMediaLocation & on_media_file )
   {
-    return provideFile( on_media_file.filename(), on_media_file.medianr() );
+    // if the file is optional we don't want a retry, ignore, abort
+    // callback, but just abort inmediately if it does not exist
+    // therefore we pass checkonly true
+    if (on_media_file.optional() )
+      return provideFileInternal( on_media_file.filename(), 
+                                  on_media_file.medianr(),
+                                  true, true);
+          
+    return provideFileInternal( on_media_file.filename(),
+                                on_media_file.medianr(),
+                                true, false );
   }
 
 
   Pathname MediaSetAccess::provideFile(const Pathname & file, unsigned media_nr )
   {
-    return provideFileInternal( file, media_nr, false, false);
+    return provideFileInternal( file, media_nr, false, false );
   }
 
   bool MediaSetAccess::doesFileExist(const Pathname & file, unsigned media_nr )
index 09ec05dbdbb6a1c751281202be7eec29ba94fc4c..00847ec519099d7a7672bbb69adf5361300b23c5 100644 (file)
@@ -113,6 +113,11 @@ namespace zypp
        * \param on_media_file location of the file on media
        * \return local pathname of the requested file
        *
+       * If \p on_media_file is marked as optional, then
+       * in case of failure the user interaction callbacks
+       * will be ignored and the exception will throw
+       * inmediately.
+       *
        * \throws MediaException if a problem occurs,
        *        see \ref media::MediaManager::provideFile()
        */
index 6b5ccb81612d91fb5b01ec2b44c86376a39a4a3c..b29ae419ca50e6728f32df55fb0150d8297b986a 100644 (file)
@@ -49,24 +49,22 @@ void Downloader::download( MediaSetAccess &media,
   SignatureFileChecker sigchecker;
 
   Pathname sig = _path + "/content.asc";
-  if ( media.doesFileExist(sig) )
-  {
-    this->enqueue( OnMediaLocation( sig, 1 ) );
-    this->start( dest_dir, media );
-    this->reset();
 
-    sigchecker = SignatureFileChecker( dest_dir + sig );
-  }
+  this->enqueue( OnMediaLocation( sig, 1 ).setOptional(true) );
+  this->start( dest_dir, media );
+  this->reset();
+
+  if ( PathInfo(dest_dir + sig).isExist() )
+      sigchecker = SignatureFileChecker( dest_dir + sig );
 
   Pathname key = _path + "/content.key";
-  if ( media.doesFileExist(key) )
-  {
-    this->enqueue( OnMediaLocation( key, 1 ) );
-    this->start( dest_dir, media );
-    this->reset();
-    sigchecker.addPublicKey(dest_dir + key);
-  }
 
+  // the key may not exist
+  this->enqueue( OnMediaLocation( key, 1 ).setOptional(true) );
+  this->start( dest_dir, media );
+  this->reset();
+  if ( PathInfo(dest_dir + key).isExist() )
+      sigchecker.addPublicKey(dest_dir + key);
 
   this->enqueue( OnMediaLocation( _path + "/content", 1 ), sigchecker );
   this->start( dest_dir, media );
index add26b80cff6f03553f38115a456270567dbaf53..9af9e5977a9f61f6283b8010330f18d7fa8a1790 100644 (file)
@@ -107,24 +107,23 @@ void Downloader::download( MediaSetAccess &media,
   
   SignatureFileChecker sigchecker;
 
-  if ( _media_ptr->doesFileExist(sigpath) )
-  {
-      this->enqueue( OnMediaLocation(sigpath,1).setOptional(true) );
-     this->start( dest_dir, *_media_ptr);
-     this->reset();
-     sigchecker = SignatureFileChecker(dest_dir + sigpath);
-  }
+  // this file is optional, may be the signature is not there
+  this->enqueue( OnMediaLocation(sigpath,1).setOptional(true) );
+  this->start( dest_dir, *_media_ptr);
+  this->reset();
 
-  if ( _media_ptr->doesFileExist(keypath) )
-  {
-      this->enqueue( OnMediaLocation(keypath,1).setOptional(true) );
-    this->start( dest_dir, *_media_ptr);
-    this->reset();
-    sigchecker.addPublicKey(dest_dir + keypath);
-  }
+  // only need a checker if the signature exist.
+  if ( PathInfo(dest_dir + sigpath).isExist() )
+      sigchecker = SignatureFileChecker(dest_dir + sigpath);
+
+  // the key path may also not be there
+  this->enqueue( OnMediaLocation(keypath,1).setOptional(true) );
+  this->start( dest_dir, *_media_ptr);
+  this->reset();
+  
+  if ( PathInfo(dest_dir + keypath).isExist() )
+      sigchecker.addPublicKey(dest_dir + keypath);
 
   this->start( dest_dir, *_media_ptr );
 
   if ( ! progress.tick() )