lib: Add _ALLOW_NOENT flag to internal variant mapping API
We have a lot of "allow_noent" type wrapper functions since a common pattern is to allow files to not exist, but still throw cleanly on other issues. This is another instance of that, and cleans up duplicated error handling code. Part of this is prep for moving away from `GFile` consumers. Closes: #319 Approved by: jlebon
This commit is contained in:
1 parent
5a996c04de
commit
3a03a35071
5 files changed
+25
-31
No files matched your search
@@ -2097,22 +2097,13 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self,
|
||||
g_autoptr(GFile) metadata_path =
|
||||
_ostree_repo_get_commit_metadata_loose_path (self, checksum);
|
||||
g_autoptr(GVariant) ret_metadata = NULL;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
if (!ot_util_variant_map_at (AT_FDCWD, gs_file_get_path_cached (metadata_path),
|
||||
G_VARIANT_TYPE ("a{sv}"),
|
||||
TRUE, &ret_metadata, &temp_error))
|
||||
OT_VARIANT_MAP_ALLOW_NOENT | OT_VARIANT_MAP_TRUSTED, &ret_metadata, error))
|
||||
{
|
||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
g_clear_error (&temp_error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_prefix_error (error, "Unable to read existing detached metadata: ");
|
||||
g_propagate_error (error, temp_error);
|
||||
goto out;
|
||||
}
|
||||
g_prefix_error (error, "Unable to read existing detached metadata: ");
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
|
||||
@@ -842,7 +842,7 @@ _ostree_repo_static_delta_dump (OstreeRepo *self,
|
||||
|
||||
if (!ot_util_variant_map_at (self->repo_dir_fd, superblock_path,
|
||||
(GVariantType*)OSTREE_STATIC_DELTA_SUPERBLOCK_FORMAT,
|
||||
TRUE, &delta_superblock, error))
|
||||
OT_VARIANT_MAP_TRUSTED, &delta_superblock, error))
|
||||
goto out;
|
||||
|
||||
g_print ("%s\n", g_variant_print (delta_superblock, 1));
|
||||
|
||||
@@ -4620,7 +4620,6 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo *self,
|
||||
g_autoptr(GBytes) summary_data = NULL;
|
||||
g_autoptr(GFile) summary_file = NULL;
|
||||
g_autoptr(GFile) signature_path = NULL;
|
||||
GError *temp_error = NULL;
|
||||
g_autoptr(GVariant) existing_signatures = NULL;
|
||||
g_autoptr(GVariant) new_metadata = NULL;
|
||||
g_autoptr(GVariant) normalized = NULL;
|
||||
@@ -4634,18 +4633,8 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo *self,
|
||||
|
||||
if (!ot_util_variant_map_at (AT_FDCWD, gs_file_get_path_cached (signature_path),
|
||||
G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING),
|
||||
TRUE, &existing_signatures, &temp_error))
|
||||
{
|
||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
g_clear_error (&temp_error);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_propagate_error (error, temp_error);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
OT_VARIANT_MAP_ALLOW_NOENT, &existing_signatures, error))
|
||||
goto out;
|
||||
|
||||
for (i = 0; key_id[i]; i++)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user