GCC Code Coverage Report


Directory: ./
File: panels/privacy/bolt/bolt-error.c
Date: 2024-05-04 07:58:27
Exec Total Coverage
Lines: 0 24 0.0%
Functions: 0 6 0.0%
Branches: 0 18 0.0%

Line Branch Exec Source
1 /*
2 * Copyright © 2017 Red Hat, Inc
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Authors:
18 * Christian J. Kellner <christian@kellner.me>
19 */
20
21 #include "config.h"
22
23 #include "bolt-error.h"
24
25 #include "bolt-names.h"
26
27 #include <gio/gio.h>
28
29 /**
30 * SECTION:bolt-error
31 * @Title: Error codes
32 *
33 */
34
35 static const GDBusErrorEntry bolt_error_entries[] = {
36 {BOLT_ERROR_FAILED, BOLT_DBUS_NAME ".Error.Failed"},
37 {BOLT_ERROR_UDEV, BOLT_DBUS_NAME ".Error.UDev"},
38 };
39
40
41 GQuark
42 bolt_error_quark (void)
43 {
44 static volatile gsize quark_volatile = 0;
45
46 g_dbus_error_register_error_domain ("bolt-error-quark",
47 &quark_volatile,
48 bolt_error_entries,
49 G_N_ELEMENTS (bolt_error_entries));
50 return (GQuark) quark_volatile;
51 }
52
53 gboolean
54 bolt_err_notfound (const GError *error)
55 {
56 return g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND) ||
57 g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT) ||
58 g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND) ||
59 g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND);
60 }
61
62 gboolean
63 bolt_err_exists (const GError *error)
64 {
65 return g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS) ||
66 g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_EXIST);
67 }
68
69 gboolean
70 bolt_err_inval (const GError *error)
71 {
72 return g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE);
73 }
74
75 gboolean
76 bolt_err_cancelled (const GError *error)
77 {
78 return g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
79 }
80
81 gboolean
82 bolt_error_propagate_stripped (GError **dest,
83 GError **source)
84 {
85 GError *src;
86
87 g_return_val_if_fail (source != NULL, FALSE);
88
89 src = *source;
90
91 if (src == NULL)
92 return TRUE;
93
94 if (g_dbus_error_is_remote_error (src))
95 g_dbus_error_strip_remote_error (src);
96
97 g_propagate_error (dest, g_steal_pointer (source));
98 return FALSE;
99 }
100