lib/core: (refactor) Drop wrapper and unneeded args for variant writing

Nothing was using the `bytes_written` data (we always discard partially written
tmpfiles), so simplify everything by dropping it. Further, we always passed an
offset of `0`, so drop that argument too. (I believe that this was previously
used by the "pack files" code that we deleted long ago)

Second, we had an unnecessary internal wrapper for this function; drop that too.

Closes: #1257
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-10-07 09:36:51 -04:00 committed by Atomic Bot
parent 22869e0b72
commit cd8fc8e37a
4 changed files with 13 additions and 63 deletions

View File

@ -76,8 +76,6 @@ GVariant *_ostree_zlib_file_header_new (GFileInfo *file_info,
gboolean _ostree_write_variant_with_size (GOutputStream *output, gboolean _ostree_write_variant_with_size (GOutputStream *output,
GVariant *variant, GVariant *variant,
guint64 alignment_offset,
gsize *out_bytes_written,
OtChecksum *checksum, OtChecksum *checksum,
GCancellable *cancellable, GCancellable *cancellable,
GError **error); GError **error);

View File

@ -387,7 +387,6 @@ write_padding (GOutputStream *output,
* _ostree_write_variant_with_size: * _ostree_write_variant_with_size:
* @output: Stream * @output: Stream
* @variant: A variant * @variant: A variant
* @alignment_offset: Used to determine whether or not we should write padding bytes
* @out_bytes_written: (out): Number of bytes written * @out_bytes_written: (out): Number of bytes written
* @checksum: (allow-none): If provided, update with written data * @checksum: (allow-none): If provided, update with written data
* @cancellable: Cancellable * @cancellable: Cancellable
@ -401,73 +400,29 @@ write_padding (GOutputStream *output,
gboolean gboolean
_ostree_write_variant_with_size (GOutputStream *output, _ostree_write_variant_with_size (GOutputStream *output,
GVariant *variant, GVariant *variant,
guint64 alignment_offset,
gsize *out_bytes_written,
OtChecksum *checksum, OtChecksum *checksum,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
guint64 variant_size;
guint32 variant_size_u32_be;
gsize bytes_written;
gsize ret_bytes_written = 0;
/* Write variant size */ /* Write variant size */
variant_size = g_variant_get_size (variant); const guint64 variant_size = g_variant_get_size (variant);
g_assert (variant_size < G_MAXUINT32); g_assert (variant_size < G_MAXUINT32);
variant_size_u32_be = GUINT32_TO_BE((guint32) variant_size); const guint32 variant_size_u32_be = GUINT32_TO_BE((guint32) variant_size);
bytes_written = 0; if (!ot_gio_write_update_checksum (output, &variant_size_u32_be, sizeof (variant_size_u32_be),
if (!ot_gio_write_update_checksum (output, &variant_size_u32_be, 4, NULL, checksum, cancellable, error))
&bytes_written, checksum,
cancellable, error))
return FALSE; return FALSE;
ret_bytes_written += bytes_written; const gsize alignment_offset = sizeof(variant_size_u32_be);
alignment_offset += bytes_written;
bytes_written = 0;
/* Pad to offset of 8, write variant */ /* Pad to offset of 8, write variant */
if (!write_padding (output, 8, alignment_offset, &bytes_written, checksum, if (!write_padding (output, 8, alignment_offset, NULL, checksum,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
ret_bytes_written += bytes_written;
bytes_written = 0;
if (!ot_gio_write_update_checksum (output, g_variant_get_data (variant), if (!ot_gio_write_update_checksum (output, g_variant_get_data (variant),
variant_size, &bytes_written, checksum, variant_size, NULL, checksum,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
ret_bytes_written += bytes_written;
if (out_bytes_written)
*out_bytes_written = ret_bytes_written;
return TRUE;
}
/*
* write_file_header_update_checksum:
* @out: Stream
* @variant: A variant, should be a file header
* @checksum: (allow-none): If provided, update with written data
* @cancellable: Cancellable
* @error: Error
*
* Write a file header variant to the provided @out stream, optionally
* updating @checksum.
*/
static gboolean
write_file_header_update_checksum (GOutputStream *out,
GVariant *header,
OtChecksum *checksum,
GCancellable *cancellable,
GError **error)
{
gsize bytes_written;
if (!_ostree_write_variant_with_size (out, header, 0, &bytes_written, checksum,
cancellable, error))
return FALSE;
return TRUE; return TRUE;
} }
@ -499,7 +454,7 @@ header_and_input_to_stream (GVariant *file_header,
header_out_stream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); 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, 0, NULL, NULL, if (!_ostree_write_variant_with_size (header_out_stream, file_header, NULL,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
@ -875,12 +830,10 @@ ostree_checksum_file_from_input (GFileInfo *file_info,
} }
else else
{ {
g_autoptr(GVariant) file_header = NULL; g_autoptr(GVariant) file_header = _ostree_file_header_new (file_info, xattrs);
file_header = _ostree_file_header_new (file_info, xattrs); if (!_ostree_write_variant_with_size (NULL, file_header, &checksum,
cancellable, error))
if (!write_file_header_update_checksum (NULL, file_header, &checksum,
cancellable, error))
return FALSE; return FALSE;
if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR) if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_REGULAR)

View File

@ -648,7 +648,7 @@ write_content_object (OstreeRepo *self,
file_meta = _ostree_zlib_file_header_new (file_info, xattrs); file_meta = _ostree_zlib_file_header_new (file_info, xattrs);
if (!_ostree_write_variant_with_size (temp_out, file_meta, 0, NULL, NULL, if (!_ostree_write_variant_with_size (temp_out, file_meta, NULL,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;

View File

@ -505,8 +505,7 @@ handle_untrusted_content_checksum (OstreeRepo *repo,
ot_checksum_init (&state->content_checksum); ot_checksum_init (&state->content_checksum);
gsize bytes_written; if (!_ostree_write_variant_with_size (NULL, header, &state->content_checksum,
if (!_ostree_write_variant_with_size (NULL, header, 0, &bytes_written, &state->content_checksum,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;