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