lib/repo: Refactor object copy import function
This came up in: https://github.com/ostreedev/ostree/pull/881 Basically doing streaming for metadata is dumb. Split up the metadata/content paths so we pass metadata around as `GVariant`. This drops the last internal caller of `ostree_repo_write_metadata_stream_trusted()` which was the dumb function mentioned. Closes: #923 Approved by: jlebon
This commit is contained in:
parent
8edb5161db
commit
848b7c0201
|
|
@ -3049,77 +3049,6 @@ copy_detached_metadata (OstreeRepo *self,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
import_one_object_copy (OstreeRepo *self,
|
|
||||||
OstreeRepo *source,
|
|
||||||
const char *checksum,
|
|
||||||
OstreeObjectType objtype,
|
|
||||||
gboolean trusted,
|
|
||||||
GCancellable *cancellable,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
guint64 length;
|
|
||||||
g_autoptr(GInputStream) object_stream = NULL;
|
|
||||||
|
|
||||||
if (!ostree_repo_load_object_stream (source, objtype, checksum,
|
|
||||||
&object_stream, &length,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (objtype == OSTREE_OBJECT_TYPE_FILE)
|
|
||||||
{
|
|
||||||
if (trusted)
|
|
||||||
{
|
|
||||||
if (!ostree_repo_write_content_trusted (self, checksum,
|
|
||||||
object_stream, length,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_autofree guchar *real_csum = NULL;
|
|
||||||
if (!ostree_repo_write_content (self, checksum,
|
|
||||||
object_stream, length,
|
|
||||||
&real_csum,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
|
|
||||||
{
|
|
||||||
if (!copy_detached_metadata (self, source, checksum, cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trusted)
|
|
||||||
{
|
|
||||||
if (!ostree_repo_write_metadata_stream_trusted (self, objtype,
|
|
||||||
checksum, object_stream, length,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_autofree guchar *real_csum = NULL;
|
|
||||||
g_autoptr(GVariant) variant = NULL;
|
|
||||||
|
|
||||||
if (!ostree_repo_load_variant (source, objtype, checksum,
|
|
||||||
&variant, error))
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (!ostree_repo_write_metadata (self, objtype,
|
|
||||||
checksum, variant,
|
|
||||||
&real_csum,
|
|
||||||
cancellable, error))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
import_one_object_link (OstreeRepo *self,
|
import_one_object_link (OstreeRepo *self,
|
||||||
OstreeRepo *source,
|
OstreeRepo *source,
|
||||||
|
|
@ -3216,29 +3145,91 @@ ostree_repo_import_object_from_with_trust (OstreeRepo *self,
|
||||||
GCancellable *cancellable,
|
GCancellable *cancellable,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean hardlink_was_supported = FALSE;
|
|
||||||
|
|
||||||
if (trusted && /* Don't hardlink into untrusted remotes */
|
if (trusted && /* Don't hardlink into untrusted remotes */
|
||||||
self->mode == source->mode)
|
self->mode == source->mode)
|
||||||
{
|
{
|
||||||
|
gboolean hardlink_was_supported = FALSE;
|
||||||
|
|
||||||
if (!import_one_object_link (self, source, checksum, objtype,
|
if (!import_one_object_link (self, source, checksum, objtype,
|
||||||
&hardlink_was_supported,
|
&hardlink_was_supported,
|
||||||
cancellable, error))
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
/* If we hardlinked, we're done! */
|
||||||
|
if (hardlink_was_supported)
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hardlink_was_supported)
|
/* The copy path */
|
||||||
{
|
|
||||||
gboolean has_object;
|
|
||||||
|
|
||||||
if (!ostree_repo_has_object (self, objtype, checksum, &has_object,
|
/* First, do we have the object already? */
|
||||||
cancellable, error))
|
gboolean has_object;
|
||||||
|
if (!ostree_repo_has_object (self, objtype, checksum, &has_object,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
/* If we have it, we're done */
|
||||||
|
if (has_object)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
if (OSTREE_OBJECT_TYPE_IS_META (objtype))
|
||||||
|
{
|
||||||
|
/* Metadata object */
|
||||||
|
g_autoptr(GVariant) variant = NULL;
|
||||||
|
|
||||||
|
if (objtype == OSTREE_OBJECT_TYPE_COMMIT)
|
||||||
|
{
|
||||||
|
/* FIXME - cleanup detached metadata if copy below fails */
|
||||||
|
if (!copy_detached_metadata (self, source, checksum, cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ostree_repo_load_variant (source, objtype, checksum,
|
||||||
|
&variant, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (!has_object)
|
if (trusted)
|
||||||
{
|
{
|
||||||
if (!import_one_object_copy (self, source, checksum, objtype, trusted,
|
if (!ostree_repo_write_metadata_trusted (self, objtype,
|
||||||
cancellable, error))
|
checksum, variant,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_autofree guchar *real_csum = NULL;
|
||||||
|
|
||||||
|
if (!ostree_repo_write_metadata (self, objtype,
|
||||||
|
checksum, variant,
|
||||||
|
&real_csum,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Content object */
|
||||||
|
guint64 length;
|
||||||
|
g_autoptr(GInputStream) object_stream = NULL;
|
||||||
|
|
||||||
|
if (!ostree_repo_load_object_stream (source, objtype, checksum,
|
||||||
|
&object_stream, &length,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (trusted)
|
||||||
|
{
|
||||||
|
if (!ostree_repo_write_content_trusted (self, checksum,
|
||||||
|
object_stream, length,
|
||||||
|
cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_autofree guchar *real_csum = NULL;
|
||||||
|
if (!ostree_repo_write_content (self, checksum,
|
||||||
|
object_stream, length,
|
||||||
|
&real_csum,
|
||||||
|
cancellable, error))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue