core: Drop some dead code from packfile writing, expose GInputStream API too
We never actually dropped into the bits to write metadata as packfiles, because such a thing doesn't exist. Also add a GInputStream-based API for writing packfiles.
This commit is contained in:
parent
556662b24c
commit
702c38739e
|
|
@ -562,46 +562,23 @@ ostree_get_relative_object_path (const char *checksum,
|
|||
}
|
||||
|
||||
gboolean
|
||||
ostree_pack_object (GOutputStream *output,
|
||||
GFile *file,
|
||||
OstreeObjectType objtype,
|
||||
ostree_pack_file_for_input (GOutputStream *output,
|
||||
GFileInfo *finfo,
|
||||
GInputStream *instream,
|
||||
GVariant *xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GFileInfo *finfo = NULL;
|
||||
GFileInputStream *instream = NULL;
|
||||
gboolean pack_builder_initialized = FALSE;
|
||||
GVariantBuilder pack_builder;
|
||||
GVariant *pack_variant = NULL;
|
||||
GVariant *xattrs = NULL;
|
||||
gsize bytes_written;
|
||||
|
||||
finfo = g_file_query_info (file, "standard::type,standard::size,standard::is-symlink,standard::symlink-target,unix::*",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!finfo)
|
||||
goto out;
|
||||
|
||||
if (objtype == OSTREE_OBJECT_TYPE_META)
|
||||
{
|
||||
guint64 object_size_be = GUINT64_TO_BE ((guint64)g_file_info_get_size (finfo));
|
||||
if (!g_output_stream_write_all (output, &object_size_be, 8, &bytes_written, cancellable, error))
|
||||
goto out;
|
||||
|
||||
instream = g_file_read (file, NULL, error);
|
||||
if (!instream)
|
||||
goto out;
|
||||
|
||||
if (g_output_stream_splice (output, (GInputStream*)instream, 0, cancellable, error) < 0)
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
{
|
||||
guint32 uid, gid, mode;
|
||||
guint32 device = 0;
|
||||
guint32 metadata_size_be;
|
||||
const char *target = NULL;
|
||||
guint64 object_size;
|
||||
gboolean pack_builder_initialized = FALSE;
|
||||
GVariantBuilder pack_builder;
|
||||
GVariant *pack_variant = NULL;
|
||||
gsize bytes_written;
|
||||
|
||||
uid = g_file_info_get_attribute_uint32 (finfo, G_FILE_ATTRIBUTE_UNIX_UID);
|
||||
gid = g_file_info_get_attribute_uint32 (finfo, G_FILE_ATTRIBUTE_UNIX_GID);
|
||||
|
|
@ -614,9 +591,6 @@ ostree_pack_object (GOutputStream *output,
|
|||
g_variant_builder_add (&pack_builder, "u", GUINT32_TO_BE (gid));
|
||||
g_variant_builder_add (&pack_builder, "u", GUINT32_TO_BE (mode));
|
||||
|
||||
xattrs = ostree_get_xattrs_for_file (file, error);
|
||||
if (!xattrs)
|
||||
goto out;
|
||||
g_variant_builder_add (&pack_builder, "@a(ayay)", xattrs);
|
||||
|
||||
if (S_ISREG (mode))
|
||||
|
|
@ -657,9 +631,6 @@ ostree_pack_object (GOutputStream *output,
|
|||
|
||||
if (S_ISREG (mode))
|
||||
{
|
||||
instream = g_file_read (file, NULL, error);
|
||||
if (!instream)
|
||||
goto out;
|
||||
bytes_written = g_output_stream_splice (output, (GInputStream*)instream, 0, cancellable, error);
|
||||
if (bytes_written < 0)
|
||||
goto out;
|
||||
|
|
@ -690,16 +661,51 @@ ostree_pack_object (GOutputStream *output,
|
|||
}
|
||||
else
|
||||
g_assert_not_reached ();
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (pack_builder_initialized)
|
||||
g_variant_builder_clear (&pack_builder);
|
||||
ot_clear_gvariant (&pack_variant);
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ostree_pack_file (GOutputStream *output,
|
||||
GFile *file,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
gboolean ret = FALSE;
|
||||
GFileInfo *finfo = NULL;
|
||||
GInputStream *instream = NULL;
|
||||
GVariant *xattrs = NULL;
|
||||
gsize bytes_written;
|
||||
|
||||
finfo = g_file_query_info (file, "standard::type,standard::size,standard::is-symlink,standard::symlink-target,unix::*",
|
||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||
if (!finfo)
|
||||
goto out;
|
||||
|
||||
if (S_ISREG (g_file_info_get_attribute_uint32 (finfo, "unix::mode")))
|
||||
{
|
||||
instream = (GInputStream*)g_file_read (file, cancellable, error);
|
||||
if (!instream)
|
||||
goto out;
|
||||
}
|
||||
|
||||
xattrs = ostree_get_xattrs_for_file (file, error);
|
||||
if (!xattrs)
|
||||
goto out;
|
||||
|
||||
if (!ostree_pack_file_for_input (output, finfo, instream, xattrs, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
g_clear_object (&finfo);
|
||||
g_clear_object (&instream);
|
||||
ot_clear_gvariant (&xattrs);
|
||||
if (pack_builder_initialized)
|
||||
g_variant_builder_clear (&pack_builder);
|
||||
ot_clear_gvariant (&pack_variant);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -152,9 +152,15 @@ gboolean ostree_get_directory_metadata (GFile *dir,
|
|||
*/
|
||||
#define OSTREE_PACK_FILE_VARIANT_FORMAT "(uuuua(ayay)t)"
|
||||
|
||||
gboolean ostree_pack_object (GOutputStream *output,
|
||||
gboolean ostree_pack_file (GOutputStream *output,
|
||||
GFile *file,
|
||||
OstreeObjectType objtype,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
gboolean ostree_pack_file_for_input (GOutputStream *output,
|
||||
GFileInfo *finfo,
|
||||
GInputStream *input,
|
||||
GVariant *xattrs,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
|
|
|
|||
|
|
@ -877,7 +877,6 @@ static gboolean
|
|||
archive_file_trusted (OstreeRepo *self,
|
||||
GFile *file,
|
||||
const char *checksum,
|
||||
OstreeObjectType objtype,
|
||||
gboolean overwrite,
|
||||
gboolean *did_exist,
|
||||
GError **error)
|
||||
|
|
@ -885,9 +884,11 @@ archive_file_trusted (OstreeRepo *self,
|
|||
GFileOutputStream *out = NULL;
|
||||
gboolean ret = FALSE;
|
||||
GFile *dest_file = NULL;
|
||||
GFileInfo *finfo = NULL;
|
||||
GInputStream *input = NULL;
|
||||
GError *temp_error = NULL;
|
||||
|
||||
if (!prepare_dir_for_checksum_get_object_path (self, checksum, objtype, &dest_file, error))
|
||||
if (!prepare_dir_for_checksum_get_object_path (self, checksum, OSTREE_OBJECT_TYPE_FILE, &dest_file, error))
|
||||
goto out;
|
||||
|
||||
if (overwrite)
|
||||
|
|
@ -915,7 +916,7 @@ archive_file_trusted (OstreeRepo *self,
|
|||
|
||||
if (out)
|
||||
{
|
||||
if (!ostree_pack_object ((GOutputStream*)out, file, objtype, NULL, error))
|
||||
if (!ostree_pack_file ((GOutputStream*)out, file, NULL, error))
|
||||
goto out;
|
||||
|
||||
if (!g_output_stream_close ((GOutputStream*)out, NULL, error))
|
||||
|
|
@ -926,6 +927,8 @@ archive_file_trusted (OstreeRepo *self,
|
|||
out:
|
||||
g_clear_object (&dest_file);
|
||||
g_clear_object (&out);
|
||||
g_clear_object (&finfo);
|
||||
g_clear_object (&input);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -940,7 +943,7 @@ ostree_repo_store_object_trusted (OstreeRepo *self,
|
|||
{
|
||||
OstreeRepoPrivate *priv = GET_PRIVATE (self);
|
||||
if (priv->archive && objtype == OSTREE_OBJECT_TYPE_FILE)
|
||||
return archive_file_trusted (self, file, checksum, objtype, overwrite, did_exist, error);
|
||||
return archive_file_trusted (self, file, checksum, overwrite, did_exist, error);
|
||||
else
|
||||
return link_object_trusted (self, file, checksum, objtype, overwrite, did_exist, error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue