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