mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-22 06:50:47 +03:00
lib: Drop GFile variant mapping API for fd-relative
In addition to generic fd relative porting, this is a necessary preparatory step for libglnx porting, because when I tried to use `g_mapped_file_new` I hit an issue with it using a different error domain from GIO. Thankfully libglnx consistently uses the GIO error domain, and here we're now using it for the `open()` call. Closes: #317 Approved by: jlebon
This commit is contained in:
parent
f725d39f11
commit
c148631a98
@ -2098,8 +2098,9 @@ ostree_repo_read_commit_detached_metadata (OstreeRepo *self,
|
||||
g_autoptr(GVariant) ret_metadata = NULL;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
if (!ot_util_variant_map (metadata_path, G_VARIANT_TYPE ("a{sv}"),
|
||||
TRUE, &ret_metadata, &temp_error))
|
||||
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))
|
||||
{
|
||||
if (g_error_matches (temp_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
||||
{
|
||||
|
@ -4627,8 +4627,9 @@ ostree_repo_add_gpg_signature_summary (OstreeRepo *self,
|
||||
if (!summary_data)
|
||||
goto out;
|
||||
|
||||
if (!ot_util_variant_map (signature_path, G_VARIANT_TYPE (OSTREE_SUMMARY_SIG_GVARIANT_STRING),
|
||||
TRUE, &existing_signatures, &temp_error))
|
||||
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))
|
||||
{
|
||||
|
@ -117,46 +117,6 @@ ot_util_variant_take_ref (GVariant *variant)
|
||||
return g_variant_take_ref (variant);
|
||||
}
|
||||
|
||||
/**
|
||||
* ot_util_variant_map:
|
||||
* @src: a #GFile
|
||||
* @type: Use this for variant
|
||||
* @trusted: See documentation of g_variant_new_from_data()
|
||||
* @out_variant: (out): Return location for new variant
|
||||
* @error:
|
||||
*
|
||||
* Memory-map @src, and store a new #GVariant referring to this memory
|
||||
* in @out_variant. Note the returned @out_variant is not floating.
|
||||
*/
|
||||
gboolean
|
||||
ot_util_variant_map (GFile *src,
|
||||
const GVariantType *type,
|
||||
gboolean trusted,
|
||||
GVariant **out_variant,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autoptr(GVariant) ret_variant = NULL;
|
||||
GMappedFile *mfile = NULL;
|
||||
|
||||
mfile = gs_file_map_noatime (src, NULL, error);
|
||||
if (!mfile)
|
||||
goto out;
|
||||
|
||||
ret_variant = g_variant_new_from_data (type,
|
||||
g_mapped_file_get_contents (mfile),
|
||||
g_mapped_file_get_length (mfile),
|
||||
trusted,
|
||||
(GDestroyNotify) g_mapped_file_unref,
|
||||
mfile);
|
||||
g_variant_ref_sink (ret_variant);
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value(out_variant, &ret_variant);
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_util_variant_map_at (int dfd,
|
||||
const char *path,
|
||||
|
@ -42,12 +42,6 @@ gboolean ot_util_variant_save (GFile *dest,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ot_util_variant_map (GFile *src,
|
||||
const GVariantType *type,
|
||||
gboolean trusted,
|
||||
GVariant **out_variant,
|
||||
GError **error);
|
||||
|
||||
gboolean ot_util_variant_map_at (int dfd,
|
||||
const char *path,
|
||||
const GVariantType *type,
|
||||
|
@ -51,12 +51,9 @@ do_print_variant_generic (const GVariantType *type,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
g_autoptr(GFile) f = NULL;
|
||||
g_autoptr(GVariant) variant = NULL;
|
||||
|
||||
f = g_file_new_for_path (filename);
|
||||
|
||||
if (!ot_util_variant_map (f, type, TRUE, &variant, error))
|
||||
if (!ot_util_variant_map_at (AT_FDCWD, filename, type, TRUE, &variant, error))
|
||||
goto out;
|
||||
|
||||
ot_dump_variant (variant);
|
||||
|
Loading…
x
Reference in New Issue
Block a user