Imported Upstream version 17.0.0
[platform/upstream/libzypp.git] / zypp / ZConfig.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ZConfig.h
10  *
11 */
12 #ifndef ZYPP_ZCONFIG_H
13 #define ZYPP_ZCONFIG_H
14
15 #include <iosfwd>
16 #include <set>
17 #include <string>
18
19 #include "zypp/APIConfig.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22
23 #include "zypp/Arch.h"
24 #include "zypp/Locale.h"
25 #include "zypp/Pathname.h"
26 #include "zypp/IdString.h"
27 #include "zypp/TriBool.h"
28
29 #include "zypp/DownloadMode.h"
30 #include "zypp/target/rpm/RpmFlags.h"
31
32 ///////////////////////////////////////////////////////////////////
33 namespace zypp
34 { /////////////////////////////////////////////////////////////////
35
36   ///////////////////////////////////////////////////////////////////
37   //
38   //    CLASS NAME : ZConfig
39   //
40   /** Interim helper class to collect global options and settings.
41    * Use it to avoid hardcoded values and calls to getZYpp() just
42    * to retrieve some value like architecture, languages or tmppath.
43    *
44    * It reads /etc/zypp/zypp.conf, the filename can be overridden by
45    * setting the ZYPP_CONF environment variable to a different file.
46    *
47    * Note, if you add settings to this file, please follow the following
48    * convention:
49    *
50    * namespace.settingname
51    *
52    * should become
53    *
54    * namespace_settingName()
55    *
56    * \ingroup ZyppConfig
57    * \ingroup Singleton
58   */
59   class ZConfig : private base::NonCopyable
60   {
61     public:
62
63       /** Singleton ctor */
64       static ZConfig & instance();
65
66       /** Print some detail about the current libzypp version.*/
67       std::ostream & about( std::ostream & str ) const;
68
69     public:
70
71       /** The target root directory.
72        * Returns an empty path if no target is set.
73        */
74       Pathname systemRoot() const;
75
76     public:
77
78       /** The autodetected system architecture. */
79       static Arch defaultSystemArchitecture();
80
81       /** The system architecture zypp uses. */
82       Arch systemArchitecture() const;
83
84       /** Override the zypp system architecture.
85        * This is useful for test scenarious. <b>But be warned</b>, zypp does
86        * not expect the system architecture to change at runtime. So
87        * set it at the verry beginning before you acess any other
88        * zypp component.
89       */
90       void setSystemArchitecture( const Arch & arch_r );
91
92       /** Reset the zypp system architecture to the default. */
93       void resetSystemArchitecture()
94       { setSystemArchitecture( defaultSystemArchitecture() ); }
95
96     public:
97       /** The autodetected prefered locale for translated texts.
98        */
99       static Locale defaultTextLocale();
100
101       /** The locale for translated texts zypp uses.
102        */
103       Locale textLocale() const;
104
105       /** Set the prefered locale for translated texts. */
106       void setTextLocale( const Locale & locale_r );
107
108       /** Reset the locale for translated texts to the default. */
109       void resetTextLocale()
110       { setTextLocale( defaultTextLocale() ); }
111
112     public:
113       /** \name Maintain user data
114        * \see \ref zypp-userdata
115        */
116       //@{
117       /** Whether a (non empty) user data sting is defined. */
118       bool hasUserData() const;
119
120       /** User defined string value to be passed to log, history, plugins... */
121       std::string userData() const;
122
123       /** Set a new \ref userData string.
124        * \returns \c TRUE if the string was accepted; \c FALSE if the
125        * string was rejected due to nonprintable characters or newlines.
126        */
127       bool setUserData( const std::string & str_r );
128       //@}
129
130     public:
131       /**
132        * Path where the caches are kept (/var/cache/zypp)
133        * \ingroup g_ZC_REPOCACHE
134        */
135       Pathname repoCachePath() const;
136
137      /**
138        * Path where the repo metadata is downloaded and kept (repoCachePath()/raw).
139         * \ingroup g_ZC_REPOCACHE
140       */
141       Pathname repoMetadataPath() const;
142
143      /**
144        * Path where the repo solv files are created and kept (repoCachePath()/solv).
145         * \ingroup g_ZC_REPOCACHE
146       */
147       Pathname repoSolvfilesPath() const;
148
149       /**
150        * Path where the repo packages are downloaded and kept (repoCachePath()/packages).
151         * \ingroup g_ZC_REPOCACHE
152       */
153       Pathname repoPackagesPath() const;
154
155       /**
156        * Path where the configfiles are kept (/etc/zypp).
157        * \ingroup g_ZC_CONFIGFILES
158        */
159       Pathname configPath() const;
160
161       /**
162        * Path where the known repositories .repo files are kept (configPath()/repos.d).
163        * \ingroup g_ZC_CONFIGFILES
164        */
165       Pathname knownReposPath() const;
166
167       /**
168        * Path where the known services .service files are kept (configPath()/services.d).
169        * \ingroup g_ZC_CONFIGFILES
170        */
171       Pathname knownServicesPath() const;
172
173       /**
174        * Path containing custom repo variable definitions (configPath()/vars.d).
175        * \see \ref zypp::repo::RepoVarExpand Repo variable expander
176        * \ingroup g_ZC_CONFIGFILES
177        */
178       Pathname varsPath() const;
179
180       /**
181        * Whether repository urls should be probed.
182        / config option
183        * repo.add.probe
184        */
185       bool repo_add_probe() const;
186
187       /**
188        * Amount of time in minutes that must pass before another refresh.
189        */
190       unsigned repo_refresh_delay() const;
191
192       /**
193        * List of locales for which translated package descriptions should be downloaded.
194        */
195       LocaleSet repoRefreshLocales() const;
196
197       /**
198        * Whether to use repository alias or name in user messages (progress,
199        * exceptions, ...).
200        * True: use alias, false: use name.
201        */
202       bool repoLabelIsAlias() const;
203
204       /**
205        * Whether to use repository alias or name in user messages (progress,
206        * exceptions, ...). Console applications might prefer to use and display
207        * the shorter alias instead of full repository name.
208        *
209        * Default: false; i.e. repo label is 'name'
210        */
211       void repoLabelIsAlias( bool yesno_r );
212
213       /**
214        * Maximum number of concurrent connections for a single transfer
215        */
216       long download_max_concurrent_connections() const;
217
218       /**
219        * Minimum download speed (bytes per second)
220        * until the connection is dropped
221        */
222       long download_min_download_speed() const;
223
224       /**
225        * Maximum download speed (bytes per second)
226        */
227       long download_max_download_speed() const;
228
229       /**
230        * Maximum silent tries
231        */
232       long download_max_silent_tries() const;
233
234       /**
235        * Maximum time in seconds that you allow a transfer operation to take.
236        */
237       long download_transfer_timeout() const;
238
239
240       /** Whether to consider using a deltarpm when downloading a package.
241        * Config option <tt>download.use_deltarpm (true)</tt>
242        */
243       bool download_use_deltarpm() const;
244
245       /** Whether to consider using a deltarpm even when rpm is local.
246        * This requires \ref download_use_deltarpm being \c true.
247        * Config option <tt>download.use_deltarpm.always (false)</tt>
248        */
249       bool download_use_deltarpm_always() const;
250
251       /**
252        * Hint which media to prefer when installing packages (download vs. CD).
253        * \see class \ref media::MediaPriority
254        */
255       bool download_media_prefer_download() const;
256       /** \overload */
257       bool download_media_prefer_volatile() const
258       { return ! download_media_prefer_download(); }
259       /**
260        * Set \ref download_media_prefer_download to a specific value.
261        */
262       void set_download_media_prefer_download( bool yesno_r );
263       /**
264        * Set \ref download_media_prefer_download to the configfiles default.
265        */
266       void set_default_download_media_prefer_download();
267
268       /** Path where media are preferably mounted or downloaded.
269        * Config option <tt>download.media_mountdir (/var/adm/mount)</tt>
270        * Needs to be a (writable) directory, otherwise /var/tmp is fallback.
271        */
272       Pathname download_mediaMountdir() const;
273       /** Set alternate value. */
274       void set_download_mediaMountdir( Pathname newval_r );
275       /** Reset to zypp.cong default. */
276       void set_default_download_mediaMountdir();
277
278       /**
279        * Commit download policy to use as default.
280        */
281       DownloadMode commit_downloadMode() const;
282
283       /** \name Signature checking (repodata and packages)
284        * If \ref gpgcheck is \c on (the default) we will either check the signature
285        * of repo metadata (packages are secured via checksum in the metadata), or the
286        * signature of an rpm package to install if it's repo metadata are not signed
287        * or not checked. If \ref gpgcheck is \c off, no checks are performed.
288        *
289        * The default behavior can be altered by explicitly setting \ref repo_gpgcheck and/or
290        * \ref pkg_gpgcheck to perform those checks always (\c on) or never (\c off).
291        *
292        * Explicitly setting \c gpgcheck, \c repo_gpgcheck or \c pkg_gpgcheck in a
293        * repositories \a .repo file will overwrite the defaults here.
294        */
295       //@{
296       bool gpgCheck() const;                    ///< Turn signature checking on/off (on)
297       TriBool repoGpgCheck() const;             ///< Check repo matadata signatures (indeterminate - according to gpgcheck)
298       TriBool pkgGpgCheck() const;              ///< Check rpm package signatures (indeterminate - according to gpgcheck)
299
300       void setGpgCheck( bool val_r );           ///< Change the value
301       void setRepoGpgCheck( TriBool val_r );    ///< Change the value
302       void setPkgGpgCheck( TriBool val_r );     ///< Change the value
303
304       void resetGpgCheck();                     ///< Reset to the zconfig default
305       void resetRepoGpgCheck();                 ///< Reset to the zconfig default
306       void resetPkgGpgCheck();                  ///< Reset to the zconfig default
307      //@}
308       //
309       /**
310        * Directory for equivalent vendor definitions  (configPath()/vendors.d)
311        * \ingroup g_ZC_CONFIGFILES
312        */
313       Pathname vendorPath() const;
314
315       /**
316        * Solver regards required packages,patterns,... only
317        */
318       bool solver_onlyRequires() const;
319
320       /**
321        * File in which dependencies described which has to be
322        * fulfilled for a running system.
323        */
324       Pathname solver_checkSystemFile() const;
325
326       /**
327        * Directory, which may or may not contain files in which
328        * dependencies described which has to be fulfilled for a
329        * running system.
330        */
331       Pathname solver_checkSystemFileDir() const;
332
333       /**
334        * Whether vendor check is by default enabled.
335        */
336       bool solver_allowVendorChange() const;
337
338       /** DUP tune: Whether to allow version downgrades upon DUP. */
339       bool solver_dupAllowDowngrade() const;
340
341       /** DUP tune: Whether to follow package renames upon DUP. */
342       bool solver_dupAllowNameChange() const;
343
344       /** DUP tune: Whether to allow package arch changes upon DUP. */
345       bool solver_dupAllowArchChange() const;
346
347       /** DUP tune: Whether to allow package vendor changes upon DUP. */
348       bool solver_dupAllowVendorChange() const;
349
350       /**
351        * Whether removing a package should also remove no longer needed requirements.
352        */
353       bool solver_cleandepsOnRemove() const;
354
355       /**
356        * When committing a dist upgrade (e.g. <tt>zypper dup</tt>)
357        * a solver testcase is written. It is needed in bugreports,
358        * in case something went wrong. This returns the number of
359        * testcases to keep on the system. Old cases will be deleted,
360        * as new ones are created. Use \c 0 to write no testcase at all.
361        */
362       unsigned solver_upgradeTestcasesToKeep() const;
363
364       /** Whether dist upgrade should remove a products dropped packages (true).
365        *
366        * A new product may suggest a list of old and no longer supported
367        * packages (dropped packages). Performing a dist upgrade the solver
368        * may try to delete them, even if they do not cause any dependency
369        * problem.
370        *
371        * Turning this option off, the solver will not try to remove those
372        * packages unless they actually do cause dependency trouble. At any
373        * time you may use zypper to detect orphaned packages, and do the
374        * cleanup manually. Or simply leave them installed as long as you don't
375        * need the disk space.
376        */
377       bool solverUpgradeRemoveDroppedPackages() const;
378       /** Set \ref solverUpgradeRemoveDroppedPackages to \a val_r. */
379       void setSolverUpgradeRemoveDroppedPackages( bool val_r );
380       /** Reset \ref solverUpgradeRemoveDroppedPackages to the \c zypp.conf default. */
381       void resetSolverUpgradeRemoveDroppedPackages();
382
383       /** \name Packages which can be installed in different versions at the same time.
384        *
385        * This returns the config file values (\c names or \c provides:...). The
386        * corresponding packages have the \c multiversionInstall property set. Those
387        * packages will be installed using 'rpm -i', so they will not implicitly obsolete
388        * other installed versions.
389        *
390        * \see \ref sat::SolvableType
391        */
392       //@{
393       const std::set<std::string> & multiversionSpec() const;
394       void multiversionSpec( std::set<std::string> new_r );
395       void clearMultiversionSpec();
396       void addMultiversionSpec( const std::string & name_r );
397       void removeMultiversionSpec( const std::string & name_r );
398       //@}
399
400       /**
401        * Path where zypp can find or create lock file (configPath()/locks)
402        * \ingroup g_ZC_CONFIGFILES
403        */
404       Pathname locksFile() const;
405
406       /**
407        * Whether locks file should be read and applied after start (true)
408        */
409       bool apply_locks_file() const;
410
411       /**
412        * Path where the update items are kept (/var/adm)
413        */
414       Pathname update_dataPath() const;
415
416      /**
417       * Path where the repo metadata is downloaded and kept (update_dataPath()/).
418       * \ingroup g_ZC_REPOCACHE
419       */
420       Pathname update_scriptsPath() const;
421
422      /**
423       * Path where the repo solv files are created and kept (update_dataPath()/solv).
424       * \ingroup g_ZC_REPOCACHE
425       */
426       Pathname update_messagesPath() const;
427
428       /** \name Command to be invoked to send update messages. */
429       //@{
430       /** Command definition for sending update messages.*/
431       std::string updateMessagesNotify() const;
432       /** Set a new command definition (see update.messages.notify in zypp.conf). */
433       void setUpdateMessagesNotify( const std::string & val_r );
434       /** Reset to the zypp.conf default. */
435       void resetUpdateMessagesNotify();
436      //@}
437
438       /** \name Options for package installation */
439       //@{
440       /** The default \ref target::rpm::RpmInstFlags for \ref ZYppCommitPolicy.
441        * Or-combination of \ref target::rpm::RpmInstFlag.
442        * \code
443        * ZConfig.instance().rpmInstallFlags().testFlag( target::rpm::RPMINST_EXCLUDEDOCS );
444        * \endcode
445        */
446       target::rpm::RpmInstFlags rpmInstallFlags() const;
447       //@}
448
449       /**
450        * Path where ZYpp install history is logged. Defaults to
451        * /var/log/zypp/history.
452        *
453        * \see http://en.opensuse.org/Libzypp/Package_History
454        */
455       Pathname historyLogFile() const;
456
457       /**
458        * Defaults to /etc/zypp/credentials.d
459        */
460       Pathname credentialsGlobalDir() const;
461
462       /**
463        * Defaults to /etc/zypp/credentials.cat
464        */
465       Pathname credentialsGlobalFile() const;
466
467       /** Package telling the "product version" on systems not using /etc/product.d/baseproduct.
468        *
469        * On RHEL, Fedora and others the "product version" is determined by the first package
470        * providing 'redhat-release'. This value is not hardcoded in YUM and can be configured
471        * with the $distroverpkg variable.
472        *
473        * Defaults to 'redhat-release'.
474        */
475       std::string distroverpkg() const;
476
477       /** \name Plugins */
478       //@{
479       /**
480        * Defaults to \c /usr/lib/zypp/plugins
481        */
482       Pathname pluginsPath() const;
483
484       //@}
485     public:
486       class Impl;
487       /** Dtor */
488       ~ZConfig();
489     private:
490       friend class Impl;
491       /** Default ctor. */
492       ZConfig();
493       /** Pointer to implementation */
494       RW_pointer<Impl, rw_pointer::Scoped<Impl> > _pimpl;
495   };
496   ///////////////////////////////////////////////////////////////////
497
498   /////////////////////////////////////////////////////////////////
499 } // namespace zypp
500 ///////////////////////////////////////////////////////////////////
501 #endif // ZYPP_ZCONFIG_H