5 #include "zypp/base/Logger.h"
6 #include "zypp/base/String.h"
7 #include "zypp/OnMediaLocation.h"
8 #include "zypp/MediaSetAccess.h"
9 #include "zypp/Fetcher.h"
10 #include "zypp/Locale.h"
11 #include "zypp/ZConfig.h"
12 #include "zypp/repo/MediaInfoDownloader.h"
13 #include "zypp/repo/susetags/Downloader.h"
14 #include "zypp/parser/ParseException.h"
15 #include "zypp/parser/susetags/RepoIndex.h"
16 #include "zypp/base/UserRequestException.h"
19 using namespace zypp::parser;
20 using namespace zypp::parser::susetags;
29 Downloader::Downloader(const Pathname &path )
35 RepoStatus Downloader::status( MediaSetAccess &media )
37 Pathname content = media.provideFile( _path + "/content");
38 return RepoStatus(content);
41 void Downloader::download( MediaSetAccess &media,
42 const Pathname &dest_dir,
43 const ProgressData::ReceiverFnc & progress )
45 downloadMediaInfo( dest_dir, media );
47 SignatureFileChecker sigchecker;
49 Pathname sig = _path + "/content.asc";
50 if ( media.doesFileExist(sig) )
52 this->enqueue( OnMediaLocation( sig, 1 ) );
53 this->start( dest_dir, media );
56 sigchecker = SignatureFileChecker( dest_dir + sig );
59 Pathname key = _path + "/content.key";
60 if ( media.doesFileExist(key) )
62 this->enqueue( OnMediaLocation( key, 1 ) );
63 this->start( dest_dir, media );
65 sigchecker.addPublicKey(dest_dir + key);
69 this->enqueue( OnMediaLocation( _path + "/content", 1 ), sigchecker );
70 this->start( dest_dir, media );
75 // Content file first to get the repoindex
77 Pathname inputfile( dest_dir + _path + "/content" );
78 ContentFileReader content;
79 content.setRepoIndexConsumer( bind( &Downloader::consumeIndex, this, _1 ) );
80 content.parse( inputfile );
84 ZYPP_THROW( ParseException( (dest_dir+_path).asString() + ": " + "No repository index in content file." ) );
88 descr_dir = _repoindex->descrdir; // path below reporoot
89 //_datadir = _repoIndex->datadir; // path below reporoot
91 for ( RepoIndex::FileChecksumMap::const_iterator it = _repoindex->metaFileChecksums.begin();
92 it != _repoindex->metaFileChecksums.end();
95 // omit unwanted translations
96 if ( str::hasPrefix( it->first, "packages" ) )
98 std::string rest( str::stripPrefix( it->first, "packages" ) );
104 || rest == ".en.gz" ) )
106 // Not 100% correct as we take each fallback of textLocale
107 Locale toParse( ZConfig::instance().textLocale() );
108 while ( toParse != Locale::noCode )
110 if ( rest == ("."+toParse.code()) || (rest == ("."+toParse.code()+".gz")) )
112 toParse = toParse.fallback();
114 if ( toParse == Locale::noCode )
121 else if ( str::endsWith( it->first, ".pat" )
122 || str::endsWith( it->first, ".pat.gz" ) )
125 // *** see also zypp/parser/susetags/RepoParser.cc ***
127 // omit unwanted patterns, see https://bugzilla.novell.com/show_bug.cgi?id=298716
128 // expect "<name>.<arch>.pat[.gz]", <name> might contain additional dots
129 // split at dots, take .pat or .pat.gz into account
131 std::vector<std::string> patparts;
132 unsigned archpos = 2;
133 // expect "<name>.<arch>.pat[.gz]", <name> might contain additional dots
134 unsigned count = str::split( it->first, std::back_inserter(patparts), "." );
135 if ( patparts[count-1] == "gz" )
138 if ( count > archpos )
140 try // might by an invalid architecture
142 Arch patarch( patparts[count-archpos] );
143 if ( !patarch.compatibleWith( ZConfig::instance().systemArchitecture() ) )
145 // discard, if not compatible
146 MIL << "Discarding pattern " << it->first << endl;
150 catch ( const Exception & excpt )
152 WAR << "Pattern file name does not contain recognizable architecture: " << it->first << endl;
153 // keep .pat file if it doesn't contain an recognizable arch
157 MIL << "adding job " << it->first << endl;
158 OnMediaLocation location( _path + descr_dir + it->first, 1 );
159 location.setChecksum( it->second );
160 this->enqueueDigested(location);
163 for ( RepoIndex::FileChecksumMap::const_iterator it = _repoindex->signingKeys.begin();
164 it != _repoindex->signingKeys.end();
167 OnMediaLocation location( _path + it->first, 1 );
168 location.setChecksum( it->second );
169 this->enqueueDigested(location);
172 this->start( dest_dir, media );
175 void Downloader::consumeIndex( const RepoIndex_Ptr & data_r )
177 MIL << "Consuming repo index" << endl;