summaryrefslogtreecommitdiff
path: root/src/libostree
diff options
context:
space:
mode:
authorKrzesimir Nowak <krzesimir@kinvolk.io>2016-05-23 13:28:04 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2016-05-26 16:53:08 +0000
commit569e43c280d6b09b5a683c5b4ea41a448f1f7ce2 (patch)
tree0c91cb805b7db00c5222ec24b4c3ce4b9f20bbfe /src/libostree
parent6bf94ec2335cd34e6c0b729bc836388732621906 (diff)
downloadostree-569e43c280d6b09b5a683c5b4ea41a448f1f7ce2.tar.gz
core: Add a function creating an archive-z2 content stream
It is quite similar to the already existing ostree_raw_file_to_content_stream function, so I factored the common part to a separate function. The difference is that we cannot report the size of the resulting stream. Can be useful for serving a "bare" repository as a faked "archive-z2" repository. Closes: #308 Approved by: cgwalters
Diffstat (limited to 'src/libostree')
-rw-r--r--src/libostree/libostree.sym2
-rw-r--r--src/libostree/ostree-core.c122
-rw-r--r--src/libostree/ostree-core.h9
3 files changed, 105 insertions, 28 deletions
diff --git a/src/libostree/libostree.sym b/src/libostree/libostree.sym
index 2aa72512..71f4bc9b 100644
--- a/src/libostree/libostree.sym
+++ b/src/libostree/libostree.sym
@@ -341,5 +341,5 @@ global:
LIBOSTREE_2016.6 {
global:
ostree_repo_remote_fetch_summary_with_options;
-
+ ostree_raw_file_to_archive_z2_stream;
} LIBOSTREE_2016.5;
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 00f767b3..d393c496 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -400,48 +400,40 @@ write_file_header_update_checksum (GOutputStream *out,
return ret;
}
-/**
- * ostree_raw_file_to_content_stream:
+/*
+ * header_and_input_to_stream:
+ * @file_header: A file header
* @input: File raw content stream
- * @file_info: A file info
- * @xattrs: (allow-none): Optional extended attributes
* @out_input: (out): Serialized object stream
- * @out_length: (out): Length of stream
+ * @out_header_size: (out): Length of the header
* @cancellable: Cancellable
* @error: Error
*
- * Convert from a "bare" file representation into an
- * OSTREE_OBJECT_TYPE_FILE stream. This is a fundamental operation
- * for writing data to an #OstreeRepo.
+ * Combines @file_header and @input into a single stream.
*/
-gboolean
-ostree_raw_file_to_content_stream (GInputStream *input,
- GFileInfo *file_info,
- GVariant *xattrs,
- GInputStream **out_input,
- guint64 *out_length,
- GCancellable *cancellable,
- GError **error)
+static gboolean
+header_and_input_to_stream (GVariant *file_header,
+ GInputStream *input,
+ GInputStream **out_input,
+ guint64 *out_header_size,
+ GCancellable *cancellable,
+ GError **error)
{
- gboolean ret = FALSE;
gpointer header_data;
gsize header_size;
g_autoptr(GInputStream) ret_input = NULL;
- g_autoptr(GVariant) file_header = NULL;
g_autoptr(GPtrArray) streams = NULL;
g_autoptr(GOutputStream) header_out_stream = NULL;
g_autoptr(GInputStream) header_in_stream = NULL;
- file_header = file_header_new (file_info, xattrs);
-
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,
cancellable, error))
- goto out;
+ return FALSE;
if (!g_output_stream_close (header_out_stream, cancellable, error))
- goto out;
+ return FALSE;
header_size = g_memory_output_stream_get_data_size ((GMemoryOutputStream*) header_out_stream);
header_data = g_memory_output_stream_steal_data ((GMemoryOutputStream*) header_out_stream);
@@ -452,15 +444,91 @@ ostree_raw_file_to_content_stream (GInputStream *input,
g_ptr_array_add (streams, g_object_ref (header_in_stream));
if (input)
g_ptr_array_add (streams, g_object_ref (input));
-
- ret_input = (GInputStream*)ostree_chain_input_stream_new (streams);
- ret = TRUE;
+ ret_input = (GInputStream*)ostree_chain_input_stream_new (streams);
ot_transfer_out_value (out_input, &ret_input);
+ if (out_header_size)
+ *out_header_size = header_size;
+
+ return TRUE;
+}
+
+/**
+ * ostree_raw_file_to_archive_z2_stream:
+ * @input: File raw content stream
+ * @file_info: A file info
+ * @xattrs: (allow-none): Optional extended attributes
+ * @out_input: (out): Serialized object stream
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Convert from a "bare" file representation into an
+ * OSTREE_OBJECT_TYPE_FILE stream suitable for ostree pull.
+ */
+gboolean
+ostree_raw_file_to_archive_z2_stream (GInputStream *input,
+ GFileInfo *file_info,
+ GVariant *xattrs,
+ GInputStream **out_input,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GVariant) file_header = NULL;
+ g_autoptr(GInputStream) zlib_input = NULL;
+
+ file_header = _ostree_zlib_file_header_new (file_info, xattrs);
+ if (input != NULL)
+ {
+ g_autoptr(GConverter) zlib_compressor = NULL;
+
+ zlib_compressor = G_CONVERTER (g_zlib_compressor_new (G_ZLIB_COMPRESSOR_FORMAT_RAW, 9));
+ zlib_input = g_converter_input_stream_new (input, zlib_compressor);
+ }
+ return header_and_input_to_stream (file_header,
+ zlib_input,
+ out_input,
+ NULL,
+ cancellable,
+ error);
+}
+
+/**
+ * ostree_raw_file_to_content_stream:
+ * @input: File raw content stream
+ * @file_info: A file info
+ * @xattrs: (allow-none): Optional extended attributes
+ * @out_input: (out): Serialized object stream
+ * @out_length: (out): Length of stream
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Convert from a "bare" file representation into an
+ * OSTREE_OBJECT_TYPE_FILE stream. This is a fundamental operation
+ * for writing data to an #OstreeRepo.
+ */
+gboolean
+ostree_raw_file_to_content_stream (GInputStream *input,
+ GFileInfo *file_info,
+ GVariant *xattrs,
+ GInputStream **out_input,
+ guint64 *out_length,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_autoptr(GVariant) file_header = NULL;
+ guint64 header_size;
+
+ file_header = file_header_new (file_info, xattrs);
+ if (!header_and_input_to_stream (file_header,
+ input,
+ out_input,
+ &header_size,
+ cancellable,
+ error))
+ return FALSE;
if (out_length)
*out_length = header_size + g_file_info_get_size (file_info);
- out:
- return ret;
+ return TRUE;
}
/**
diff --git a/src/libostree/ostree-core.h b/src/libostree/ostree-core.h
index 29b5a1c0..4d788b20 100644
--- a/src/libostree/ostree-core.h
+++ b/src/libostree/ostree-core.h
@@ -275,6 +275,15 @@ gboolean ostree_content_file_parse_at (gboolean compressed,
GError **error);
_OSTREE_PUBLIC
+gboolean
+ostree_raw_file_to_archive_z2_stream (GInputStream *input,
+ GFileInfo *file_info,
+ GVariant *xattrs,
+ GInputStream **out_input,
+ GCancellable *cancellable,
+ GError **error);
+
+_OSTREE_PUBLIC
gboolean ostree_raw_file_to_content_stream (GInputStream *input,
GFileInfo *file_info,
GVariant *xattrs,