1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
4  *
5  * Licensed under the GNU Lesser General Public License Version 2.1
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21 
22 #ifndef __DNF_CONTEXT_H
23 #define __DNF_CONTEXT_H
24 
25 #include "dnf-types.h"
26 #include "plugin/plugin.h"
27 
28 #ifndef __GI_SCANNER__
29 #include "dnf-transaction.h"
30 #include "dnf-sack.h"
31 #endif
32 
33 #include <stdbool.h>
34 
35 G_BEGIN_DECLS
36 
37 #define DNF_TYPE_CONTEXT (dnf_context_get_type ())
38 G_DECLARE_DERIVABLE_TYPE (DnfContext, dnf_context, DNF, CONTEXT, GObject)
39 
40 struct _DnfContextClass
41 {
42         GObjectClass            parent_class;
43         void                    (*invalidate)           (DnfContext     *context,
44                                                          const gchar    *message);
45         /*< private >*/
46         void (*_dnf_reserved1)  (void);
47         void (*_dnf_reserved2)  (void);
48         void (*_dnf_reserved3)  (void);
49         void (*_dnf_reserved4)  (void);
50         void (*_dnf_reserved5)  (void);
51         void (*_dnf_reserved6)  (void);
52         void (*_dnf_reserved7)  (void);
53         void (*_dnf_reserved8)  (void);
54 };
55 
56 /**
57  * DnfContextCleanFlags:
58  * @DNF_CONTEXT_CLEAN_EXPIRE_CACHE:            Clean the indicator file for cache directories' age
59  * @DNF_CONTEXT_CLEAN_PACKAGES:                Clean the packages section for cache
60  * @DNF_CONTEXT_CLEAN_METADATA:                Clean the metadata section for cache directories
61  * @DNF_CONTEXT_CLEAN_ALL:                     Clean out all of the cache directories
62  *
63  * The clean flags for cache directories cleaning.
64  **/
65 typedef enum {
66         DNF_CONTEXT_CLEAN_EXPIRE_CACHE          = (1 << 0),
67         DNF_CONTEXT_CLEAN_PACKAGES              = (1 << 1),
68         DNF_CONTEXT_CLEAN_METADATA              = (1 << 2),
69         DNF_CONTEXT_CLEAN_ALL                   = (1 << 3),
70 } DnfContextCleanFlags;
71 
72 /**
73  * DnfContextInvalidateFlags:
74  * @DNF_CONTEXT_INVALIDATE_FLAG_NONE:           No caches are invalid
75  * @DNF_CONTEXT_INVALIDATE_FLAG_RPMDB:          The rpmdb cache is invalid
76  * @DNF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT:     Any enrollment may be invalid
77  *
78  * The update flags.
79  **/
80 typedef enum {
81         DNF_CONTEXT_INVALIDATE_FLAG_NONE        = 0,
82         DNF_CONTEXT_INVALIDATE_FLAG_RPMDB       = 1,
83         DNF_CONTEXT_INVALIDATE_FLAG_ENROLLMENT  = 2,
84         /*< private >*/
85         DNF_CONTEXT_INVALIDATE_FLAG_LAST
86 } DnfContextInvalidateFlags;
87 
88 /**
89  * DnfContextSetupSackFlags:
90  * @DNF_CONTEXT_SETUP_SACK_FLAG_NONE:             No special behaviours
91  * @DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_RPMDB:       Don't load system's rpmdb
92  * @DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_FILELISTS:   Don't load filelists
93  * @DNF_CONTEXT_SETUP_SACK_FLAG_LOAD_UPDATEINFO:  Load updateinfo if available
94  *
95  * The sack setup flags.
96  *
97  * Since: 0.13.0
98  **/
99 typedef enum {
100         DNF_CONTEXT_SETUP_SACK_FLAG_NONE            = (1 << 0),
101         DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_RPMDB      = (1 << 1),
102         DNF_CONTEXT_SETUP_SACK_FLAG_SKIP_FILELISTS  = (1 << 2),
103         DNF_CONTEXT_SETUP_SACK_FLAG_LOAD_UPDATEINFO = (1 << 3),
104 } DnfContextSetupSackFlags;
105 
106 gboolean         dnf_context_globals_init               (GError **error);
107 
108 DnfContext      *dnf_context_new                        (void);
109 
110 /* utils */
111 const gchar     *find_base_arch                         (const char *native);
112 
113 /* getters */
114 const gchar     *dnf_context_get_config_file_path       (void);
115 gboolean         dnf_context_is_set_config_file_path    (void);
116 const gchar * const *dnf_context_get_repos_dir          (DnfContext     *context);
117 const gchar     *dnf_context_get_repo_dir               (DnfContext     *context);
118 const gchar * const *dnf_context_get_vars_dir           (DnfContext     *context);
119 const gchar     *dnf_context_get_base_arch              (DnfContext     *context);
120 const gchar     *dnf_context_get_os_info                (DnfContext     *context);
121 const gchar     *dnf_context_get_arch_info              (DnfContext     *context);
122 const gchar     *dnf_context_get_release_ver            (DnfContext     *context);
123 const gchar     *dnf_context_get_platform_module        (DnfContext     *context);
124 const gchar     *dnf_context_get_cache_dir              (DnfContext     *context);
125 const gchar     *dnf_context_get_arch                   (DnfContext     *context);
126 const gchar     *dnf_context_get_solv_dir               (DnfContext     *context);
127 const gchar     *dnf_context_get_lock_dir               (DnfContext     *context);
128 const gchar     *dnf_context_get_rpm_verbosity          (DnfContext     *context);
129 const gchar     *dnf_context_get_install_root           (DnfContext     *context);
130 const gchar     *dnf_context_get_source_root            (DnfContext     *context);
131 const gchar     **dnf_context_get_native_arches         (DnfContext     *context);
132 const gchar     **dnf_context_get_installonly_pkgs      (DnfContext     *context);
133 gboolean         dnf_context_get_best                   (void);
134 gboolean         dnf_context_get_install_weak_deps      (void);
135 gboolean         dnf_context_get_allow_vendor_change    (void);
136 gboolean         dnf_context_get_cache_only             (DnfContext     *context);
137 gboolean         dnf_context_get_check_disk_space       (DnfContext     *context);
138 gboolean         dnf_context_get_check_transaction      (DnfContext     *context);
139 gboolean         dnf_context_get_keep_cache             (DnfContext     *context);
140 gboolean         dnf_context_get_only_trusted           (DnfContext     *context);
141 gboolean         dnf_context_get_zchunk                 (DnfContext     *context);
142 gboolean         dnf_context_get_write_history          (DnfContext     *context);
143 guint            dnf_context_get_cache_age              (DnfContext     *context);
144 guint            dnf_context_get_installonly_limit      (DnfContext     *context);
145 const gchar     *dnf_context_get_http_proxy             (DnfContext     *context);
146 gboolean         dnf_context_get_enable_filelists       (DnfContext     *context);
147 GPtrArray       *dnf_context_get_repos                  (DnfContext     *context);
148 #ifndef __GI_SCANNER__
149 DnfRepoLoader   *dnf_context_get_repo_loader            (DnfContext     *context);
150 DnfTransaction  *dnf_context_get_transaction            (DnfContext     *context);
151 DnfSack         *dnf_context_get_sack                   (DnfContext     *context);
152 HyGoal           dnf_context_get_goal                   (DnfContext     *context);
153 #endif
154 DnfState*        dnf_context_get_state                  (DnfContext     *context);
155 const char *     dnf_context_get_user_agent             (DnfContext     *context);
156 
157 /* setters */
158 void             dnf_context_set_config_file_path       (const gchar    *config_file_path);
159 void             dnf_context_set_repos_dir              (DnfContext     *context,
160                                                          const gchar * const *repos_dir);
161 void             dnf_context_set_repo_dir               (DnfContext     *context,
162                                                          const gchar    *repo_dir);
163 void             dnf_context_set_vars_dir               (DnfContext     *context,
164                                                          const gchar * const *vars_dir);
165 void             dnf_context_set_release_ver            (DnfContext     *context,
166                                                          const gchar    *release_ver);
167 void             dnf_context_set_platform_module        (DnfContext     *context,
168                                                          const gchar    *platform_module);
169 void             dnf_context_set_cache_dir              (DnfContext     *context,
170                                                          const gchar    *cache_dir);
171 void             dnf_context_set_arch                   (DnfContext     *context,
172                                                          const gchar    *base_arch);
173 void             dnf_context_set_solv_dir               (DnfContext     *context,
174                                                          const gchar    *solv_dir);
175 void             dnf_context_set_vendor_cache_dir       (DnfContext     *context,
176                                                          const gchar    *vendor_cache_dir);
177 void             dnf_context_set_vendor_solv_dir        (DnfContext     *context,
178                                                          const gchar    *vendor_solv_dir);
179 void             dnf_context_set_lock_dir               (DnfContext     *context,
180                                                          const gchar    *lock_dir);
181 void             dnf_context_set_rpm_verbosity          (DnfContext     *context,
182                                                          const gchar    *rpm_verbosity);
183 void             dnf_context_set_install_root           (DnfContext     *context,
184                                                          const gchar    *install_root);
185 void             dnf_context_set_source_root            (DnfContext     *context,
186                                                          const gchar    *source_root);
187 void             dnf_context_set_best                   (gboolean        best);
188 void             dnf_context_set_install_weak_deps      (gboolean        enabled);
189 void             dnf_context_set_allow_vendor_change    (gboolean        vendorchange);
190 void             dnf_context_set_cache_only             (DnfContext     *context,
191                                                          gboolean        cache_only);
192 void             dnf_context_set_check_disk_space       (DnfContext     *context,
193                                                          gboolean        check_disk_space);
194 void             dnf_context_set_check_transaction      (DnfContext     *context,
195                                                          gboolean        check_transaction);
196 void             dnf_context_set_keep_cache             (DnfContext     *context,
197                                                          gboolean        keep_cache);
198 void             dnf_context_set_enable_filelists       (DnfContext     *context,
199                                                          gboolean        enable_filelists);
200 void             dnf_context_set_only_trusted           (DnfContext     *context,
201                                                          gboolean        only_trusted);
202 void             dnf_context_set_zchunk                 (DnfContext     *context,
203                                                          gboolean        only_trusted);
204 void             dnf_context_set_write_history          (DnfContext     *context,
205                                                          gboolean        value);
206 void             dnf_context_set_cache_age              (DnfContext     *context,
207                                                          guint           cache_age);
208 
209 void             dnf_context_set_rpm_macro              (DnfContext     *context,
210                                                          const gchar    *key,
211                                                          const gchar    *value);
212 void             dnf_context_set_http_proxy             (DnfContext     *context,
213                                                          const gchar    *proxyurl);
214 void             dnf_context_set_user_agent             (DnfContext     *context,
215                                                          const gchar    *user_agent);
216 
217 /* object methods */
218 gboolean         dnf_context_setup                      (DnfContext     *context,
219                                                          GCancellable   *cancellable,
220                                                          GError         **error);
221 gboolean         dnf_context_setup_enrollments          (DnfContext     *context,
222                                                          GError         **error);
223 gboolean         dnf_context_setup_sack                 (DnfContext     *context,
224                                                          DnfState       *state,
225                                                          GError         **error);
226 gboolean         dnf_context_setup_sack_with_flags      (DnfContext      *context,
227                                                          DnfState        *state,
228                                                          DnfContextSetupSackFlags flags,
229                                                          GError          **error);
230 gboolean         dnf_context_commit                     (DnfContext     *context,
231                                                          DnfState       *state,
232                                                          GError         **error);
233 void             dnf_context_invalidate                 (DnfContext     *context,
234                                                          const gchar    *message);
235 void             dnf_context_invalidate_full            (DnfContext     *context,
236                                                          const gchar    *message,
237                                                          DnfContextInvalidateFlags flags);
238 gboolean         dnf_context_clean_cache                (DnfContext     *context,
239                                                          DnfContextCleanFlags      flags,
240                                                          GError         **error);
241 gboolean         dnf_context_install                    (DnfContext     *context,
242                                                          const gchar    *name,
243                                                          GError         **error);
244 gboolean         dnf_context_remove                     (DnfContext     *context,
245                                                          const gchar    *name,
246                                                          GError         **error);
247 gboolean         dnf_context_update                     (DnfContext     *context,
248                                                          const gchar    *name,
249                                                          GError         **error);
250 gboolean         dnf_context_update_all                 (DnfContext     *context,
251                                                          GError         **error);
252 gboolean         dnf_context_distrosync                 (DnfContext     *context,
253                                                          const gchar    *name,
254                                                          GError         **error);
255 gboolean         dnf_context_distrosync_all             (DnfContext     *context,
256                                                          GError         **error);
257 gboolean         dnf_context_repo_enable                (DnfContext     *context,
258                                                          const gchar    *repo_id,
259                                                          GError         **error);
260 gboolean         dnf_context_repo_disable               (DnfContext     *context,
261                                                          const gchar    *repo_id,
262                                                          GError         **error);
263 gboolean         dnf_context_run                        (DnfContext     *context,
264                                                          GCancellable   *cancellable,
265                                                          GError         **error);
266 
267 /* plugins support */
268 void             dnf_context_disable_plugins            (const gchar    *plugin_name_pattern);
269 void             dnf_context_enable_plugins             (const gchar    *plugin_name_pattern);
270 gchar**          dnf_context_get_disabled_plugins       (void);
271 gchar**          dnf_context_get_enabled_plugins        (void);
272 gboolean         dnf_context_get_plugins_all_disabled   (void);
273 void             dnf_context_set_plugins_all_disabled   (gboolean        disabled);
274 const char *     dnf_context_get_plugins_dir            (DnfContext     *context);
275 void             dnf_context_set_plugins_dir            (DnfContext     *context,
276                                                          const char     *plugins_dir);
277 bool             dnf_context_plugin_hook                (DnfContext     *context,
278                                                          PluginHookId    id,
279                                                          DnfPluginHookData *hookData,
280                                                          DnfPluginError *error);
281 /// String must be dealocated by g_free()
282 gchar *          dnf_context_get_module_report          (DnfContext * context);
283 
284 /**
285  * dnf_context_reset_modules:
286  * @context: DnfContext
287  * @sack: DnfSack
288  * @module_names: Names of modules to reset
289  * @error: Error
290  *
291  * Reset modules, commit modular changes, and recalculate module filtration.
292  * Note you likely want to use dnf_context_module_reset instead which matches
293  * the behaviour of other modular APIs to not commit modular changes to disk
294  * until dnf_context_run(). Returns FALSE when an error is set.
295  *
296  * Since: 0.38.1
297  **/
298 gboolean         dnf_context_reset_modules              (DnfContext * context,
299                                                          DnfSack * sack,
300                                                          const char ** module_names,
301                                                          GError ** error);
302 
303 /**
304  * dnf_context_reset_all_modules:
305  * @context: DnfContext
306  * @sack: DnfSack
307  * @error: Error
308  *
309  * Reset all modules and recalculate module filtration.
310  * Returns FALSE when an error is set.
311  *
312  * Since: 0.46.2
313  **/
314 gboolean         dnf_context_reset_all_modules          (DnfContext * context,
315                                                          DnfSack * sack,
316                                                          GError ** error);
317 
318 /**
319  * dnf_context_module_enable:
320  * @context: DnfContext
321  * @module_specs: Module specs that should be enabled
322  * @error: Error
323  *
324  * Enable modules, recalculate module filtration, but do not commit modular changes.
325  * To commit modular changes, call dnf_context_run().
326  * Returns FALSE when an error is set.
327  *
328  * Since: 0.55.0
329  **/
330 gboolean         dnf_context_module_enable              (DnfContext * context,
331                                                          const char ** module_specs,
332                                                          GError ** error);
333 
334 /**
335  * dnf_context_module_install:
336  * @context: DnfContext
337  * @module_specs: Module specs that should be installed
338  * @error: Error
339  *
340  * Enable modules and mark for installation but do not commit modular changes.
341  * To commit modular changes, call dnf_context_run().
342  * Returns FALSE when an error is set.
343  *
344  * Since: 0.63.0
345  **/
346 gboolean           dnf_context_module_install            (DnfContext * context,
347                                                           const char ** module_specs,
348                                                           GError ** error);
349 
350 /**
351  * dnf_context_module_disable:
352  * @context: DnfContext
353  * @module_specs: Module specs that should be enabled
354  * @error: Error
355  *
356  * Disable modules, recalculate module filtration, but do not commit modular changes.
357  * To commit modular changes it requires to call dnf_context_run()
358  * Returns FALSE when an error is set.
359  *
360  * Since: 0.55.0
361  **/
362 gboolean         dnf_context_module_disable             (DnfContext * context,
363                                                          const char ** module_specs,
364                                                          GError ** error);
365 
366 /**
367  * dnf_context_module_disable_all:
368  * @context: DnfContext
369  * @module_specs: Module specs that should be enabled
370  * @error: Error
371  *
372  * Disable all modules, recalculate module filtration, but do not commit modular
373  * changes.  To commit modular changes it requires to call dnf_context_run()
374  * Returns FALSE when an error is set.
375  *
376  * Since: 0.64.0
377  **/
378 gboolean         dnf_context_module_disable_all         (DnfContext * context,
379                                                          GError ** error);
380 
381 /**
382  * dnf_context_module_reset:
383  * @context: DnfContext
384  * @module_specs: Module specs that should be enabled
385  * @error: Error
386  *
387  * Reset modules, recalculate module filtration, but do not commit modular changes.
388  * To commit modular changes it requires to call dnf_context_run()
389  * Returns FALSE when an error is set.
390  *
391  * Since: 0.55.0
392  **/
393 gboolean         dnf_context_module_reset               (DnfContext * context,
394                                                          const char ** module_specs,
395                                                          GError ** error);
396 /**
397  * dnf_context_module_switched_check:
398  * @context: DnfContext
399  * @error: Error
400  *
401  * Ceck if any module is switched and return FALSE and sets an error
402  * Returns FALSE when an error is set.
403  *
404  * Since: 0.55.0
405  **/
406 gboolean         dnf_context_module_switched_check      (DnfContext * context,
407                                                          GError ** error);
408 
409 G_END_DECLS
410 
411 #endif /* __DNF_CONTEXT_H */
412