mirror of
https://github.com/ostreedev/ostree.git
synced 2025-01-05 13:18:17 +03:00
lib/core: Port a few functions to decl-after-stmt
No functional changes, just prep for more work. Closes: #1257 Approved by: jlebon
This commit is contained in:
parent
cd8fc8e37a
commit
d10593e65d
@ -287,30 +287,24 @@ GVariant *
|
|||||||
_ostree_file_header_new (GFileInfo *file_info,
|
_ostree_file_header_new (GFileInfo *file_info,
|
||||||
GVariant *xattrs)
|
GVariant *xattrs)
|
||||||
{
|
{
|
||||||
guint32 uid;
|
|
||||||
guint32 gid;
|
guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
|
||||||
guint32 mode;
|
guint32 gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
|
||||||
|
guint32 mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
|
||||||
|
|
||||||
const char *symlink_target;
|
const char *symlink_target;
|
||||||
GVariant *ret;
|
|
||||||
g_autoptr(GVariant) tmp_xattrs = NULL;
|
|
||||||
|
|
||||||
uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
|
|
||||||
gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
|
|
||||||
mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
|
|
||||||
|
|
||||||
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
|
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
|
||||||
symlink_target = g_file_info_get_symlink_target (file_info);
|
symlink_target = g_file_info_get_symlink_target (file_info);
|
||||||
else
|
else
|
||||||
symlink_target = "";
|
symlink_target = "";
|
||||||
|
|
||||||
|
g_autoptr(GVariant) tmp_xattrs = NULL;
|
||||||
if (xattrs == NULL)
|
if (xattrs == NULL)
|
||||||
tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));
|
tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));
|
||||||
|
|
||||||
ret = g_variant_new ("(uuuus@a(ayay))", GUINT32_TO_BE (uid),
|
return g_variant_ref_sink (g_variant_new ("(uuuus@a(ayay))", GUINT32_TO_BE (uid),
|
||||||
GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0,
|
GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0,
|
||||||
symlink_target, xattrs ? xattrs : tmp_xattrs);
|
symlink_target, xattrs ?: tmp_xattrs));
|
||||||
g_variant_ref_sink (ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -324,33 +318,25 @@ GVariant *
|
|||||||
_ostree_zlib_file_header_new (GFileInfo *file_info,
|
_ostree_zlib_file_header_new (GFileInfo *file_info,
|
||||||
GVariant *xattrs)
|
GVariant *xattrs)
|
||||||
{
|
{
|
||||||
guint64 size;
|
guint64 size = g_file_info_get_size (file_info);
|
||||||
guint32 uid;
|
guint32 uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
|
||||||
guint32 gid;
|
guint32 gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
|
||||||
guint32 mode;
|
guint32 mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
|
||||||
|
|
||||||
const char *symlink_target;
|
const char *symlink_target;
|
||||||
GVariant *ret;
|
|
||||||
g_autoptr(GVariant) tmp_xattrs = NULL;
|
|
||||||
|
|
||||||
size = g_file_info_get_size (file_info);
|
|
||||||
uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
|
|
||||||
gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
|
|
||||||
mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
|
|
||||||
|
|
||||||
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
|
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
|
||||||
symlink_target = g_file_info_get_symlink_target (file_info);
|
symlink_target = g_file_info_get_symlink_target (file_info);
|
||||||
else
|
else
|
||||||
symlink_target = "";
|
symlink_target = "";
|
||||||
|
|
||||||
|
g_autoptr(GVariant) tmp_xattrs = NULL;
|
||||||
if (xattrs == NULL)
|
if (xattrs == NULL)
|
||||||
tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));
|
tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));
|
||||||
|
|
||||||
ret = g_variant_new ("(tuuuus@a(ayay))",
|
return g_variant_ref_sink (g_variant_new ("(tuuuus@a(ayay))",
|
||||||
GUINT64_TO_BE (size), GUINT32_TO_BE (uid),
|
GUINT64_TO_BE (size), GUINT32_TO_BE (uid),
|
||||||
GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0,
|
GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), 0,
|
||||||
symlink_target, xattrs ? xattrs : tmp_xattrs);
|
symlink_target, xattrs ?: tmp_xattrs));
|
||||||
g_variant_ref_sink (ret);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -445,33 +431,30 @@ header_and_input_to_stream (GVariant *file_header,
|
|||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gpointer header_data;
|
/* Get a memory buffer for the header */
|
||||||
gsize header_size;
|
g_autoptr(GOutputStream) header_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
|
||||||
g_autoptr(GInputStream) ret_input = NULL;
|
|
||||||
g_autoptr(GPtrArray) streams = NULL;
|
|
||||||
g_autoptr(GOutputStream) header_out_stream = NULL;
|
|
||||||
g_autoptr(GInputStream) header_in_stream = NULL;
|
|
||||||
|
|
||||||
header_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
|
|
||||||
|
|
||||||
if (!_ostree_write_variant_with_size (header_out_stream, file_header, NULL,
|
if (!_ostree_write_variant_with_size (header_out_stream, file_header, NULL,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!g_output_stream_close (header_out_stream, cancellable, error))
|
if (!g_output_stream_close (header_out_stream, cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
header_size = g_memory_output_stream_get_data_size ((GMemoryOutputStream*) header_out_stream);
|
/* Our result stream chain */
|
||||||
header_data = g_memory_output_stream_steal_data ((GMemoryOutputStream*) header_out_stream);
|
g_autoptr(GPtrArray) streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
||||||
header_in_stream = g_memory_input_stream_new_from_data (header_data, header_size, g_free);
|
|
||||||
|
|
||||||
streams = g_ptr_array_new_with_free_func ((GDestroyNotify)g_object_unref);
|
/* Append the header to the chain */
|
||||||
|
const gsize header_size = g_memory_output_stream_get_data_size ((GMemoryOutputStream*) header_out_stream);
|
||||||
|
gpointer header_data = g_memory_output_stream_steal_data ((GMemoryOutputStream*) header_out_stream);
|
||||||
|
g_autoptr(GInputStream) header_in_stream = g_memory_input_stream_new_from_data (header_data, header_size, g_free);
|
||||||
|
|
||||||
g_ptr_array_add (streams, g_object_ref (header_in_stream));
|
g_ptr_array_add (streams, g_object_ref (header_in_stream));
|
||||||
|
|
||||||
|
/* And if we have an input stream, append that */
|
||||||
if (input)
|
if (input)
|
||||||
g_ptr_array_add (streams, g_object_ref (input));
|
g_ptr_array_add (streams, g_object_ref (input));
|
||||||
|
|
||||||
ret_input = (GInputStream*)ostree_chain_input_stream_new (streams);
|
/* Return the result stream */
|
||||||
|
g_autoptr(GInputStream) ret_input = (GInputStream*)ostree_chain_input_stream_new (streams);
|
||||||
ot_transfer_out_value (out_input, &ret_input);
|
ot_transfer_out_value (out_input, &ret_input);
|
||||||
if (out_header_size)
|
if (out_header_size)
|
||||||
*out_header_size = header_size;
|
*out_header_size = header_size;
|
||||||
|
Loading…
Reference in New Issue
Block a user