libzypp  17.37.10
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  {
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 
162  inline std::ostream & operator<<( std::ostream & str, const ProvideFileSpec::Impl & obj )
163  {
164  return str << "{" << obj._destFilenameHint << "{" << obj._downloadSize << "|" << obj._checksum << "|" << obj._deltafile << "}" << "}";
165  }
166 
168  inline std::ostream & dumpOn( std::ostream & str, const ProvideFileSpec::Impl & obj )
169  { return str << obj; }
170 
171 
173  : _pimpl( new Impl() )
174  {}
175 
177  : _pimpl( new Impl() )
178  {
179  setDownloadSize( loc.downloadSize() );
180  setOptional( loc.optional() );
181  setChecksum( loc.checksum() );
182  setOpenSize( loc.openSize() );
183  setOpenChecksum( loc.openChecksum() );
184  setHeaderSize( loc.headerSize() );
186  setDeltafile( loc.deltafile() );
187  }
188 
190  {}
191 
193  { return _pimpl->_destFilenameHint; }
194 
196  { _pimpl->_destFilenameHint = filename; return *this; }
197 
199  { return _pimpl->_checkExistsOnly; }
200 
202  { _pimpl->_checkExistsOnly = set; return *this; }
203 
205  { return _pimpl->_optional; }
206 
208  { _pimpl->_optional = (val_r); return *this; }
209 
211  { return _pimpl->_downloadSize; }
212 
214  { _pimpl->_downloadSize = (val_r); return *this; }
215 
217  { return _pimpl->_checksum; }
218 
220  { _pimpl->_checksum = (val_r); return *this; }
221 
223  { return _pimpl->_openSize; }
224 
226  { _pimpl->_openSize = (val_r); return *this; }
227 
229  { return _pimpl->_openChecksum; }
230 
232  { _pimpl->_openChecksum = (val_r); return *this; }
233 
235  { return _pimpl->_headerSize; }
236 
238  { _pimpl->_headerSize = (val_r); return *this; }
239 
241  { return _pimpl->_headerChecksum; }
242 
244  { _pimpl->_headerChecksum = (val_r); return *this; }
245 
247  { return _pimpl->_deltafile; }
248 
250  { _pimpl->_deltafile = (path); return *this; }
251 
253  { return _pimpl->_mirrorsAllowed; }
254 
256  { _pimpl->_mirrorsAllowed = std::move(set); return *this; }
257 
259  { return _pimpl->_customHeaders; }
260 
262  { return _pimpl->_customHeaders; }
263 
265  {
266  _pimpl->_customHeaders.set( key,val );
267  return *this;
268  }
269 
271  {
272  _pimpl->_customHeaders.add( key,val );
273  return *this;
274  }
275 
277  {
278  return zypp::OnMediaLocation( path, mediaNr )
280  .setOptional( optional() )
281  .setChecksum( checksum() )
282  .setOpenSize( openSize() )
286  .setDeltafile( deltafile() )
288  }
289 
290  std::ostream & operator<<( std::ostream & str, const ProvideFileSpec & obj )
291  { return str << *obj._pimpl; }
292 
293  std::ostream & dumpOn( std::ostream & str, const ProvideFileSpec & obj )
294  { return dumpOn( str, *obj._pimpl ); }
295 
296 } // namespace zypp
ProvideFileSpec & setHeaderChecksum(const zypp::CheckSum &val_r)
Set the headerChecksum.
Definition: providespec.cc:243
void add(const std::string &key, const Value &val)
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.
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:31
ProvideFileSpec & setOptional(bool val)
Set whether the resource is optional.
Definition: providespec.cc:207
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:222
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:85
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:228
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:293
zypp::RWCOW_pointer< Impl > _pimpl
Implementation class.
Definition: providespec.h:199
ProvideMediaSpec & setMedianr(unsigned medianr)
Definition: providespec.cc:113
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:246
OnMediaLocation & setChecksum(CheckSum val_r)
Set the checksum.
Definition: Arch.h:363
const std::string & label() const
Definition: providespec.cc:101
ProvideFileSpec & setOpenChecksum(const zypp::CheckSum &val_r)
Set the openChecksum.
Definition: providespec.cc:231
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:276
ProvideFileSpec & setDestFilenameHint(const zypp::Pathname &filename)
Definition: providespec.cc:195
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
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:216
zypp::Pathname mediaFile() const
Definition: providespec.cc:119
ProvideFileSpec & setDeltafile(const zypp::Pathname &path)
Set the deltafile.
Definition: providespec.cc:249
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:255
const zypp::CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.
Definition: providespec.cc:240
ProvideFileSpec & setHeaderSize(const zypp::ByteCount &val_r)
Set the headerSize.
Definition: providespec.cc:237
ProvideFileSpec & addCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:270
const zypp::ByteCount & downloadSize() const
The size of the resource on the server.
Definition: providespec.cc:210
void set(const std::string &key, Value val)
const zypp::Pathname & destFilenameHint() const
Definition: providespec.cc:192
ProvideFileSpec & setOpenSize(const zypp::ByteCount &val_r)
Set the openSize.
Definition: providespec.cc:225
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:219
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:213
bool optional() const
Whether this is an optional resource.
Definition: providespec.cc:204
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:252
Impl(std::string &&label, zypp::Pathname &&vPath, unsigned medianr)
Definition: providespec.cc:40
ProvideFileSpec & setCheckExistsOnly(const bool set=true)
Definition: providespec.cc:201
std::ostream & operator<<(std::ostream &str, zypp::RepoManagerFlags::RawMetadataRefreshPolicy obj)
Definition: repomanager.cc:101
OnMediaLocation & setOptional(bool val)
Set whether the resource is optional.
ProvideFileSpec & setCustomHeaderValue(const std::string &key, const HeaderValueMap::Value &val)
Definition: providespec.cc:264
const zypp::ByteCount & headerSize() const
The size of the header prepending the resource (e.g.
Definition: providespec.cc:234
bool optional() const
Whether this is an optional resource.
HeaderValueMap & customHeaders()
Definition: providespec.cc:258
ProvideMediaSpec(std::string label="", zypp::Pathname verifyData=zypp::Pathname(), unsigned medianr=1)
Definition: providespec.cc:95
bool checkExistsOnly() const
Definition: providespec.cc:198
const CheckSum & headerChecksum() const
The checksum of the header prepending the resource (e.g.