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