libzypp  17.37.18
providespec.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 #include <iostream>
14 #include <utility>
15 #include "providespec.h"
16 
17 using std::endl;
18 
19 namespace zyppng
20 {
22  {
23  public:
31  };
32 
33 
35  {
36  public:
37  Impl()
38  {}
39 
40  Impl( std::string &&label, zypp::Pathname &&vPath, unsigned medianr )
41  : _label(std::move( label ))
42  , _medianr( medianr )
43  , _verifyDataPath(std::move(vPath))
44  {}
45 
46  std::string _label;
47  unsigned _medianr = 0U;
49 
50  public:
52  static zypp::shared_ptr<Impl> nullimpl()
53  { static zypp::shared_ptr<Impl> _nullimpl( new Impl ); return _nullimpl; }
54 
55  private:
56  friend ProvideMediaSpec::Impl * zypp::rwcowClone<ProvideMediaSpec::Impl>( const ProvideMediaSpec::Impl * rhs );
57  Impl * clone() const { return new Impl( *this ); }
58  };
59 
61  {
62  public:
63  Impl()
64  {}
65 
68  bool _checkExistsOnly = false;
69 
70  bool _optional = false;
73 
76 
79 
81 
82  bool _mirrorsAllowed = true;
83 
84  public:
86  static zypp::shared_ptr<Impl> nullimpl()
87  { static zypp::shared_ptr<Impl> _nullimpl( new Impl ); return _nullimpl; }
88 
89  private:
90  friend ProvideFileSpec::Impl * zypp::rwcowClone<ProvideFileSpec::Impl>( const ProvideFileSpec::Impl * rhs );
91  Impl * clone() const { return new Impl( *this ); }
92  };
93 
94 
95  ProvideMediaSpec::ProvideMediaSpec( std::string label, zypp::filesystem::Pathname verifyData, unsigned medianr )
96  : _pimpl( new Impl( std::move(label), std::move(verifyData), medianr ) )
97  {
98 
99  }
100 
101  const std::string &ProvideMediaSpec::label() const
102  { return _pimpl->_label; }
103 
104  ProvideMediaSpec &ProvideMediaSpec::setLabel(const std::string &label)
105  {
106  _pimpl->_label = label;
107  return *this;
108  }
109 
110  unsigned ProvideMediaSpec::medianr() const
111  { return _pimpl->_medianr; }
112 
114  {
115  _pimpl->_medianr = medianr;
116  return *this;
117  }
118 
120  { return _pimpl->_verifyDataPath; }
121 
123  {
124  _pimpl->_verifyDataPath = pName;
125  return *this;
126  }
127 
129  { return _pimpl->_customHeaders; }
130 
132  { return _pimpl->_customHeaders; }
133 
135  {
136  _pimpl->_customHeaders.set( key,val );
137  return *this;
138  }
139 
141  {
142  _pimpl->_customHeaders.add( key,val );
143  return *this;
144  }
145 
147  {
148  // first check if we have the same media data
149  if ( _pimpl->_verifyDataPath != other._pimpl->_verifyDataPath )
150  return false;
151 
152  // if the verify file is not empty check the medianr
153  if ( !_pimpl->_verifyDataPath.empty() ) {
154  return _pimpl->_medianr == other._pimpl->_medianr;
155  }
156 
157  // can't tell without the URL
158  return zypp::indeterminate;
159  }
160 
161  bool ProvideMediaSpec::isSameMedium( const zypp::MirroredOrigin &originA, const ProvideMediaSpec &specA, const zypp::MirroredOrigin &originB, const ProvideMediaSpec &specB )
162  {
163  const auto check = specA.isSameMedium(specB);
164  if ( !zypp::indeterminate (check) )
165  return (bool)check;
166 
167  // if the endpoints intersect we assume same medium
168  const auto &intersects = []( const zypp::MirroredOrigin &l1, const zypp::MirroredOrigin &l2 ){
169  bool intersect = false;
170  for ( const auto &u: l1 ) {
171  intersect = ( std::find( l2.begin (), l2.end(), u ) != l2.end() );
172  if ( intersect )
173  break;
174  }
175  return intersect;
176  };
177 
178  return intersects( originA, originB );
179  }
180 
182  inline std::ostream & operator<<( std::ostream & str, const ProvideFileSpec::Impl & obj )
183  {
184  return str << "{" << obj._destFilenameHint << "{" << obj._downloadSize << "|" << obj._checksum << "|" << obj._deltafile << "}" << "}";
185  }
186 
188  inline std::ostream & dumpOn( std::ostream & str, const ProvideFileSpec::Impl & obj )
189  { return str << obj; }
190 
191 
193  : _pimpl( new Impl() )
194  {}
195 
197  : _pimpl( new Impl() )
198  {
199  setDownloadSize( loc.downloadSize() );
200  setOptional( loc.optional() );
201  setChecksum( loc.checksum() );
202  setOpenSize( loc.openSize() );
203  setOpenChecksum( loc.openChecksum() );
204  setHeaderSize( loc.headerSize() );
206  setDeltafile( loc.deltafile() );
207  }
208 
210  {}
211 
213  { return _pimpl->_destFilenameHint; }
214 
216  { _pimpl->_destFilenameHint = filename; return *this; }
217 
219  { return _pimpl->_checkExistsOnly; }
220 
222  { _pimpl->_checkExistsOnly = set; return *this; }
223 
225  { return _pimpl->_optional; }
226 
228  { _pimpl->_optional = (val_r); return *this; }
229 
231  { return _pimpl->_downloadSize; }
232 
234  { _pimpl->_downloadSize = (val_r); return *this; }
235 
237  { return _pimpl->_checksum; }
238 
240  { _pimpl->_checksum = (val_r); return *this; }
241 
243  { return _pimpl->_openSize; }
244 
246  { _pimpl->_openSize = (val_r); return *this; }
247 
249  { return _pimpl->_openChecksum; }
250 
252  { _pimpl->_openChecksum = (val_r); return *this; }
253 
255  { return _pimpl->_headerSize; }
256 
258  { _pimpl->_headerSize = (val_r); return *this; }
259 
261  { return _pimpl->_headerChecksum; }
262 
264  { _pimpl->_headerChecksum = (val_r); return *this; }
265 
267  { return _pimpl->_deltafile; }
268 
270  { _pimpl->_deltafile = (path); return *this; }
271 
273  { return _pimpl->_mirrorsAllowed; }
274 
276  { _pimpl->_mirrorsAllowed = std::move(set); return *this; }
277 
279  { return _pimpl->_customHeaders; }
280 
282  { return _pimpl->_customHeaders; }
283 
285  {
286  _pimpl->_customHeaders.set( key,val );
287  return *this;
288  }
289 
291  {
292  _pimpl->_customHeaders.add( key,val );
293  return *this;
294  }
295 
297  {
298  return zypp::OnMediaLocation( path, mediaNr )
300  .setOptional( optional() )
301  .setChecksum( checksum() )
302  .setOpenSize( openSize() )
306  .setDeltafile( deltafile() )
308  }
309 
310  std::ostream & operator<<( std::ostream & str, const ProvideFileSpec & obj )
311  { return str << *obj._pimpl; }
312 
313  std::ostream & dumpOn( std::ostream & str, const ProvideFileSpec & obj )
314  { return dumpOn( str, *obj._pimpl ); }
315 
316 } // namespace zypp
ProvideFileSpec & setHeaderChecksum(const zypp::CheckSum &val_r)
Set the headerChecksum.
Definition: providespec.cc:263
OnMediaLocation & setOpenChecksum(CheckSum val_r)
Set the openChecksum.
OnMediaLocation & setHeaderChecksum(CheckSum val_r)
Set the headerChecksum.
const CheckSum & openChecksum() const
The checksum of the resource once it has been uncompressed or unpacked.
ProvideFileSpec & setOptional(bool val)
Set whether the resource is optional.
Definition: providespec.cc:227
const ByteCount & headerSize() const
The size of the header prepending the resource (e.g.
Describes a resource file located on a medium.
const zypp::ByteCount & openSize() const
The size of the resource once it has been uncompressed or unpacked.
Definition: providespec.cc:242
const ByteCount & openSize() const
The size of the resource once it has been uncompressed or unpacked.
zypp::RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: providespec.h:88
zypp::CheckSum _headerChecksum
Definition: providespec.cc:78
Store and operate with byte count.
Definition: ByteCount.h:31
const zypp::CheckSum & openChecksum() const
The checksum of the resource once it has been uncompressed or unpacked.
Definition: providespec.cc:248
static zypp::shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: providespec.cc:52
ProvideSpecBasePrivate & operator=(const ProvideSpecBasePrivate &)=delete
std::ostream & dumpOn(std::ostream &str, const ProvideFileSpec &obj)
Definition: providespec.cc:313
zypp::RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: providespec.h:202
ProvideMediaSpec & setMedianr(unsigned medianr)
Definition: providespec.cc:113
std::ostream & operator<<(std::ostream &str, const ProvideFileSpec &obj)
Definition: providespec.cc:310
String related utilities and Regular expression matching.
const zypp::Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink ) ...
Definition: providespec.cc:266
OnMediaLocation & setChecksum(CheckSum val_r)
Set the checksum.
Definition: ansi.h:854
const std::string & label() const
Definition: providespec.cc:101
ProvideFileSpec & setOpenChecksum(const zypp::CheckSum &val_r)
Set the openChecksum.
Definition: providespec.cc:251
OnMediaLocation & setMirrorsAllowed(bool set=true)
Enables or disables the use of mirrors when fetching this file.
const CheckSum & checksum() const
The checksum of the resource on the server.
zypp::OnMediaLocation asOnMediaLocation(const zypp::Pathname &path, unsigned int mediaNr) const
Definition: providespec.cc:296
ProvideFileSpec & setDestFilenameHint(const zypp::Pathname &filename)
Definition: providespec.cc:215
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:31
OnMediaLocation & setOpenSize(ByteCount val_r)
Set the openSize.
unsigned medianr() const
Definition: providespec.cc:110
zypp::Pathname _destFilenameHint
Definition: providespec.cc:66
const zypp::CheckSum & checksum() const
The checksum of the resource on the server.
Definition: providespec.cc:236
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
zypp::Pathname mediaFile() const
Definition: providespec.cc:119
ProvideFileSpec & setDeltafile(const zypp::Pathname &path)
Set the deltafile.
Definition: providespec.cc:269
const ByteCount & downloadSize() const
The size of the resource on the server.
OnMediaLocation & setHeaderSize(ByteCount val_r)
Set the headerSize.
ProvideFileSpec & setMirrorsAllowed(bool set=true)
Enables or disables the use of mirrors when fetching this file.
Definition: providespec.cc:275
const zypp::CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.
Definition: providespec.cc:260
ProvideFileSpec & setHeaderSize(const zypp::ByteCount &val_r)
Set the headerSize.
Definition: providespec.cc:257
ProvideFileSpec & addCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:290
const zypp::ByteCount & downloadSize() const
The size of the resource on the server.
Definition: providespec.cc:230
const zypp::Pathname & destFilenameHint() const
Definition: providespec.cc:212
ProvideFileSpec & setOpenSize(const zypp::ByteCount &val_r)
Set the openSize.
Definition: providespec.cc:245
OnMediaLocation & setDeltafile(Pathname path)
Set the deltafile.
ProvideMediaSpec & addCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:140
const Pathname & deltafile() const
The existing deltafile that can be used to reduce download size ( zchunk or metalink ) ...
zypp::TriBool isSameMedium(const ProvideMediaSpec &other) const
Definition: providespec.cc:146
OnMediaLocation & setDownloadSize(ByteCount val_r)
Set the downloadSize.
HeaderValueMap & customHeaders()
Definition: providespec.cc:128
ProvideFileSpec & setChecksum(const zypp::CheckSum &val_r)
Set the checksum.
Definition: providespec.cc:239
ProvideMediaSpec & setLabel(const std::string &label)
Definition: providespec.cc:104
ProvideMediaSpec & setCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:134
static zypp::shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: providespec.cc:86
ProvideMediaSpec & setMediaFile(const zypp::Pathname &pName)
Definition: providespec.cc:122
ProvideFileSpec & setDownloadSize(const zypp::ByteCount &val_r)
Set the downloadSize.
Definition: providespec.cc:233
bool optional() const
Whether this is an optional resource.
Definition: providespec.cc:224
zypp::ByteCount _downloadSize
Definition: providespec.cc:71
bool mirrorsAllowed() const
The requested file is allowed to be fetched via mirrors ( defaults to true )
Definition: providespec.cc:272
Impl(std::string &&label, zypp::Pathname &&vPath, unsigned medianr)
Definition: providespec.cc:40
ProvideFileSpec & setCheckExistsOnly(const bool set=true)
Definition: providespec.cc:221
OnMediaLocation & setOptional(bool val)
Set whether the resource is optional.
ProvideFileSpec & setCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:284
const zypp::ByteCount & headerSize() const
The size of the header prepending the resource (e.g.
Definition: providespec.cc:254
bool optional() const
Whether this is an optional resource.
HeaderValueMap & customHeaders()
Definition: providespec.cc:278
ProvideMediaSpec(std::string label="", zypp::Pathname verifyData=zypp::Pathname(), unsigned medianr=1)
Definition: providespec.cc:95
bool checkExistsOnly() const
Definition: providespec.cc:218
const CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.