summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-12-12 07:23:51 +0100
committerThomas Haller <thaller@redhat.com>2018-12-12 08:22:12 +0100
commitb7fc328a66dd66f3f9d9f702e8b4a6d505ea3560 (patch)
tree9ccd7a34555ed3df35ffc09978652e7078e28c47
parent066c4645762cc9215f1734127b1847f32ee543a3 (diff)
downloadNetworkManager-b7fc328a66dd66f3f9d9f702e8b4a6d505ea3560.tar.gz
shared: add nm_utils_error_is_notfound() helper
Inspired by bolt's bolt_err_notfound() in "bolt-error.c".
-rw-r--r--shared/nm-utils/nm-shared-utils.c23
-rw-r--r--shared/nm-utils/nm-shared-utils.h2
2 files changed, 20 insertions, 5 deletions
diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c
index bd67647b10..87094a30df 100644
--- a/shared/nm-utils/nm-shared-utils.c
+++ b/shared/nm-utils/nm-shared-utils.c
@@ -1067,11 +1067,24 @@ nm_utils_error_is_cancelled (GError *error,
gboolean consider_is_disposing)
{
if (error) {
- if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
- return TRUE;
- if ( consider_is_disposing
- && g_error_matches (error, NM_UTILS_ERROR, NM_UTILS_ERROR_CANCELLED_DISPOSING))
- return TRUE;
+ if (error->domain == G_IO_ERROR)
+ return NM_IN_SET (error->code, G_IO_ERROR_CANCELLED);
+ if (consider_is_disposing) {
+ if (error->domain == NM_UTILS_ERROR)
+ return NM_IN_SET (error->code, NM_UTILS_ERROR_CANCELLED_DISPOSING);
+ }
+ }
+ return FALSE;
+}
+
+gboolean
+nm_utils_error_is_notfound (GError *error)
+{
+ if (error) {
+ if (error->domain == G_IO_ERROR)
+ return NM_IN_SET (error->code, G_IO_ERROR_NOT_FOUND);
+ if (error->domain == G_FILE_ERROR)
+ return NM_IN_SET (error->code, G_FILE_ERROR_NOENT);
}
return FALSE;
}
diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h
index 5a9bb541d6..c7e9dbfcbb 100644
--- a/shared/nm-utils/nm-shared-utils.h
+++ b/shared/nm-utils/nm-shared-utils.h
@@ -680,6 +680,8 @@ void nm_utils_error_set_cancelled (GError **error,
gboolean nm_utils_error_is_cancelled (GError *error,
gboolean consider_is_disposing);
+gboolean nm_utils_error_is_notfound (GError *error);
+
static inline void
nm_utils_error_set_literal (GError **error, int error_code, const char *literal)
{