libzypp: zypp/repo/yum/RepomdFileCollector.cc Source File

libzypp 17.38.14

RepomdFileCollector.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "RepomdFileCollector.h"
11#include <zypp/ZConfig.h>
12#include <zypp/PathInfo.h>
13#include <zypp/RepoInfo.h>
14#include <solv/solvversion.h>
15
16namespace zypp::env
17{
18 bool ZYPP_REPOMD_WITH_OTHER()
19 {
20 static bool val = [](){
21 const char * env = getenv("ZYPP_REPOMD_WITH_OTHER");
22 return( env && zypp::str::strToBool( env, true ) );
23 }();
24 return val;
25 }
26
27 bool ZYPP_REPOMD_WITH_FILELISTS()
28 {
29 static bool val = [](){
30 const char * env = getenv("ZYPP_REPOMD_WITH_FILELISTS");
31 return( env && zypp::str::strToBool( env, true ) );
32 }();
33 return val;
34 }
35}
36
37 namespace zypp::repo::yum
38{
39
40 namespace
41 {
42 inline OnMediaLocation loc_with_path_prefix( OnMediaLocation loc_r, const Pathname & prefix_r )
43 {
44 if ( ! prefix_r.empty() && prefix_r != "/" )
45 loc_r.changeFilename( prefix_r / loc_r.filename() );
46 return loc_r;
47 }
48
49 // search old repository file to run the delta algorithm on
50 Pathname search_deltafile( const Pathname & dir, const Pathname & file )
51 {
52 Pathname deltafile;
53 if ( ! PathInfo(dir).isDir() )
54 return deltafile;
55
56 // Strip the checksum preceding the file stem so we can look for an
57 // old *-primary.xml which may contain some reusable blocks.
58 std::string base { file.basename() };
59 size_t hypoff = base.find( '-' );
60 if ( hypoff != std::string::npos )
61 base.replace( 0, hypoff + 1, "" );
62
63 std::list<std::string> retlist;
64 if ( ! filesystem::readdir( retlist, dir, false ) )
65 {
66 for ( const auto & fn : retlist )
67 {
68 if ( str::endsWith( fn, base ) )
69 deltafile = fn;
70 }
71 }
72 if ( !deltafile.empty() )
73 return dir/deltafile;
74
75 return deltafile;
76 }
77 } // namespace
78
79
92 RepomdFileCollector::RepomdFileCollector( const Pathname &destDir_r )
93 : _destDir { destDir_r }
94 {
95 addWantedLocale( ZConfig::instance().textLocale() );
96 for ( const Locale & it : ZConfig::instance().repoRefreshLocales() )
97 addWantedLocale( it );
98 }
99
100 RepomdFileCollector::~RepomdFileCollector()
101 { }
102
107 bool RepomdFileCollector::collect(const OnMediaLocation &loc_r, const std::string &typestr_r)
108 {
109 if ( str::endsWith( typestr_r, "_db" ) )
110 return true; // skip sqlitedb
111
112 bool zchk { str::endsWith( typestr_r, "_zck" ) };
113#if defined(LIBSOLVEXT_FEATURE_ZCHUNK_COMPRESSION)
114 const std::string & basetype { zchk ? typestr_r.substr( 0, typestr_r.size()-4 ) : typestr_r };
115#else
116 if ( zchk )
117 return true; // skip zchunk if not supported by libsolv
118 const std::string & basetype { typestr_r };
119#endif
120
121 // filter well known resource types
122 if ( basetype == "other" && not env::ZYPP_REPOMD_WITH_OTHER() )
123 return true; // skip it
124
125 if ( basetype == "filelists" && not env::ZYPP_REPOMD_WITH_FILELISTS() )
126 return true; // skip it
127
128 // filter localized susedata
129 if ( str::startsWith( basetype, "susedata." ) )
130 {
131 // susedata.LANG
132 if ( ! wantLocale( Locale(basetype.c_str()+9) ) )
133 return true; // skip it
134 }
135
136 // may take it... (prefer zchnk)
137 if ( zchk || !_wantedFiles.count( basetype ) )
138 _wantedFiles[basetype] = loc_r;
139
140 return true;
141 }
142
143 void RepomdFileCollector::finalize(const FinalizeCb &cb)
144 {
145 // schedule fileS for download
146 for ( const auto & el : _wantedFiles ) {
147 const OnMediaLocation & loc { el.second };
148 const OnMediaLocation & loc_with_path { loc_with_path_prefix( loc, repoInfo().path() ) };
149 cb( OnMediaLocation(loc_with_path).setDeltafile( search_deltafile( deltaDir()/"repodata", loc.filename() ) ) );
150 }
151 }
152
153 bool RepomdFileCollector::wantLocale(const Locale &locale_r) const
154 { return _wantedLocales.count( locale_r ); }
155
156 void RepomdFileCollector::addWantedLocale(Locale locale_r)
157 {
158 while ( locale_r )
159 {
160 _wantedLocales.insert( locale_r );
161 locale_r = locale_r.fallback();
162 }
163 }
164
165}
RepoInfo.h
RepomdFileCollector.h
ZConfig.h
zypp::Locale
'Language[_Country]' codes.
Definition Locale.h:51
zypp::Locale::fallback
Locale fallback() const
Return the fallback locale for this locale, if no fallback exists the empty Locale::noCode.
Definition Locale.cc:211
zypp::OnMediaLocation
Describes a resource file located on a medium.
Definition onmedialocation.h:37
zypp::OnMediaLocation::filename
const Pathname & filename() const
The path to the resource on the medium.
Definition onmedialocation.cc:90
zypp::OnMediaLocation::changeFilename
OnMediaLocation & changeFilename(Pathname filename_r)
Individual manipulation of filename (prefer setLocation).
Definition onmedialocation.cc:102
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:794
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::filesystem::Pathname::basename
std::string basename() const
Return the last component of this path.
Definition Pathname.h:137
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition Pathname.h:117
zypp::base
Definition Random.cc:7
zypp::env
Namespace intended to collect all environment variables we use.
Definition RepoVariables.cc:34
zypp::env::ZYPP_REPOMD_WITH_FILELISTS
bool ZYPP_REPOMD_WITH_FILELISTS()
Definition RepomdFileCollector.cc:27
zypp::env::ZYPP_REPOMD_WITH_OTHER
bool ZYPP_REPOMD_WITH_OTHER()
Definition RepomdFileCollector.cc:18
zypp::filesystem::readdir
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
Definition PathInfo.cc:624
zypp::repo::yum
Definition RepomdFileCollector.cc:38
zypp::str::startsWith
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
Definition String.h:1155
zypp::str::endsWith
bool endsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasSuffix
Definition String.h:1162
zypp::str::strToBool
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Definition String.h:500
zypp::repo::yum::RepomdFileCollector::_destDir
const Pathname & _destDir
Definition RepomdFileCollector.h:48
zypp::repo::yum::RepomdFileCollector::addWantedLocale
void addWantedLocale(Locale locale_r)
Definition RepomdFileCollector.cc:156
zypp::repo::yum::RepomdFileCollector::~RepomdFileCollector
virtual ~RepomdFileCollector()
Definition RepomdFileCollector.cc:100
zypp::repo::yum::RepomdFileCollector::_wantedFiles
std::map< std::string, OnMediaLocation > _wantedFiles
Definition RepomdFileCollector.h:51
zypp::repo::yum::RepomdFileCollector::deltaDir
virtual const Pathname & deltaDir() const =0
zypp::repo::yum::RepomdFileCollector::collect
bool collect(const OnMediaLocation &loc_r, const std::string &typestr_r)
The callback invoked by the RepomdFileReader.
Definition RepomdFileCollector.cc:107
zypp::repo::yum::RepomdFileCollector::FinalizeCb
std::function< void(const OnMediaLocation &file)> FinalizeCb
Definition RepomdFileCollector.h:29
zypp::repo::yum::RepomdFileCollector::finalize
void finalize(const FinalizeCb &cb)
Definition RepomdFileCollector.cc:143
zypp::repo::yum::RepomdFileCollector::repoInfo
virtual const RepoInfo & repoInfo() const =0
zypp::repo::yum::RepomdFileCollector::wantLocale
bool wantLocale(const Locale &locale_r) const
Definition RepomdFileCollector.cc:153
zypp::repo::yum::RepomdFileCollector::RepomdFileCollector
RepomdFileCollector(const Pathname &destDir_r)
Definition RepomdFileCollector.cc:92
zypp::repo::yum::RepomdFileCollector::_wantedLocales
LocaleSet _wantedLocales
Locales do download.
Definition RepomdFileCollector.h:50
PathInfo.h