00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <fstream>
00011 #include "zypp/base/String.h"
00012 #include "zypp/base/Logger.h"
00013 #include "zypp/base/Function.h"
00014
00015 #include "zypp/Date.h"
00016
00017 #include "zypp/parser/yum/RepomdFileReader.h"
00018 #include "zypp/parser/yum/PatchesFileReader.h"
00019 #include "Downloader.h"
00020 #include "zypp/repo/MediaInfoDownloader.h"
00021 #include "zypp/base/UserRequestException.h"
00022 #include "zypp/parser/xml/Reader.h"
00023
00024 using namespace std;
00025 using namespace zypp::xml;
00026 using namespace zypp::parser::yum;
00027
00028 namespace zypp
00029 {
00030 namespace repo
00031 {
00032 namespace yum
00033 {
00034
00035 Downloader::Downloader( const Pathname &path )
00036 : _path(path), _media_ptr(0L)
00037 {
00038 }
00039
00040 RepoStatus Downloader::status( MediaSetAccess &media )
00041 {
00042 Pathname repomd = media.provideFile( _path + "/repodata/repomd.xml");
00043 return RepoStatus(repomd);
00044 }
00045
00046 bool Downloader::patches_Callback( const OnMediaLocation &loc,
00047 const string &id )
00048 {
00049 MIL << id << " : " << loc << endl;
00050 this->enqueueDigested(loc);
00051 return true;
00052 }
00053
00054
00055 bool Downloader::repomd_Callback( const OnMediaLocation &loc,
00056 const ResourceType &dtype )
00057 {
00058 MIL << dtype << " : " << loc << endl;
00059
00061
00062 if ( dtype == ResourceType::OTHER )
00063 {
00064 MIL << "Skipping other.xml" << endl;
00065 return true;
00066 }
00067
00068 if ( dtype == ResourceType::FILELISTS )
00069 {
00070 MIL << "Skipping filelists.xml.gz" << endl;
00071 return true;
00072 }
00073
00074 this->enqueueDigested(loc);
00075
00076
00077
00078
00079 if ( dtype == ResourceType::PATCHES )
00080 {
00081 this->start( _dest_dir, *_media_ptr );
00082
00083 PatchesFileReader( _dest_dir + _path + loc.filename(),
00084 bind( &Downloader::patches_Callback, this, _1, _2));
00085 }
00086
00087 return true;
00088 }
00089
00090 void Downloader::download( MediaSetAccess &media,
00091 const Pathname &dest_dir,
00092 const ProgressData::ReceiverFnc & progressrcv )
00093 {
00094 Pathname repomdpath = _path + "/repodata/repomd.xml";
00095 Pathname keypath = _path + "/repodata/repomd.xml.key";
00096 Pathname sigpath = _path + "/repodata/repomd.xml.asc";
00097
00098 _media_ptr = (&media);
00099
00100 ProgressData progress;
00101 progress.sendTo(progressrcv);
00102 progress.toMin();
00103
00104
00105
00106 _dest_dir = dest_dir;
00107
00108 if ( _media_ptr->doesFileExist(keypath) )
00109 this->enqueue( OnMediaLocation(keypath,1) );
00110
00111 if ( _media_ptr->doesFileExist(sigpath) )
00112 this->enqueue( OnMediaLocation(sigpath,1) );
00113
00114 this->start( dest_dir, *_media_ptr );
00115
00116 if ( ! progress.tick() )
00117 ZYPP_THROW(AbortRequestException());
00118
00119 SignatureFileChecker sigchecker;
00120
00121 if ( PathInfo( dest_dir + sigpath ).isExist() )
00122 sigchecker = SignatureFileChecker(dest_dir + sigpath);
00123
00124 if ( PathInfo( dest_dir + keypath ).isExist() )
00125 sigchecker.addPublicKey(dest_dir + keypath );
00126
00127 this->enqueue( OnMediaLocation(repomdpath,1), sigchecker );
00128 this->start( dest_dir, *_media_ptr);
00129
00130 if ( ! progress.tick() )
00131 ZYPP_THROW(AbortRequestException());
00132
00133 this->reset();
00134
00135 Reader reader( dest_dir + _path + "/repodata/repomd.xml" );
00136 RepomdFileReader( dest_dir + _path + "/repodata/repomd.xml", bind( &Downloader::repomd_Callback, this, _1, _2));
00137
00138
00139 this->start( dest_dir, *_media_ptr);
00140 progress.toMax();
00141 }
00142
00143 }
00144 }
00145 }
00146
00147
00148