lib/deltas: Port to more to new code style

Looking at the uses of `ostree_repo_load_file()` here.

Closes: #953
Approved by: jlebon
This commit is contained in:
Colin Walters 2017-06-23 15:29:45 -04:00 committed by Atomic Bot
parent 612c8a5fa8
commit e23071dc39
2 changed files with 116 additions and 174 deletions

View File

@ -138,11 +138,11 @@ xattr_chunk_hash (const void *vp)
g_variant_get_child (v, i, "(^&ay@ay)", g_variant_get_child (v, i, "(^&ay@ay)",
&name, &value); &name, &value);
value_data = g_variant_get_fixed_array (value, &value_len, 1); value_data = g_variant_get_fixed_array (value, &value_len, 1);
h += g_str_hash (name); h += g_str_hash (name);
h += bufhash (value_data, value_len); h += bufhash (value_data, value_len);
} }
return h; return h;
} }
@ -235,7 +235,7 @@ objtype_checksum_array_new (GPtrArray *objects)
const char *checksum; const char *checksum;
guint8 csum[OSTREE_SHA256_DIGEST_LEN]; guint8 csum[OSTREE_SHA256_DIGEST_LEN];
guint8 objtype_v; guint8 objtype_v;
ostree_object_name_deserialize (serialized_key, &checksum, &objtype); ostree_object_name_deserialize (serialized_key, &checksum, &objtype);
objtype_v = (guint8) objtype; objtype_v = (guint8) objtype;
@ -253,29 +253,25 @@ splice_stream_to_payload (OstreeStaticDeltaPartBuilder *current_part,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
const guint readlen = 4096;
gsize bytes_read;
while (TRUE) while (TRUE)
{ {
const guint readlen = 4096;
allocate_part_buffer_space (current_part, readlen); allocate_part_buffer_space (current_part, readlen);
gsize bytes_read;
if (!g_input_stream_read_all (istream, if (!g_input_stream_read_all (istream,
current_part->payload->str + current_part->payload->len, current_part->payload->str + current_part->payload->len,
readlen, readlen,
&bytes_read, &bytes_read,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (bytes_read == 0) if (bytes_read == 0)
break; break;
current_part->payload->len += bytes_read; current_part->payload->len += bytes_read;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static void static void
@ -293,7 +289,7 @@ write_content_mode_xattrs (OstreeRepo *repo,
guint32 mode = guint32 mode =
g_file_info_get_attribute_uint32 (content_finfo, "unix::mode"); g_file_info_get_attribute_uint32 (content_finfo, "unix::mode");
g_autoptr(GVariant) modev g_autoptr(GVariant) modev
= g_variant_ref_sink (g_variant_new ("(uuu)", = g_variant_ref_sink (g_variant_new ("(uuu)",
GUINT32_TO_BE (uid), GUINT32_TO_BE (uid),
GUINT32_TO_BE (gid), GUINT32_TO_BE (gid),
GUINT32_TO_BE (mode))); GUINT32_TO_BE (mode)));
@ -317,41 +313,40 @@ process_one_object (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; OstreeStaticDeltaPartBuilder *current_part = *current_part_val;
guint64 content_size;
g_autoptr(GInputStream) content_stream = NULL;
g_autoptr(GFileInfo) content_finfo = NULL; g_autoptr(GFileInfo) content_finfo = NULL;
g_autoptr(GVariant) content_xattrs = NULL; g_autoptr(GVariant) content_xattrs = NULL;
guint64 compressed_size; guint64 content_size;
OstreeStaticDeltaPartBuilder *current_part = *current_part_val; g_autoptr(GInputStream) content_stream = NULL;
if (OSTREE_OBJECT_TYPE_IS_META (objtype)) if (OSTREE_OBJECT_TYPE_IS_META (objtype))
{ {
if (!ostree_repo_load_object_stream (repo, objtype, checksum, if (!ostree_repo_load_object_stream (repo, objtype, checksum,
&content_stream, &content_size, &content_stream, &content_size,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
else else
{ {
if (!ostree_repo_load_file (repo, checksum, &content_stream, if (!ostree_repo_load_file (repo, checksum, &content_stream,
&content_finfo, &content_xattrs, &content_finfo, &content_xattrs,
cancellable, error)) cancellable, error))
goto out; return FALSE;
content_size = g_file_info_get_size (content_finfo); content_size = g_file_info_get_size (content_finfo);
} }
/* Check to see if this delta is maximum size */ /* Check to see if this delta is maximum size */
if (current_part->objects->len > 0 && if (current_part->objects->len > 0 &&
current_part->payload->len + content_size > builder->max_chunk_size_bytes) current_part->payload->len + content_size > builder->max_chunk_size_bytes)
{ {
*current_part_val = current_part = allocate_part (builder); *current_part_val = current_part = allocate_part (builder);
} }
guint64 compressed_size;
if (!ostree_repo_query_object_storage_size (repo, objtype, checksum, if (!ostree_repo_query_object_storage_size (repo, objtype, checksum,
&compressed_size, &compressed_size,
cancellable, error)) cancellable, error))
goto out; return FALSE;
builder->loose_compressed_size += compressed_size; builder->loose_compressed_size += compressed_size;
current_part->uncompressed_size += content_size; current_part->uncompressed_size += content_size;
@ -366,7 +361,7 @@ process_one_object (OstreeRepo *repo,
if (!splice_stream_to_payload (current_part, content_stream, if (!splice_stream_to_payload (current_part, content_stream,
cancellable, error)) cancellable, error))
goto out; return FALSE;
g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE);
_ostree_write_varuint64 (current_part->operations, content_size); _ostree_write_varuint64 (current_part->operations, content_size);
@ -375,21 +370,16 @@ process_one_object (OstreeRepo *repo,
else else
{ {
gsize mode_offset, xattr_offset, content_offset; gsize mode_offset, xattr_offset, content_offset;
guint32 mode; guint32 mode = g_file_info_get_attribute_uint32 (content_finfo, "unix::mode");
mode = g_file_info_get_attribute_uint32 (content_finfo, "unix::mode");
write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs, write_content_mode_xattrs (repo, current_part, content_finfo, content_xattrs,
&mode_offset, &xattr_offset); &mode_offset, &xattr_offset);
if (S_ISLNK (mode)) if (S_ISLNK (mode))
{ {
const char *target;
g_assert (content_stream == NULL); g_assert (content_stream == NULL);
const char *target = g_file_info_get_symlink_target (content_finfo);
target = g_file_info_get_symlink_target (content_finfo); content_stream =
content_stream =
g_memory_input_stream_new_from_data (target, strlen (target), NULL); g_memory_input_stream_new_from_data (target, strlen (target), NULL);
content_size = strlen (target); content_size = strlen (target);
} }
@ -401,7 +391,7 @@ process_one_object (OstreeRepo *repo,
content_offset = current_part->payload->len; content_offset = current_part->payload->len;
if (!splice_stream_to_payload (current_part, content_stream, if (!splice_stream_to_payload (current_part, content_stream,
cancellable, error)) cancellable, error))
goto out; return FALSE;
g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_OPEN_SPLICE_AND_CLOSE);
_ostree_write_varuint64 (current_part->operations, mode_offset); _ostree_write_varuint64 (current_part->operations, mode_offset);
@ -410,9 +400,7 @@ process_one_object (OstreeRepo *repo,
_ostree_write_varuint64 (current_part->operations, content_offset); _ostree_write_varuint64 (current_part->operations, content_offset);
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
typedef struct { typedef struct {
@ -491,34 +479,28 @@ try_content_bsdiff (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GFileInfo) from_finfo = NULL; g_autoptr(GFileInfo) from_finfo = NULL;
g_autoptr(GFileInfo) to_finfo = NULL;
ContentBsdiff *ret_bsdiff = NULL;
*out_bsdiff = NULL;
if (!ostree_repo_load_file (repo, from, NULL, &from_finfo, NULL, if (!ostree_repo_load_file (repo, from, NULL, &from_finfo, NULL,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
g_autoptr(GFileInfo) to_finfo = NULL;
if (!ostree_repo_load_file (repo, to, NULL, &to_finfo, NULL, if (!ostree_repo_load_file (repo, to, NULL, &to_finfo, NULL,
cancellable, error)) cancellable, error))
return FALSE; return FALSE;
if (g_file_info_get_size (to_finfo) + g_file_info_get_size (from_finfo) > max_bsdiff_size_bytes) *out_bsdiff = NULL;
{
ret = TRUE;
goto out;
}
ret_bsdiff = g_new0 (ContentBsdiff, 1); /* Ignore this if it's too large */
if (g_file_info_get_size (to_finfo) + g_file_info_get_size (from_finfo) > max_bsdiff_size_bytes)
return TRUE;
ContentBsdiff *ret_bsdiff = g_new0 (ContentBsdiff, 1);
ret_bsdiff->from_checksum = g_strdup (from); ret_bsdiff->from_checksum = g_strdup (from);
ret = TRUE; ot_transfer_out_value (out_bsdiff, &ret_bsdiff);
if (out_bsdiff) return TRUE;
*out_bsdiff = g_steal_pointer (&ret_bsdiff);
out:
return ret;
} }
static gboolean static gboolean
@ -530,35 +512,27 @@ try_content_rollsum (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
g_autoptr(GBytes) tmp_from = NULL;
g_autoptr(GBytes) tmp_to = NULL;
OstreeRollsumMatches *matches = NULL;
ContentRollsum *ret_rollsum = NULL;
*out_rollsum = NULL; *out_rollsum = NULL;
/* Load the content objects, splice them to uncompressed temporary files that /* Load the content objects, splice them to uncompressed temporary files that
* we can just mmap() and seek around in conveniently. * we can just mmap() and seek around in conveniently.
*/ */
g_autoptr(GBytes) tmp_from = NULL;
if (!get_unpacked_unlinked_content (repo, from, &tmp_from, cancellable, error)) if (!get_unpacked_unlinked_content (repo, from, &tmp_from, cancellable, error))
goto out; return FALSE;
g_autoptr(GBytes) tmp_to = NULL;
if (!get_unpacked_unlinked_content (repo, to, &tmp_to, cancellable, error)) if (!get_unpacked_unlinked_content (repo, to, &tmp_to, cancellable, error))
goto out; return FALSE;
matches = _ostree_compute_rollsum_matches (tmp_from, tmp_to); OstreeRollsumMatches *matches = _ostree_compute_rollsum_matches (tmp_from, tmp_to);
{ guint match_ratio = (matches->bufmatches*100)/matches->total; const guint match_ratio = (matches->bufmatches*100)/matches->total;
/* Only proceed if the file contains (arbitrary) more than 50% of /* Only proceed if the file contains (arbitrary) more than 50% of
* the previous chunks. * the previous chunks.
*/ */
if (match_ratio < 50) if (match_ratio < 50)
{ return TRUE;
ret = TRUE;
goto out;
}
}
if (opts & DELTAOPT_FLAG_VERBOSE) if (opts & DELTAOPT_FLAG_VERBOSE)
{ {
@ -568,17 +542,11 @@ try_content_rollsum (OstreeRepo *repo,
matches->total, (unsigned long long)matches->match_size); matches->total, (unsigned long long)matches->match_size);
} }
ret_rollsum = g_new0 (ContentRollsum, 1); ContentRollsum *ret_rollsum = g_new0 (ContentRollsum, 1);
ret_rollsum->from_checksum = g_strdup (from); ret_rollsum->from_checksum = g_strdup (from);
ret_rollsum->matches = g_steal_pointer (&matches); ret_rollsum->matches = g_steal_pointer (&matches);
ot_transfer_out_value (out_rollsum, &ret_rollsum);
ret = TRUE; return TRUE;
if (out_rollsum)
*out_rollsum = g_steal_pointer (&ret_rollsum);
out:
if (matches)
_ostree_rollsum_matches_free (matches);
return ret;
} }
struct bzdiff_opaque_s struct bzdiff_opaque_s
@ -625,14 +593,7 @@ process_one_rollsum (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
guint64 content_size;
g_autoptr(GBytes) tmp_to = NULL;
g_autoptr(GFileInfo) content_finfo = NULL;
g_autoptr(GVariant) content_xattrs = NULL;
OstreeStaticDeltaPartBuilder *current_part = *current_part_val; OstreeStaticDeltaPartBuilder *current_part = *current_part_val;
const guint8 *tmp_to_buf;
gsize tmp_to_len;
/* Check to see if this delta has gone over maximum size */ /* Check to see if this delta has gone over maximum size */
if (current_part->objects->len > 0 && if (current_part->objects->len > 0 &&
@ -641,17 +602,21 @@ process_one_rollsum (OstreeRepo *repo,
*current_part_val = current_part = allocate_part (builder); *current_part_val = current_part = allocate_part (builder);
} }
g_autoptr(GBytes) tmp_to = NULL;
if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to,
cancellable, error)) cancellable, error))
goto out; return FALSE;
tmp_to_buf = g_bytes_get_data (tmp_to, &tmp_to_len); gsize tmp_to_len;
const guint8 *tmp_to_buf = g_bytes_get_data (tmp_to, &tmp_to_len);
g_autoptr(GFileInfo) content_finfo = NULL;
g_autoptr(GVariant) content_xattrs = NULL;
if (!ostree_repo_load_file (repo, to_checksum, NULL, if (!ostree_repo_load_file (repo, to_checksum, NULL,
&content_finfo, &content_xattrs, &content_finfo, &content_xattrs,
cancellable, error)) cancellable, error))
goto out; return FALSE;
content_size = g_file_info_get_size (content_finfo); guint64 content_size = g_file_info_get_size (content_finfo);
g_assert_cmpint (tmp_to_len, ==, content_size); g_assert_cmpint (tmp_to_len, ==, content_size);
current_part->uncompressed_size += content_size; current_part->uncompressed_size += content_size;
@ -685,11 +650,10 @@ process_one_rollsum (OstreeRepo *repo,
{ {
GVariant *match = matchlist->pdata[i]; GVariant *match = matchlist->pdata[i];
guint32 crc; guint32 crc;
guint64 prefix;
g_variant_get (match, "(uttt)", &crc, &offset, &to_start, &from_start); g_variant_get (match, "(uttt)", &crc, &offset, &to_start, &from_start);
prefix = to_start - writing_offset; const guint64 prefix = to_start - writing_offset;
if (prefix > 0) if (prefix > 0)
{ {
@ -720,13 +684,11 @@ process_one_rollsum (OstreeRepo *repo,
if (!reading_payload) if (!reading_payload)
g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE);
{ guint64 remainder = tmp_to_len - writing_offset; const guint64 remainder = tmp_to_len - writing_offset;
if (remainder > 0) if (remainder > 0)
append_payload_chunk_and_write (current_part, tmp_to_buf + writing_offset, remainder); append_payload_chunk_and_write (current_part, tmp_to_buf + writing_offset, remainder);
writing_offset += remainder; writing_offset += remainder;
g_assert_cmpint (writing_offset, ==, tmp_to_len); g_assert_cmpint (writing_offset, ==, tmp_to_len);
}
g_assert_cmpint (writing_offset, ==, content_size); g_assert_cmpint (writing_offset, ==, content_size);
} }
@ -734,9 +696,7 @@ process_one_rollsum (OstreeRepo *repo,
g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_CLOSE); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_CLOSE);
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -748,17 +708,7 @@ process_one_bsdiff (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
guint64 content_size;
g_autoptr(GFileInfo) content_finfo = NULL;
g_autoptr(GVariant) content_xattrs = NULL;
OstreeStaticDeltaPartBuilder *current_part = *current_part_val; OstreeStaticDeltaPartBuilder *current_part = *current_part_val;
g_autoptr(GBytes) tmp_from = NULL;
g_autoptr(GBytes) tmp_to = NULL;
const guint8 *tmp_to_buf;
gsize tmp_to_len;
const guint8 *tmp_from_buf;
gsize tmp_from_len;
/* Check to see if this delta has gone over maximum size */ /* Check to see if this delta has gone over maximum size */
if (current_part->objects->len > 0 && if (current_part->objects->len > 0 &&
@ -767,21 +717,27 @@ process_one_bsdiff (OstreeRepo *repo,
*current_part_val = current_part = allocate_part (builder); *current_part_val = current_part = allocate_part (builder);
} }
g_autoptr(GBytes) tmp_from = NULL;
if (!get_unpacked_unlinked_content (repo, bsdiff_content->from_checksum, &tmp_from, if (!get_unpacked_unlinked_content (repo, bsdiff_content->from_checksum, &tmp_from,
cancellable, error)) cancellable, error))
goto out; return FALSE;
g_autoptr(GBytes) tmp_to = NULL;
if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to, if (!get_unpacked_unlinked_content (repo, to_checksum, &tmp_to,
cancellable, error)) cancellable, error))
goto out; return FALSE;
tmp_to_buf = g_bytes_get_data (tmp_to, &tmp_to_len); gsize tmp_to_len;
tmp_from_buf = g_bytes_get_data (tmp_from, &tmp_from_len); const guint8 *tmp_to_buf = g_bytes_get_data (tmp_to, &tmp_to_len);
gsize tmp_from_len;
const guint8 *tmp_from_buf = g_bytes_get_data (tmp_from, &tmp_from_len);
g_autoptr(GFileInfo) content_finfo = NULL;
g_autoptr(GVariant) content_xattrs = NULL;
if (!ostree_repo_load_file (repo, to_checksum, NULL, if (!ostree_repo_load_file (repo, to_checksum, NULL,
&content_finfo, &content_xattrs, &content_finfo, &content_xattrs,
cancellable, error)) cancellable, error))
goto out; return FALSE;
content_size = g_file_info_get_size (content_finfo); const guint64 content_size = g_file_info_get_size (content_finfo);
g_assert_cmpint (tmp_to_len, ==, content_size); g_assert_cmpint (tmp_to_len, ==, content_size);
current_part->uncompressed_size += content_size; current_part->uncompressed_size += content_size;
@ -819,10 +775,8 @@ process_one_bsdiff (OstreeRepo *repo,
op.cancellable = cancellable; op.cancellable = cancellable;
op.error = error; op.error = error;
stream.opaque = &op; stream.opaque = &op;
if (bsdiff (tmp_from_buf, tmp_from_len, tmp_to_buf, tmp_to_len, &stream) < 0) { if (bsdiff (tmp_from_buf, tmp_from_len, tmp_to_buf, tmp_to_len, &stream) < 0)
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "bsdiff generation failed"); return glnx_throw (error, "bsdiff generation failed");
goto out;
}
payload = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (out)); payload = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (out));
payload_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out)); payload_size = g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (out));
@ -838,9 +792,7 @@ process_one_bsdiff (OstreeRepo *repo,
g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE); g_string_append_c (current_part->operations, (gchar)OSTREE_STATIC_DELTA_OP_UNSET_READ_SOURCE);
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -862,7 +814,7 @@ check_object_world_readable (OstreeRepo *repo,
return TRUE; return TRUE;
} }
static gboolean static gboolean
generate_delta_lowlatency (OstreeRepo *repo, generate_delta_lowlatency (OstreeRepo *repo,
const char *from, const char *from,
const char *to, const char *to,
@ -871,7 +823,6 @@ generate_delta_lowlatency (OstreeRepo *repo,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE;
GHashTableIter hashiter; GHashTableIter hashiter;
gpointer key, value; gpointer key, value;
OstreeStaticDeltaPartBuilder *current_part = NULL; OstreeStaticDeltaPartBuilder *current_part = NULL;
@ -892,27 +843,27 @@ generate_delta_lowlatency (OstreeRepo *repo,
{ {
if (!ostree_repo_read_commit (repo, from, &root_from, NULL, if (!ostree_repo_read_commit (repo, from, &root_from, NULL,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, from, if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, from,
&from_commit, error)) &from_commit, error))
goto out; return FALSE;
if (!ostree_repo_traverse_commit (repo, from, 0, &from_reachable_objects, if (!ostree_repo_traverse_commit (repo, from, 0, &from_reachable_objects,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
if (!ostree_repo_read_commit (repo, to, &root_to, NULL, if (!ostree_repo_read_commit (repo, to, &root_to, NULL,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, to, if (!ostree_repo_load_variant (repo, OSTREE_OBJECT_TYPE_COMMIT, to,
&to_commit, error)) &to_commit, error))
goto out; return FALSE;
if (!ostree_repo_traverse_commit (repo, to, 0, &to_reachable_objects, if (!ostree_repo_traverse_commit (repo, to, 0, &to_reachable_objects,
cancellable, error)) cancellable, error))
goto out; return FALSE;
new_reachable_metadata = ostree_repo_traverse_new_reachable (); new_reachable_metadata = ostree_repo_traverse_new_reachable ();
new_reachable_regfile_content = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); new_reachable_regfile_content = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
@ -939,7 +890,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL, if (!ostree_repo_load_file (repo, checksum, NULL, &finfo, NULL,
cancellable, error)) cancellable, error))
goto out; return FALSE;
ftype = g_file_info_get_file_type (finfo); ftype = g_file_info_get_file_type (finfo);
if (ftype == G_FILE_TYPE_REGULAR) if (ftype == G_FILE_TYPE_REGULAR)
@ -958,7 +909,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
CONTENT_SIZE_SIMILARITY_THRESHOLD_PERCENT, CONTENT_SIZE_SIMILARITY_THRESHOLD_PERCENT,
&modified_regfile_content, &modified_regfile_content,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
else else
modified_regfile_content = g_hash_table_new (g_str_hash, g_str_equal); modified_regfile_content = g_hash_table_new (g_str_hash, g_str_equal);
@ -1001,13 +952,13 @@ generate_delta_lowlatency (OstreeRepo *repo,
* bare repository defined as its parent. * bare repository defined as its parent.
*/ */
if (!check_object_world_readable (repo, from_checksum, &from_world_readable, cancellable, error)) if (!check_object_world_readable (repo, from_checksum, &from_world_readable, cancellable, error))
goto out; return FALSE;
if (!from_world_readable) if (!from_world_readable)
continue; continue;
if (!try_content_rollsum (repo, opts, from_checksum, to_checksum, if (!try_content_rollsum (repo, opts, from_checksum, to_checksum,
&rollsum, cancellable, error)) &rollsum, cancellable, error))
goto out; return FALSE;
if (rollsum) if (rollsum)
{ {
@ -1021,7 +972,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!try_content_bsdiff (repo, from_checksum, to_checksum, if (!try_content_bsdiff (repo, from_checksum, to_checksum,
&bsdiff, builder->max_bsdiff_size_bytes, &bsdiff, builder->max_bsdiff_size_bytes,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (bsdiff) if (bsdiff)
g_hash_table_insert (bsdiff_optimized_content_objects, g_strdup (to_checksum), bsdiff); g_hash_table_insert (bsdiff_optimized_content_objects, g_strdup (to_checksum), bsdiff);
@ -1050,7 +1001,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!process_one_object (repo, builder, &current_part, if (!process_one_object (repo, builder, &current_part,
checksum, objtype, checksum, objtype,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
/* Now do rollsummed objects */ /* Now do rollsummed objects */
@ -1064,7 +1015,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!process_one_rollsum (repo, builder, &current_part, if (!process_one_rollsum (repo, builder, &current_part,
checksum, rollsum, checksum, rollsum,
cancellable, error)) cancellable, error))
goto out; return FALSE;
builder->n_rollsum++; builder->n_rollsum++;
} }
@ -1080,7 +1031,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!process_one_bsdiff (repo, builder, &current_part, if (!process_one_bsdiff (repo, builder, &current_part,
checksum, bsdiff, checksum, bsdiff,
cancellable, error)) cancellable, error))
goto out; return FALSE;
builder->n_bsdiff++; builder->n_bsdiff++;
} }
@ -1103,11 +1054,11 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!ostree_repo_load_object_stream (repo, OSTREE_OBJECT_TYPE_FILE, checksum, if (!ostree_repo_load_object_stream (repo, OSTREE_OBJECT_TYPE_FILE, checksum,
NULL, &uncompressed_size, NULL, &uncompressed_size,
cancellable, error)) cancellable, error))
goto out; return FALSE;
if (builder->min_fallback_size_bytes > 0 && if (builder->min_fallback_size_bytes > 0 &&
uncompressed_size > builder->min_fallback_size_bytes) uncompressed_size > builder->min_fallback_size_bytes)
fallback = TRUE; fallback = TRUE;
if (fallback) if (fallback)
{ {
g_autofree char *size = g_format_size (uncompressed_size); g_autofree char *size = g_format_size (uncompressed_size);
@ -1115,7 +1066,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (opts & DELTAOPT_FLAG_VERBOSE) if (opts & DELTAOPT_FLAG_VERBOSE)
g_printerr ("fallback for %s (%s)\n", checksum, size); g_printerr ("fallback for %s (%s)\n", checksum, size);
g_ptr_array_add (builder->fallback_objects, g_ptr_array_add (builder->fallback_objects,
ostree_object_name_serialize (checksum, OSTREE_OBJECT_TYPE_FILE)); ostree_object_name_serialize (checksum, OSTREE_OBJECT_TYPE_FILE));
g_hash_table_iter_remove (&hashiter); g_hash_table_iter_remove (&hashiter);
builder->n_fallback++; builder->n_fallback++;
@ -1136,7 +1087,7 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!process_one_object (repo, builder, &current_part, if (!process_one_object (repo, builder, &current_part,
checksum, OSTREE_OBJECT_TYPE_FILE, checksum, OSTREE_OBJECT_TYPE_FILE,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
/* Now symlinks */ /* Now symlinks */
@ -1148,12 +1099,10 @@ generate_delta_lowlatency (OstreeRepo *repo,
if (!process_one_object (repo, builder, &current_part, if (!process_one_object (repo, builder, &current_part,
checksum, OSTREE_OBJECT_TYPE_FILE, checksum, OSTREE_OBJECT_TYPE_FILE,
cancellable, error)) cancellable, error))
goto out; return FALSE;
} }
ret = TRUE; return TRUE;
out:
return ret;
} }
static gboolean static gboolean
@ -1163,14 +1112,10 @@ get_fallback_headers (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
gboolean ret = FALSE; g_autoptr(GVariantBuilder) fallback_builder =
guint i; g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT));
g_autoptr(GVariant) ret_headers = NULL;
g_autoptr(GVariantBuilder) fallback_builder = NULL;
fallback_builder = g_variant_builder_new (G_VARIANT_TYPE ("a" OSTREE_STATIC_DELTA_FALLBACK_FORMAT)); for (guint i = 0; i < builder->fallback_objects->len; i++)
for (i = 0; i < builder->fallback_objects->len; i++)
{ {
GVariant *serialized = builder->fallback_objects->pdata[i]; GVariant *serialized = builder->fallback_objects->pdata[i];
const char *checksum; const char *checksum;
@ -1185,23 +1130,22 @@ get_fallback_headers (OstreeRepo *self,
if (!ostree_repo_load_object_stream (self, objtype, checksum, if (!ostree_repo_load_object_stream (self, objtype, checksum,
NULL, &uncompressed_size, NULL, &uncompressed_size,
cancellable, error)) cancellable, error))
goto out; return FALSE;
compressed_size = uncompressed_size; compressed_size = uncompressed_size;
} }
else else
{ {
g_autoptr(GFileInfo) file_info = NULL;
if (!ostree_repo_query_object_storage_size (self, OSTREE_OBJECT_TYPE_FILE, if (!ostree_repo_query_object_storage_size (self, OSTREE_OBJECT_TYPE_FILE,
checksum, checksum,
&compressed_size, &compressed_size,
cancellable, error)) cancellable, error))
goto out; return FALSE;
g_autoptr(GFileInfo) file_info = NULL;
if (!ostree_repo_load_file (self, checksum, if (!ostree_repo_load_file (self, checksum,
NULL, &file_info, NULL, NULL, &file_info, NULL,
cancellable, error)) cancellable, error))
goto out; return FALSE;
uncompressed_size = g_file_info_get_size (file_info); uncompressed_size = g_file_info_get_size (file_info);
} }
@ -1214,13 +1158,9 @@ get_fallback_headers (OstreeRepo *self,
maybe_swap_endian_u64 (builder->swap_endian, uncompressed_size))); maybe_swap_endian_u64 (builder->swap_endian, uncompressed_size)));
} }
ret_headers = g_variant_ref_sink (g_variant_builder_end (fallback_builder)); g_autoptr(GVariant) ret_headers = g_variant_ref_sink (g_variant_builder_end (fallback_builder));
ot_transfer_out_value (out_headers, &ret_headers);
ret = TRUE; return TRUE;
if (out_headers)
*out_headers = g_steal_pointer (&ret_headers);
out:
return ret;
} }
/** /**
@ -1352,7 +1292,7 @@ ostree_repo_static_delta_generate (OstreeRepo *self,
} }
{ guint8 endianness_char; { guint8 endianness_char;
switch (endianness) switch (endianness)
{ {
case G_LITTLE_ENDIAN: case G_LITTLE_ENDIAN:
@ -1413,14 +1353,14 @@ ostree_repo_static_delta_generate (OstreeRepo *self,
{ guint j; { guint j;
for (j = 0; j < part_builder->modes->len; j++) for (j = 0; j < part_builder->modes->len; j++)
g_variant_builder_add_value (&mode_builder, part_builder->modes->pdata[j]); g_variant_builder_add_value (&mode_builder, part_builder->modes->pdata[j]);
for (j = 0; j < part_builder->xattrs->len; j++) for (j = 0; j < part_builder->xattrs->len; j++)
g_variant_builder_add_value (&xattr_builder, part_builder->xattrs->pdata[j]); g_variant_builder_add_value (&xattr_builder, part_builder->xattrs->pdata[j]);
} }
payload_b = g_string_free_to_bytes (part_builder->payload); payload_b = g_string_free_to_bytes (part_builder->payload);
part_builder->payload = NULL; part_builder->payload = NULL;
operations_b = g_string_free_to_bytes (part_builder->operations); operations_b = g_string_free_to_bytes (part_builder->operations);
part_builder->operations = NULL; part_builder->operations = NULL;
/* FIXME - avoid duplicating memory here */ /* FIXME - avoid duplicating memory here */

View File

@ -21,6 +21,7 @@
#pragma once #pragma once
#include <gio/gio.h> #include <gio/gio.h>
#include "libglnx.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -39,5 +40,6 @@ _ostree_compute_rollsum_matches (GBytes *from,
GBytes *to); GBytes *to);
void _ostree_rollsum_matches_free (OstreeRollsumMatches *rollsum); void _ostree_rollsum_matches_free (OstreeRollsumMatches *rollsum);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeRollsumMatches, _ostree_rollsum_matches_free)
G_END_DECLS G_END_DECLS